Skip to content

Commit

Permalink
sptool: Initial structure
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Mar 18, 2024
1 parent ebf8cf9 commit 404c496
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CLEAN+=build/.update-modules
deps: $(BUILD_DEPS)
.PHONY: deps

build-devnets: build lotus-seed lotus-shed curio
build-devnets: build lotus-seed lotus-shed curio sptool
.PHONY: build-devnets

debug: GOFLAGS+=-tags=debug
Expand Down Expand Up @@ -106,6 +106,12 @@ BINS+=curio
cu2k: GOFLAGS+=-tags=2k
cu2k: curio

sptool: $(BUILD_DEPS)
rm -f sptool
$(GOCC) build $(GOFLAGS) -o sptool ./cmd/sptool
.PHONY: sptool
BINS+=sptool

lotus-worker: $(BUILD_DEPS)
rm -f lotus-worker
$(GOCC) build $(GOFLAGS) -o lotus-worker ./cmd/lotus-worker
Expand All @@ -124,13 +130,13 @@ lotus-gateway: $(BUILD_DEPS)
.PHONY: lotus-gateway
BINS+=lotus-gateway

build: lotus lotus-miner lotus-worker curio
build: lotus lotus-miner lotus-worker curio sptool
@[[ $$(type -P "lotus") ]] && echo "Caution: you have \
an existing lotus binary in your PATH. This may cause problems if you don't run 'sudo make install'" || true

.PHONY: build

install: install-daemon install-miner install-worker install-curio
install: install-daemon install-miner install-worker install-curio install-sptool

install-daemon:
install -C ./lotus /usr/local/bin/lotus
Expand All @@ -141,6 +147,9 @@ install-miner:
install-curio:
install -C ./curio /usr/local/bin/curio

install-sptool:
install -C ./sptool /usr/local/bin/sptool

install-worker:
install -C ./lotus-worker /usr/local/bin/lotus-worker

Expand All @@ -159,6 +168,9 @@ uninstall-miner:
uninstall-curio:
rm -f /usr/local/bin/curio

uninstall-sptool:
rm -f /usr/local/bin/sptool

uninstall-worker:
rm -f /usr/local/bin/lotus-worker

Expand Down Expand Up @@ -260,7 +272,7 @@ install-miner-service: install-miner install-daemon-service
@echo "To start the service, run: 'sudo systemctl start lotus-miner'"
@echo "To enable the service on startup, run: 'sudo systemctl enable lotus-miner'"

install-curio-service: install-curio install-daemon-service
install-curio-service: install-curio install-sptool install-daemon-service
mkdir -p /etc/systemd/system
mkdir -p /var/log/lotus
install -C -m 0644 ./scripts/curio.service /etc/systemd/system/curio.service
Expand Down Expand Up @@ -401,12 +413,12 @@ gen: actors-code-gen type-gen cfgdoc-gen docsgen api-gen circleci

jen: gen

snap: lotus lotus-miner lotus-worker curio
snap: lotus lotus-miner lotus-worker curio sptool
snapcraft
# snapcraft upload ./lotus_*.snap

# separate from gen because it needs binaries
docsgen-cli: lotus lotus-miner lotus-worker curio
docsgen-cli: lotus lotus-miner lotus-worker curio sptool
python3 ./scripts/generate-lotus-cli.py
./lotus config default > documentation/en/default-lotus-config.toml
./lotus-miner config default > documentation/en/default-lotus-miner-config.toml
Expand Down
9 changes: 9 additions & 0 deletions cmd/sptool/actor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import "github.com/urfave/cli/v2"

var actorCmd = &cli.Command{
Name: "actor",
Usage: "Manage Filecoin Miner Actor Metadata",
Subcommands: []*cli.Command{},
}
59 changes: 59 additions & 0 deletions cmd/sptool/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"context"
"fmt"
"github.com/filecoin-project/lotus/build"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
"os"
"os/signal"
)

var log = logging.Logger("sptool")

func main() {
local := []*cli.Command{}

app := &cli.App{
Name: "sptool",
Usage: "Manage Filecoin Miner Actor",
Version: build.UserVersion(),
Commands: local,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"LOTUS_PATH"},
Hidden: true,
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
},
&cli.StringFlag{
Name: "log-level",
Value: "info",
},
},
Before: func(cctx *cli.Context) error {
return logging.SetLogLevel("sptool", cctx.String("sptool"))
},
}

// terminate early on ctrl+c
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-c
cancel()
fmt.Println("Received interrupt, shutting down... Press CTRL+C again to force shutdown")
<-c
fmt.Println("Forcing stop")
os.Exit(1)
}()

if err := app.RunContext(ctx, os.Args); err != nil {
log.Errorf("%+v", err)
os.Exit(1)
return
}

}
3 changes: 2 additions & 1 deletion scripts/generate-lotus-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ def get_cmd_recursively(cur_cmd):
generate_lotus_cli('lotus')
generate_lotus_cli('lotus-miner')
generate_lotus_cli('lotus-worker')
generate_lotus_cli('curio')
generate_lotus_cli('curio')
generate_lotus_cli('sptool')

0 comments on commit 404c496

Please sign in to comment.