work on signals

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2024-07-24 13:21:30 +02:00
parent 06cc70f978
commit d6045a74ea
7 changed files with 28 additions and 24 deletions
+7 -14
View File
@@ -37,7 +37,7 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
gr := run.Group{}
ctx, cancel := defineContext(cfg)
ctx, cancel := context.WithCancel(c.Context)
defer cancel()
@@ -51,7 +51,9 @@ func Server(cfg *config.Config) *cli.Command {
runtime.WithRegistry(reg),
runtime.WithTraceProvider(traceProvider),
)
logger.Info().
Str("server", cfg.Service.Name).
Msg("reva runtime exited")
return nil
}, func(err error) {
logger.Error().
@@ -60,7 +62,6 @@ func Server(cfg *config.Config) *cli.Command {
Msg("Shutting down server")
cancel()
os.Exit(1)
})
debugServer, err := debug.Server(
@@ -74,6 +75,9 @@ func Server(cfg *config.Config) *cli.Command {
}
gr.Add(debugServer.ListenAndServe, func(_ error) {
logger.Info().
Str("server", cfg.Service.Name).
Msg("Shutting down debug erver")
cancel()
})
@@ -86,14 +90,3 @@ func Server(cfg *config.Config) *cli.Command {
},
}
}
// defineContext sets the context for the service. If there is a context configured it will create a new child from it,
// if not, it will create a root context that can be cancelled.
func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) {
return func() (context.Context, context.CancelFunc) {
if cfg.Context == nil {
return context.WithCancel(context.Background())
}
return context.WithCancel(cfg.Context)
}()
}