-
Notifications
You must be signed in to change notification settings - Fork 0
/
gleichzeitig.go
62 lines (58 loc) · 1.24 KB
/
gleichzeitig.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
package main
import (
"fmt"
"io"
"log"
"os"
"os/signal"
)
var VERSION = ""
var COMMITSHA = ""
var COMMITDATE = ""
var CONFIG Config = Config{}
func main() {
log.SetFlags(log.Ltime)
if len(os.Args) > 1 {
switch os.Args[1] {
case "run", "r":
run(os.Args[2:])
case "init", "i":
initGleichzeitig()
case "help", "h":
printHelp()
case "version", "v":
printVersion()
}
} else {
CONFIG = getConfig()
pwd, _ := os.Getwd()
logInfo("starting gleichzeitig with config located at '" + pwd + "/" + CONFIG_PATH + "'")
if CONFIG.LogFile != "" {
logInfo("found config value for 'config.log_file'")
logInfo("logging to file: '" + CONFIG.LogFile + "'")
f, err := os.OpenFile(CONFIG.LogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if err != nil {
logErr("failed to open logging file: '" + err.Error() + "'")
}
defer f.Close()
mv := io.MultiWriter(os.Stdout, f)
log.SetOutput(mv)
}
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
go func() {
<-c
fmt.Println()
for i, c := range COMMANDS {
err := c.Process.Kill()
if err != nil {
commandPrint(i, "command already stopped.")
} else {
commandPrint(i, "terminated.")
}
}
os.Exit(1)
}()
startCommands()
}
}