-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
55 lines (47 loc) · 1.13 KB
/
main.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
package main
import (
"context"
"flag"
"github.com/zlepper/gpm/internal"
"log"
"os"
"os/signal"
)
func main() {
var err error
configPath := flag.String("config", "config.json", "The path to the config file. If not specified, will search in the current working directory.")
flag.Parse()
log.Printf("GPM version %s\n", internal.VERSION)
pm := NewProcessManager()
err = pm.ParseConfigFile(*configPath)
if err != nil {
log.Println("Could not parse config file", err)
return
}
ctx, cancel := context.WithCancel(context.Background())
done := make(chan error, 1)
go func() {
done <- pm.StartProcesses(ctx)
}()
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)
select {
case err = <-done:
if err != nil {
log.Println("Error while running processes: ", err)
} else {
log.Println("Processes finished by themselves.")
}
case <-signalChan:
log.Println("Got interrupt, stopping processes.")
cancel()
select {
case err = <-done:
if err != nil {
log.Println("Error while stopping processes: ", err)
} else {
log.Println("All processes stopped without issues.")
}
}
}
}