From 88d59f6a5f8788212436b2b9c4fede8f1c65ed12 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 14 Dec 2022 15:42:50 -0500 Subject: [PATCH] Set notifications for SIGTERM and SIGINT when we start the cli --- cli/helper.go | 9 +++++++++ node/shutdown.go | 1 + 2 files changed, 10 insertions(+) diff --git a/cli/helper.go b/cli/helper.go index c4a61397c..81a5bb033 100644 --- a/cli/helper.go +++ b/cli/helper.go @@ -4,6 +4,8 @@ import ( "fmt" "io" "os" + "os/signal" + "syscall" ufcli "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -36,6 +38,13 @@ func IncorrectNumArgs(cctx *ufcli.Context) error { } func RunApp(app *ufcli.App) { + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGTERM, syscall.SIGINT) + go func() { + <-c + os.Exit(1) + }() + if err := app.Run(os.Args); err != nil { if os.Getenv("LOTUS_DEV") != "" { log.Warnf("%+v", err) diff --git a/node/shutdown.go b/node/shutdown.go index e630031da..f44ca0857 100644 --- a/node/shutdown.go +++ b/node/shutdown.go @@ -51,6 +51,7 @@ func MonitorShutdown(triggerCh <-chan struct{}, handlers ...ShutdownHandler) <-c close(out) }() + signal.Reset(syscall.SIGTERM, syscall.SIGINT) signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT) return out }