diff --git a/cli/sync.go b/cli/sync.go index ab50889c1..ba0f7963f 100644 --- a/cli/sync.go +++ b/cli/sync.go @@ -2,6 +2,9 @@ package cli import ( "fmt" + "os" + "os/signal" + "syscall" "time" cid "github.com/ipfs/go-cid" @@ -64,6 +67,9 @@ var syncWaitCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) + sigChan := make(chan os.Signal, 2) + signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT) + for { ss, err := napi.SyncState(ctx) if err != nil { @@ -81,7 +87,12 @@ var syncWaitCmd = &cli.Command{ return nil } - time.Sleep(1 * time.Second) + select { + case <-sigChan: + fmt.Println("\nExit by user") + return nil + case <-time.After(1 * time.Second): + } } }, }