2019-09-05 01:37:13 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-02-06 02:45:28 +01:00
|
|
|
"log"
|
2019-12-04 22:44:35 +01:00
|
|
|
"os"
|
2021-02-06 02:45:28 +01:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2020-10-30 16:30:03 +01:00
|
|
|
|
|
|
|
"github.com/TwinProduction/gatus/config"
|
2020-12-30 02:22:17 +01:00
|
|
|
"github.com/TwinProduction/gatus/controller"
|
2021-02-06 02:45:28 +01:00
|
|
|
"github.com/TwinProduction/gatus/storage"
|
2020-10-30 16:30:03 +01:00
|
|
|
"github.com/TwinProduction/gatus/watchdog"
|
2019-09-05 01:37:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-12-04 22:44:35 +01:00
|
|
|
cfg := loadConfiguration()
|
2020-04-15 01:20:00 +02:00
|
|
|
go watchdog.Monitor(cfg)
|
2021-02-06 02:45:28 +01:00
|
|
|
go controller.Handle()
|
|
|
|
// Wait for termination signal
|
|
|
|
sig := make(chan os.Signal, 1)
|
|
|
|
done := make(chan bool, 1)
|
|
|
|
signal.Notify(sig, os.Interrupt, os.Kill, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
<-sig
|
|
|
|
log.Println("Received interruption signal, attempting to gracefully shut down")
|
|
|
|
controller.Shutdown()
|
|
|
|
err := storage.Get().Save()
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Failed to save storage provider:", err.Error())
|
|
|
|
}
|
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
<-done
|
|
|
|
log.Println("Shutting down")
|
2019-09-07 03:59:50 +02:00
|
|
|
}
|
|
|
|
|
2019-12-04 22:44:35 +01:00
|
|
|
func loadConfiguration() *config.Config {
|
|
|
|
var err error
|
2020-03-08 23:16:39 +01:00
|
|
|
customConfigFile := os.Getenv("GATUS_CONFIG_FILE")
|
|
|
|
if len(customConfigFile) > 0 {
|
|
|
|
err = config.Load(customConfigFile)
|
2019-12-04 22:44:35 +01:00
|
|
|
} else {
|
|
|
|
err = config.LoadDefaultConfiguration()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return config.Get()
|
|
|
|
}
|