feat: run lotus-shed commands in context that is cancelled on sigterm
This commit is contained in:
parent
bc6017194d
commit
0131781808
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user