From e0d66fe0eeccf1b3c08f9761477375f87fdecbe7 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Fri, 7 May 2021 11:46:20 +0200 Subject: [PATCH] Exit with an error code if not exiting due to a signal Icinga DB should not exit with code 0 if it does so due to an error. --- cmd/icingadb/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/icingadb/main.go b/cmd/icingadb/main.go index d6baa096..92b249a1 100644 --- a/cmd/icingadb/main.go +++ b/cmd/icingadb/main.go @@ -17,7 +17,16 @@ import ( "syscall" ) +const ( + ExitSuccess = 0 + ExitFailure = 1 +) + func main() { + os.Exit(run()) +} + +func run() int { cmd := command.New() logger := cmd.Logger defer logger.Sync() @@ -103,13 +112,13 @@ func main() { // otherwise there is no way to get Icinga DB back into a working state. panic(errors.New("HA exited without an error but main context isn't cancelled")) } - return + return ExitFailure case <-ctx.Done(): - return + panic(errors.New("main context closed unexpectedly")) case s := <-sig: logger.Infow("Exiting due to signal", zap.String("signal", s.String())) cancelCtx() - return + return ExitSuccess } } }