2015-08-21 17:27:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"fmt"
|
2015-08-24 05:28:45 +00:00
|
|
|
"os"
|
|
|
|
"syscall"
|
2015-08-21 17:27:26 +00:00
|
|
|
"io/ioutil"
|
2015-08-24 05:28:45 +00:00
|
|
|
"os/signal"
|
2015-08-21 17:27:26 +00:00
|
|
|
"encoding/json"
|
2015-08-23 03:20:58 +00:00
|
|
|
"./core"
|
|
|
|
"./engine"
|
2015-08-21 17:27:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
file, err := ioutil.ReadFile("./config.json")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(fmt.Sprintf("%v\n", err))
|
|
|
|
}
|
|
|
|
|
2015-08-23 03:20:58 +00:00
|
|
|
c := core.Config{}
|
2015-08-21 17:27:26 +00:00
|
|
|
json.Unmarshal(file, &c)
|
|
|
|
|
2015-08-23 03:20:58 +00:00
|
|
|
engines := make([]*core.Engine, 0)
|
2015-08-23 00:35:33 +00:00
|
|
|
|
2015-08-23 03:20:58 +00:00
|
|
|
for _, check := range c.Checks {
|
|
|
|
engines = append(engines, engine.EngineFromConfig(check))
|
|
|
|
}
|
2015-08-23 00:35:33 +00:00
|
|
|
|
2015-08-24 05:28:45 +00:00
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-sigs
|
|
|
|
|
|
|
|
log.Print(fmt.Sprintf("Stopping."))
|
2015-08-23 03:20:58 +00:00
|
|
|
for _, engine := range engines {
|
2015-08-24 05:28:45 +00:00
|
|
|
engine.Stop()
|
2015-08-21 17:27:26 +00:00
|
|
|
}
|
2015-08-24 05:28:45 +00:00
|
|
|
log.Print("Exiting.")
|
2015-08-21 17:27:26 +00:00
|
|
|
}
|