Merge pull request #9874 from filecoin-project/gstuart/always-be-able-to-shutdown

fix: daemon: listen for SIGINT and SIGTERM even before node starts
This commit is contained in:
Geoff Stuart 2022-12-15 13:12:29 -05:00 committed by GitHub
commit 806b9a5521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -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)

View File

@ -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
}