Skip to content

Commit

Permalink
feat_: graceful shutdown with status-backend (#6189)
Browse files Browse the repository at this point in the history
* fix_: graceful shutdown node in status-backend

* fix_: function doc
  • Loading branch information
igor-sirotin authored Dec 10, 2024
1 parent e6c2f89 commit 8b95c81
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/status-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"flag"
stdlog "log"
"os"
"os/signal"
"syscall"

"golang.org/x/crypto/ssh/terminal"

Expand All @@ -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 (
Expand All @@ -39,6 +42,7 @@ func main() {
defer sentry.Recover()

flag.Parse()
go handleInterrupts()

srv := server.NewServer()
srv.Setup()
Expand All @@ -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)
}

0 comments on commit 8b95c81

Please sign in to comment.