lotus/cmd/lotus-seal-worker/main.go

92 lines
1.9 KiB
Go
Raw Normal View History

package main
2019-11-21 00:52:59 +00:00
import (
2019-11-21 18:38:43 +00:00
"github.com/mitchellh/go-homedir"
2019-11-21 00:52:59 +00:00
"os"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/api"
2019-11-21 00:52:59 +00:00
"github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli"
)
var log = logging.Logger("main")
func main() {
logging.SetLogLevel("*", "INFO")
log.Info("Starting lotus worker")
local := []*cli.Command{
runCmd,
}
app := &cli.App{
2019-11-22 16:25:56 +00:00
Name: "lotus-seal-worker",
2019-11-21 00:52:59 +00:00
Usage: "Remote storage miner worker",
Version: build.Version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"WORKER_PATH"},
Value: "~/.lotusworker", // TODO: Consider XDG_DATA_HOME
},
&cli.StringFlag{
2019-11-21 16:10:04 +00:00
Name: "storagerepo",
EnvVars: []string{"LOTUS_STORAGE_PATH"},
2019-11-21 00:52:59 +00:00
Value: "~/.lotusstorage", // TODO: Consider XDG_DATA_HOME
},
},
Commands: local,
}
if err := app.Run(os.Args); err != nil {
2019-11-21 18:38:43 +00:00
log.Warnf("%+v", err)
2019-11-21 00:52:59 +00:00
return
}
}
var runCmd = &cli.Command{
Name: "run",
Usage: "Start lotus worker",
2019-11-21 00:52:59 +00:00
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
2019-11-21 18:38:43 +00:00
return xerrors.Errorf("getting miner api: %w", err)
2019-11-21 00:52:59 +00:00
}
defer closer()
ctx := lcli.ReqContext(cctx)
2019-11-21 18:38:43 +00:00
_, auth, err := lcli.GetRawAPI(cctx, "storagerepo")
2019-11-21 16:10:04 +00:00
_, storageAddr, err := lcli.RepoInfo(cctx, "storagerepo")
if err != nil {
2019-11-21 18:38:43 +00:00
return xerrors.Errorf("getting miner repo: %w", err)
2019-11-21 16:10:04 +00:00
}
2019-11-21 18:38:43 +00:00
r, err := homedir.Expand(cctx.String("repo"))
2019-11-21 16:10:04 +00:00
if err != nil {
return err
}
2019-11-21 00:52:59 +00:00
v, err := nodeApi.Version(ctx)
if err != nil {
return err
}
if v.APIVersion != build.APIVersion {
return xerrors.Errorf("lotus-storage-miner API version doesn't match: local: ", api.Version{APIVersion: build.APIVersion})
2019-11-21 00:52:59 +00:00
}
go func() {
<-ctx.Done()
2019-12-04 16:53:32 +00:00
log.Warn("Shutting down..")
2019-11-21 00:52:59 +00:00
}()
2019-11-21 18:38:43 +00:00
return acceptJobs(ctx, nodeApi, "http://"+storageAddr, auth, r)
2019-11-21 00:52:59 +00:00
},
}