Add stop cmd for lotus worker
This commit is contained in:
parent
a843c52e38
commit
dfea74cca8
@ -76,6 +76,10 @@ type Worker interface {
|
|||||||
|
|
||||||
// Like ProcessSession, but returns an error when worker is disabled
|
// Like ProcessSession, but returns an error when worker is disabled
|
||||||
Session(context.Context) (uuid.UUID, error) //perm:admin
|
Session(context.Context) (uuid.UUID, error) //perm:admin
|
||||||
|
|
||||||
|
// Trigger shutdown
|
||||||
|
Shutdown(context.Context) error //perm:admin
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ storiface.WorkerCalls = *new(Worker)
|
var _ storiface.WorkerCalls = *new(Worker)
|
||||||
|
@ -965,6 +965,8 @@ type WorkerStruct struct {
|
|||||||
|
|
||||||
SetEnabled func(p0 context.Context, p1 bool) error `perm:"admin"`
|
SetEnabled func(p0 context.Context, p1 bool) error `perm:"admin"`
|
||||||
|
|
||||||
|
Shutdown func(p0 context.Context) error `perm:"admin"`
|
||||||
|
|
||||||
StorageAddLocal func(p0 context.Context, p1 string) error `perm:"admin"`
|
StorageAddLocal func(p0 context.Context, p1 string) error `perm:"admin"`
|
||||||
|
|
||||||
TaskDisable func(p0 context.Context, p1 sealtasks.TaskType) error `perm:"admin"`
|
TaskDisable func(p0 context.Context, p1 sealtasks.TaskType) error `perm:"admin"`
|
||||||
@ -5560,6 +5562,17 @@ func (s *WorkerStub) SetEnabled(p0 context.Context, p1 bool) error {
|
|||||||
return ErrNotSupported
|
return ErrNotSupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *WorkerStruct) Shutdown(p0 context.Context) error {
|
||||||
|
if s.Internal.Shutdown == nil {
|
||||||
|
return ErrNotSupported
|
||||||
|
}
|
||||||
|
return s.Internal.Shutdown(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *WorkerStub) Shutdown(p0 context.Context) error {
|
||||||
|
return ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
func (s *WorkerStruct) StorageAddLocal(p0 context.Context, p1 string) error {
|
func (s *WorkerStruct) StorageAddLocal(p0 context.Context, p1 string) error {
|
||||||
if s.Internal.StorageAddLocal == nil {
|
if s.Internal.StorageAddLocal == nil {
|
||||||
return ErrNotSupported
|
return ErrNotSupported
|
||||||
|
@ -55,6 +55,7 @@ func main() {
|
|||||||
|
|
||||||
local := []*cli.Command{
|
local := []*cli.Command{
|
||||||
runCmd,
|
runCmd,
|
||||||
|
stopCmd,
|
||||||
infoCmd,
|
infoCmd,
|
||||||
storageCmd,
|
storageCmd,
|
||||||
setCmd,
|
setCmd,
|
||||||
@ -115,6 +116,27 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var stopCmd = &cli.Command{
|
||||||
|
Name: "stop",
|
||||||
|
Usage: "Stop a running lotus worker",
|
||||||
|
Flags: []cli.Flag{},
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
api, closer, err := lcli.GetWorkerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
err = api.Shutdown(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var runCmd = &cli.Command{
|
var runCmd = &cli.Command{
|
||||||
Name: "run",
|
Name: "run",
|
||||||
Usage: "Start lotus worker",
|
Usage: "Start lotus worker",
|
||||||
@ -623,6 +645,15 @@ var runCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-workerApi.Done()
|
||||||
|
log.Warn("Shutting down...")
|
||||||
|
if err := srv.Shutdown(context.TODO()); err != nil {
|
||||||
|
log.Errorf("shutting down RPC server failed: %s", err)
|
||||||
|
}
|
||||||
|
log.Warn("Graceful shutdown successful")
|
||||||
|
}()
|
||||||
|
|
||||||
return srv.Serve(nl)
|
return srv.Serve(nl)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -118,4 +118,8 @@ func (w *Worker) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error)
|
|||||||
return build.OpenRPCDiscoverJSON_Worker(), nil
|
return build.OpenRPCDiscoverJSON_Worker(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Worker) Shutdown(ctx context.Context) error {
|
||||||
|
return w.LocalWorker.Close()
|
||||||
|
}
|
||||||
|
|
||||||
var _ storiface.WorkerCalls = &Worker{}
|
var _ storiface.WorkerCalls = &Worker{}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
* [Paths](#Paths)
|
* [Paths](#Paths)
|
||||||
* [Remove](#Remove)
|
* [Remove](#Remove)
|
||||||
* [Session](#Session)
|
* [Session](#Session)
|
||||||
|
* [Shutdown](#Shutdown)
|
||||||
* [Version](#Version)
|
* [Version](#Version)
|
||||||
* [Add](#Add)
|
* [Add](#Add)
|
||||||
* [AddPiece](#AddPiece)
|
* [AddPiece](#AddPiece)
|
||||||
@ -1453,6 +1454,16 @@ Inputs: `null`
|
|||||||
|
|
||||||
Response: `"07070707-0707-0707-0707-070707070707"`
|
Response: `"07070707-0707-0707-0707-070707070707"`
|
||||||
|
|
||||||
|
### Shutdown
|
||||||
|
Trigger shutdown
|
||||||
|
|
||||||
|
|
||||||
|
Perms: admin
|
||||||
|
|
||||||
|
Inputs: `null`
|
||||||
|
|
||||||
|
Response: `{}`
|
||||||
|
|
||||||
### Version
|
### Version
|
||||||
|
|
||||||
|
|
||||||
|
@ -829,6 +829,10 @@ func (l *LocalWorker) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LocalWorker) Done() <-chan struct{} {
|
||||||
|
return l.closing
|
||||||
|
}
|
||||||
|
|
||||||
// WaitQuiet blocks as long as there are tasks running
|
// WaitQuiet blocks as long as there are tasks running
|
||||||
func (l *LocalWorker) WaitQuiet() {
|
func (l *LocalWorker) WaitQuiet() {
|
||||||
l.running.Wait()
|
l.running.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user