Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat_: graceful shutdown with status-backend #6189

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 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,17 @@ func main() {
srv.RegisterMobileAPI()
srv.Serve()
}

// haltOnInterruptSignal catches interrupt signal (SIGINT) and
// stops the node. It times out after 5 seconds
igor-sirotin marked this conversation as resolved.
Show resolved Hide resolved
// if the node can not be stopped.
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)
}
Loading