Skip to content

Commit 77aabde

Browse files
committed
Wait spawn processes correctly
1 parent 62cb2a3 commit 77aabde

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

goreman.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func readProcfile() error {
6666
func readEnvfile() error {
6767
content, err := ioutil.ReadFile(".env")
6868
if err != nil {
69-
if os.IsNotExist(err){
69+
if os.IsNotExist(err) {
7070
return nil
7171
}
7272
return err

proc.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"os"
56
"os/signal"
67
"sync"
@@ -16,7 +17,12 @@ func stopProc(proc string, quit bool) error {
1617
}
1718

1819
procs[proc].quit = quit
19-
return procs[proc].cmd.Process.Signal(syscall.SIGINT)
20+
err := procs[proc].cmd.Process.Signal(syscall.SIGINT)
21+
if err != nil {
22+
return err
23+
}
24+
_, err = procs[proc].cmd.Process.Wait()
25+
return err
2026
}
2127

2228
func done() {
@@ -48,7 +54,12 @@ func restartProc(proc string) error {
4854
if err != nil {
4955
return err
5056
}
51-
return startProc(proc)
57+
println("spawn")
58+
if !spawnProc(proc) {
59+
return errors.New("Failed to restart")
60+
}
61+
println("spawned")
62+
return nil
5263
}
5364

5465
// spawn all procs.
@@ -66,15 +77,11 @@ func startProcs() error {
6677
}()
6778
signal.Notify(sc, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
6879
<-sc
69-
if state {
70-
for proc, p := range procs {
71-
if p.cmd != nil {
72-
stopProc(proc, true)
73-
} else {
74-
done()
75-
}
80+
for proc, p := range procs {
81+
if p.cmd != nil {
82+
stopProc(proc, true)
7683
}
84+
done()
7785
}
78-
wg.Wait()
7986
return nil
8087
}

0 commit comments

Comments
 (0)