diff --git a/shutdown/shutdown.go b/shutdown/shutdown.go index 7fe7ab04..d2bd3ca7 100644 --- a/shutdown/shutdown.go +++ b/shutdown/shutdown.go @@ -3,13 +3,14 @@ package shutdown import ( "os" "os/signal" + "sync" "github.com/flanksource/commons/logger" ) var shutdownHooks []func() -func Shutdown() { +var Shutdown = sync.OnceFunc(func() { if len(shutdownHooks) == 0 { return } @@ -18,7 +19,7 @@ func Shutdown() { fn() } shutdownHooks = []func(){} -} +}) func ShutdownAndExit(code int, msg string) { Shutdown()