MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / main

Function main

cmd/server/main.go:67–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67func main() {
68 defer logger.Sync()
69
70 ctx, cancelFn := context.WithCancel(context.Background())
71 // os signal handler
72 shutdownCh := make(chan struct{})
73 registerSignal(func() {
74 close(shutdownCh)
75 cancelFn()
76 })
77
78 flag.Parse()
79
80 logger.Get().Info("Kvrocks controller is running with version: " + version.Version)
81 cfg := config.Default()
82 if len(configPath) != 0 {
83 content, err := os.ReadFile(configPath)
84 if err != nil {
85 logger.Get().With(zap.Error(err)).Error("Failed to read the config file")
86 return
87 }
88 if err := yaml.Unmarshal(content, cfg); err != nil {
89 logger.Get().With(zap.Error(err)).Error("Failed to unmarshal the config file")
90 return
91 }
92 }
93 if err := cfg.Validate(); err != nil {
94 logger.Get().With(zap.Error(err)).Error("Failed to validate the config file")
95 return
96 }
97
98 if cfg.Log != nil && cfg.Log.Filename != "" {
99 logger.Get().Info("Logs will be saved to " + cfg.Log.Filename)
100 if err := logger.InitLoggerRotate(cfg.Log.Level, cfg.Log.Filename, cfg.Log.MaxBackups, cfg.Log.MaxAge, cfg.Log.MaxSize, cfg.Log.Compress); err != nil {
101 logger.Get().With(zap.Error(err)).Error("Failed to init the log rotate")
102 return
103 }
104 }
105
106 srv, err := server.NewServer(cfg)
107 if err != nil {
108 logger.Get().With(zap.Error(err)).Error("Failed to create the server")
109 return
110 }
111 if err := srv.Start(ctx); err != nil {
112 logger.Get().With(zap.Error(err)).Error("Failed to start the server")
113 return
114 }
115
116 // wait for the term signal
117 <-shutdownCh
118 if err := srv.Stop(); err != nil {
119 logger.Get().With(zap.Error(err)).Error("Failed to close the server")
120 } else {
121 logger.Get().Info("Bye bye, Kvrocks controller was exited")
122 }
123}

Callers

nothing calls this directly

Calls 11

StartMethod · 0.95
StopMethod · 0.95
SyncFunction · 0.92
GetFunction · 0.92
DefaultFunction · 0.92
InitLoggerRotateFunction · 0.92
NewServerFunction · 0.92
registerSignalFunction · 0.85
InfoMethod · 0.80
ErrorMethod · 0.80
ValidateMethod · 0.45

Tested by

no test coverage detected