forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoreman_dev.go
84 lines (74 loc) · 2.3 KB
/
goreman_dev.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package processrestart
import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"strings"
"time"
pkgerrors "github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
// usingGoremanDev is whether we are running goreman in dev/start.sh
var usingGoremanDev = os.Getenv("GOREMAN") != ""
// restartGoremanDev restarts the processes when running goreman in dev/start.sh. It takes care to
// avoid a race condition where some services have started up with the new config and some are still
// running with the old config.
func restartGoremanDev() error {
goreman := os.Getenv("GOREMAN")
if goreman == "" {
return errors.New("unable to reload site")
}
// Should be kept in sync with Procfile.
allProcessesExceptFrontend := []string{
"gitserver",
"query-runner",
"repo-updater",
"searcher",
"replacer",
"symbols",
"github-proxy",
"syntect_server",
"zoekt-indexserver",
"zoekt-webserver",
// frontend is restarted separately last
}
runCommand := func(command string, processes ...string) error {
group, ctx := errgroup.WithContext(context.Background())
for _, proc := range processes {
proc := proc
group.Go(func() error {
args := append(strings.Fields(goreman), "run", command, proc)
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
if runErr := cmd.Run(); runErr != nil {
if err := ctx.Err(); err != nil {
return err
}
return pkgerrors.Wrap(runErr, "process "+proc)
}
return nil
})
}
if err := group.Wait(); err != nil {
return fmt.Errorf("failed to run %q command on all processes: %s", command, err)
}
return nil
}
if err := runCommand("stop", allProcessesExceptFrontend...); err != nil {
return err
}
// Make the frontend process unreachable from the other processes because they'll try to read
// config/data from frontend (us), and until frontend restarts, it has the pre-restart config.
close(WillRestart)
time.Sleep(100 * time.Millisecond)
// Start all other processes. If they need to communicate with frontend (us), they must be
// designed to wait for a short period until frontend is reachable again (after frontend is
// restarted right below).
if err := runCommand("start", allProcessesExceptFrontend...); err != nil {
return err
}
return runCommand("restart", "frontend")
}