Merge pull request #10877 from filecoin-project/lotus-shed-cancel-context

feat: run lotus-shed commands in context that is cancelled on sigterm
This commit is contained in:
Friðrik Ásmundsson 2023-05-27 10:30:52 +00:00 committed by GitHub
commit b269a1ba35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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, shutting down... Press CTRL+C again to force shutdown")
<-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