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