From 8b95c814886fd828de19acb2d1c6c384976c6bb0 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Tue, 10 Dec 2024 19:58:30 +0000 Subject: [PATCH] feat_: graceful shutdown with status-backend (#6189) * fix_: graceful shutdown node in status-backend * fix_: function doc --- cmd/status-backend/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/status-backend/main.go b/cmd/status-backend/main.go index 18af96a2b29..cb3a499ddbc 100644 --- a/cmd/status-backend/main.go +++ b/cmd/status-backend/main.go @@ -4,6 +4,8 @@ import ( "flag" stdlog "log" "os" + "os/signal" + "syscall" "golang.org/x/crypto/ssh/terminal" @@ -13,6 +15,7 @@ import ( "github.com/status-im/status-go/internal/sentry" "github.com/status-im/status-go/internal/version" "github.com/status-im/status-go/logutils" + statusgo "github.com/status-im/status-go/mobile" ) var ( @@ -39,6 +42,7 @@ func main() { defer sentry.Recover() flag.Parse() + go handleInterrupts() srv := server.NewServer() srv.Setup() @@ -57,3 +61,16 @@ func main() { srv.RegisterMobileAPI() srv.Serve() } + +// handleInterrupts catches interrupt signal (SIGTERM/SIGINT) and +// gracefully logouts and stops the node. +func handleInterrupts() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) + defer signal.Stop(ch) + + receivedSignal := <-ch + logger.Info("interrupt signal received", "signal", receivedSignal) + _ = statusgo.Logout() + os.Exit(0) +}