first take at a "lotus-storage-miner stop" command

Fixes #1827
This commit is contained in:
laser 2020-06-02 12:31:21 -07:00
parent 1e8a875edb
commit ee9d9a52a9
3 changed files with 39 additions and 2 deletions

View File

@ -27,6 +27,7 @@ func main() {
initCmd,
rewardsCmd,
runCmd,
stopCmd,
sectorsCmd,
storageCmd,
setPriceCmd,

View File

@ -100,9 +100,12 @@ var runCmd = &cli.Command{
return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", storageRepoPath)
}
shutdownChan := make(chan struct{})
var minerapi api.StorageMiner
stop, err := node.New(ctx,
node.StorageMiner(&minerapi),
node.Override(new(dtypes.ShutdownCh), shutdownChan),
node.Online(),
node.Repo(r),
@ -156,8 +159,12 @@ var runCmd = &cli.Command{
sigChan := make(chan os.Signal, 2)
go func() {
<-sigChan
log.Warn("Shutting down..")
select {
case <-sigChan:
case <-shutdownChan:
}
log.Warn("Shutting down...")
if err := stop(context.TODO()); err != nil {
log.Errorf("graceful shutting down failed: %s", err)
}

View File

@ -0,0 +1,29 @@
package main
import (
_ "net/http/pprof"
"gopkg.in/urfave/cli.v2"
lcli "github.com/filecoin-project/lotus/cli"
)
var stopCmd = &cli.Command{
Name: "stop",
Usage: "Stop a running lotus storage miner",
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetAPI(cctx)
if err != nil {
return err
}
defer closer()
err = api.Shutdown(lcli.ReqContext(cctx))
if err != nil {
return err
}
return nil
},
}