Set notifications for SIGTERM and SIGINT when we start the cli

This commit is contained in:
Geoff Stuart 2022-12-14 15:42:50 -05:00
parent f3830b60ae
commit 88d59f6a5f
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
}