in cmd/server/main.go [67:123]
func main() {
defer logger.Sync()
ctx, cancelFn := context.WithCancel(context.Background())
// os signal handler
shutdownCh := make(chan struct{})
registerSignal(func() {
close(shutdownCh)
cancelFn()
})
flag.Parse()
logger.Get().Info("Kvrocks controller is running with version: " + version.Version)
cfg := config.Default()
if len(configPath) != 0 {
content, err := os.ReadFile(configPath)
if err != nil {
logger.Get().With(zap.Error(err)).Error("Failed to read the config file")
return
}
if err := yaml.Unmarshal(content, cfg); err != nil {
logger.Get().With(zap.Error(err)).Error("Failed to unmarshal the config file")
return
}
}
if err := cfg.Validate(); err != nil {
logger.Get().With(zap.Error(err)).Error("Failed to validate the config file")
return
}
if cfg.Log != nil && cfg.Log.Filename != "" {
logger.Get().Info("Logs will be saved to " + cfg.Log.Filename)
if err := logger.InitLoggerRotate(cfg.Log.Level, cfg.Log.Filename, cfg.Log.MaxBackups, cfg.Log.MaxAge, cfg.Log.MaxSize, cfg.Log.Compress); err != nil {
logger.Get().With(zap.Error(err)).Error("Failed to init the log rotate")
return
}
}
srv, err := server.NewServer(cfg)
if err != nil {
logger.Get().With(zap.Error(err)).Error("Failed to create the server")
return
}
if err := srv.Start(ctx); err != nil {
logger.Get().With(zap.Error(err)).Error("Failed to start the server")
return
}
// wait for the term signal
<-shutdownCh
if err := srv.Stop(); err != nil {
logger.Get().With(zap.Error(err)).Error("Failed to close the server")
} else {
logger.Get().Info("Bye bye, Kvrocks controller was exited")
}
}