diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index ce2a32cd4..5aec2f52f 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -60,6 +60,7 @@ func main() { storageCmd, setCmd, waitQuietCmd, + resourcesCmd, tasksCmd, } diff --git a/cmd/lotus-seal-worker/resources.go b/cmd/lotus-seal-worker/resources.go new file mode 100644 index 000000000..b3a01713c --- /dev/null +++ b/cmd/lotus-seal-worker/resources.go @@ -0,0 +1,72 @@ +package main + +import ( + "fmt" + "os" + "sort" + + "github.com/urfave/cli/v2" + + "github.com/filecoin-project/lotus/extern/sector-storage/storiface" +) + +var resourcesCmd = &cli.Command{ + Name: "resources", + Usage: "Manage resource table overrides", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Usage: "print all resource envvars", + }, + &cli.BoolFlag{ + Name: "default", + Usage: "print all resource envvars", + }, + }, + Action: func(cctx *cli.Context) error { + def := map[string]string{} + set := map[string]string{} + all := map[string]string{} + + _, err := storiface.ParseResourceEnv(func(key, d string) (string, bool) { + if d != "" { + all[key] = d + def[key] = d + } + + s, ok := os.LookupEnv(key) + if ok { + all[key] = s + set[key] = s + } + + return s, ok + }) + if err != nil { + return err + } + + printMap := func(m map[string]string) { + var arr []string + for k, v := range m { + arr = append(arr, fmt.Sprintf("%s=%s", k, v)) + } + sort.Strings(arr) + for _, s := range arr { + fmt.Println(s) + } + } + + if cctx.Bool("default") { + printMap(def) + } else { + if cctx.Bool("all") { + printMap(all) + } else { + printMap(set) + } + } + + return nil + }, +} diff --git a/documentation/en/cli-lotus-worker.md b/documentation/en/cli-lotus-worker.md index 3b0c7ae4f..bbfc7bb6c 100644 --- a/documentation/en/cli-lotus-worker.md +++ b/documentation/en/cli-lotus-worker.md @@ -15,6 +15,7 @@ COMMANDS: storage manage sector storage set Manage worker settings wait-quiet Block until all running tasks exit + resources Manage resource table overrides tasks Manage task processing help, h Shows a list of commands or help for one command @@ -127,6 +128,21 @@ OPTIONS: ``` +## lotus-worker resources +``` +NAME: + lotus-worker resources - Manage resource table overrides + +USAGE: + lotus-worker resources [command options] [arguments...] + +OPTIONS: + --all print all resource envvars (default: false) + --default print all resource envvars (default: false) + --help, -h show help (default: false) + +``` + ## lotus-worker tasks ``` NAME: