INNER CODE UNIT · Go
runServeWithGracefulShutdown
powerman/go-monolith-example · cmd/mono/main.go:117
func runServeWithGracefulShutdown(_ *cobra.Command, _ []string) error {
log.Info("started", "version", def.Version())
defer log.Info("finished", "version", def.Version())
ctxStartup, cancel := context.WithTimeout(context.Background(), serveStartupTimeout.Value(nil))
defer cancel()
ctxShutdown, shutdown := context.WithCancel(context.Background())
ctxShutdown, _ = signal.NotifyContext(ctxShutdown, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGABRT, syscall.SIGTERM)
go func() {
<-ctxShutdown.Done()
time.Sleep(serveShutdownTimeout.Value(nil))
log.PrintErr("failed to graceful shutdown", "version", def.Version())
os.Exit(1)
}()
services := make([]func(Ctx) error, len(embeddedServices))
for i := range embeddedServices {