|
|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"FRMS/internal/pkg/config"
|
|
|
|
|
"FRMS/internal/pkg/logging"
|
|
|
|
@ -27,6 +28,9 @@ func LoadConfig(file, path, ext string) (*viper.Viper, error) {
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
|
|
fmt.Printf("starting server... ")
|
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
|
|
gracefulShutdown := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
|
|
|
@ -48,19 +52,23 @@ func main() {
|
|
|
|
|
|
|
|
|
|
c := NewCoordinator(conf, errCh)
|
|
|
|
|
go c.Start()
|
|
|
|
|
logging.Debug(logging.DStart, "CCO 01 Server %s started", conf.Get("name"))
|
|
|
|
|
logging.Debug(logging.DStart, "CCO 01 %s started", conf.Get("name"))
|
|
|
|
|
|
|
|
|
|
elapsed := time.Now().Sub(start)
|
|
|
|
|
fmt.Printf("done %v\n", elapsed.Round(time.Microsecond))
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case err := <-errCh: // blocking to wait for any errors and keep alive otherwise
|
|
|
|
|
case err := <-errCh:
|
|
|
|
|
panic(err)
|
|
|
|
|
case <-gracefulShutdown:
|
|
|
|
|
// Shutdown via INT
|
|
|
|
|
// storing config
|
|
|
|
|
fmt.Printf("\nStoring config to %s\n", conf.ConfigFileUsed())
|
|
|
|
|
fmt.Printf("\nstopping server... ")
|
|
|
|
|
start := time.Now()
|
|
|
|
|
if err := conf.WriteConfig(); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("Stored config successfully. Exiting...")
|
|
|
|
|
logging.Debug(logging.DExit, "CON wrote %s", conf.ConfigFileUsed())
|
|
|
|
|
elapsed := time.Now().Sub(start)
|
|
|
|
|
fmt.Printf("done %v\n", elapsed.Round(time.Microsecond))
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|