feat: run lotus-shed commands in context that is cancelled on sigterm

This commit is contained in:
Fridrik Asmundsson 2023-05-16 11:25:57 +00:00
parent bc6017194d
commit 0131781808

View File

@ -1,8 +1,10 @@
package main
import (
"context"
"fmt"
"os"
"os/signal"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
@ -118,7 +120,20 @@ func main() {
},
}
if err := app.Run(os.Args); err != nil {
// terminate early on ctrl+c
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-c
cancel()
fmt.Println("Received interrupt, stopping... Press CTRL+C again to force stop")
<-c
fmt.Println("Forcing stop")
os.Exit(1)
}()
if err := app.RunContext(ctx, os.Args); err != nil {
log.Errorf("%+v", err)
os.Exit(1)
return