diff --git a/app/daemon.go b/app/daemon.go index b66a4a5..caccbb1 100644 --- a/app/daemon.go +++ b/app/daemon.go @@ -42,8 +42,17 @@ func cmdStdout(commandline []string) chan *string { func runCommands(commands [][]string, moment string) { for _, command := range commands { cmd := exec.Command(command[0], command[1:]...) + cmd.WaitDelay = time.Minute + + logger.Printf(logger.INFO, "%v command: run %v\n", moment, command) + if err := cmd.Start(); err != nil { - logger.Printf(logger.ERROR, "couldn't execute %v command: %v", moment, err) + logger.Printf(logger.ERROR, "%v command: run %v: %v", moment, command, err) + } else { + err := cmd.Wait() + if err != nil { + logger.Printf(logger.ERROR, "%v command: run %v: %v", moment, command, err) + } } } } diff --git a/app/main.go b/app/main.go index 30ec348..ba4c437 100644 --- a/app/main.go +++ b/app/main.go @@ -115,7 +115,7 @@ var exampleConf string func Main() { if len(os.Args) <= 1 { - logger.Fatalln("No argument provided") + logger.Fatalln("No argument provided. Try `reaction help`") basicUsage() os.Exit(1) } else if os.Args[1] == "-h" || os.Args[1] == "--help" { diff --git a/app/startup.go b/app/startup.go index 8435f25..3a3436f 100644 --- a/app/startup.go +++ b/app/startup.go @@ -45,11 +45,11 @@ func (c *Conf) setup() { stream.name = streamName if strings.Contains(stream.name, ".") { - logger.Fatalln("Bad configuration: character '.' is not allowed in stream names", stream.name) + logger.Fatalf("Bad configuration: character '.' is not allowed in stream names: '%v'", stream.name) } if len(stream.Filters) == 0 { - logger.Fatalln("Bad configuration: no filters configured in", stream.name) + logger.Fatalf("Bad configuration: no filters configured in %v", stream.name) } for filterName := range stream.Filters { @@ -58,23 +58,23 @@ func (c *Conf) setup() { filter.name = filterName if strings.Contains(filter.name, ".") { - logger.Fatalln("Bad configuration: character '.' is not allowed in filter names", filter.name) + logger.Fatalf("Bad configuration: character '.' is not allowed in filter names: '%v'", filter.name) } // Parse Duration if filter.RetryPeriod == "" { if filter.Retry > 1 { - logger.Fatalln("Bad configuration: retry but no retryduration in", stream.name, ".", filter.name) + logger.Fatalf("Bad configuration: retry but no retryperiod in %v.%v", stream.name, filter.name) } } else { retryDuration, err := time.ParseDuration(filter.RetryPeriod) if err != nil { - logger.Fatalln("Bad configuration: Failed to parse retry time in", stream.name, ".", filter.name, ":", err) + logger.Fatalf("Bad configuration: Failed to parse retry time in %v.%v: %v", stream.name, filter.name, err) } filter.retryDuration = retryDuration } if len(filter.Regex) == 0 { - logger.Fatalln("Bad configuration: no regexes configured in", stream.name, ".", filter.name) + logger.Fatalf("Bad configuration: no regexes configured in %v.%v", stream.name, filter.name) } // Compute Regexes // Look for Patterns inside Regexes @@ -140,16 +140,21 @@ func parseConf(filename string) *Conf { var conf Conf if filename[len(filename)-4:] == ".yml" || filename[len(filename)-5:] == ".yaml" { + logger.Println(logger.DEBUG, "yaml") err = jsonnet.NewYAMLToJSONDecoder(data).Decode(&conf) + if err != nil { + logger.Fatalln("Failed to parse yaml configuration file:", err) + } } else { + logger.Println(logger.DEBUG, "json") var jsondata string jsondata, err = jsonnet.MakeVM().EvaluateFile(filename) if err == nil { err = json.Unmarshal([]byte(jsondata), &conf) } - } - if err != nil { - logger.Fatalln("Failed to parse configuration file:", err) + if err != nil { + logger.Fatalln("Failed to parse json configuration file:", err) + } } conf.setup() diff --git a/config/test.jsonnet b/config/test.jsonnet index 61b51c7..c3ccf97 100644 --- a/config/test.jsonnet +++ b/config/test.jsonnet @@ -5,6 +5,17 @@ }, }, + start: [ + ['err'], + ['sleep', '10'], + ], + + stop: [ + ['sleep', '1'], + ['false'], + ['true'], + ], + streams: { tailDown1: { cmd: ['sh', '-c', "echo 1 2 3 4 5 1 2 3 4 5 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 | tr ' ' '\n' | while read i; do sleep 2; echo found $(($i % 10)); done"],