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:
commit
806b9a5521
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user