lotus/cmd/lotus-provider/main.go

166 lines
4.0 KiB
Go
Raw Permalink Normal View History

2023-08-23 23:57:34 +00:00
package main
import (
"context"
2023-10-16 15:28:58 +00:00
"fmt"
"os"
"os/signal"
2023-12-12 05:15:41 +00:00
"runtime/pprof"
2023-10-16 15:28:58 +00:00
"syscall"
2023-08-23 23:57:34 +00:00
"github.com/fatih/color"
logging "github.com/ipfs/go-log/v2"
"github.com/mitchellh/go-homedir"
2023-08-23 23:57:34 +00:00
"github.com/urfave/cli/v2"
"github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/cmd/lotus-provider/deps"
2023-08-23 23:57:34 +00:00
"github.com/filecoin-project/lotus/lib/lotuslog"
"github.com/filecoin-project/lotus/lib/tracing"
"github.com/filecoin-project/lotus/node/repo"
)
var log = logging.Logger("main")
2023-10-16 15:28:58 +00:00
func SetupCloseHandler() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("\r- Ctrl+C pressed in Terminal")
2023-12-15 00:13:44 +00:00
_ = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
2023-12-12 05:15:41 +00:00
panic(1)
2023-10-16 15:28:58 +00:00
}()
}
2023-08-23 23:57:34 +00:00
func main() {
2023-10-16 15:28:58 +00:00
SetupCloseHandler()
2023-08-23 23:57:34 +00:00
lotuslog.SetupLogLevels()
local := []*cli.Command{
//initCmd,
runCmd,
stopCmd,
2023-08-28 16:37:36 +00:00
configCmd,
2023-11-21 00:05:59 +00:00
testCmd,
webCmd,
2023-08-23 23:57:34 +00:00
//backupCmd,
//lcli.WithCategory("chain", actorCmd),
//lcli.WithCategory("storage", sectorsCmd),
//lcli.WithCategory("storage", provingCmd),
//lcli.WithCategory("storage", storageCmd),
//lcli.WithCategory("storage", sealingCmd),
}
jaeger := tracing.SetupJaegerTracing("lotus")
defer func() {
if jaeger != nil {
_ = jaeger.ForceFlush(context.Background())
}
}()
for _, cmd := range local {
cmd := cmd
originBefore := cmd.Before
cmd.Before = func(cctx *cli.Context) error {
if jaeger != nil {
_ = jaeger.Shutdown(cctx.Context)
}
jaeger = tracing.SetupJaegerTracing("lotus/" + cmd.Name)
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
if originBefore != nil {
return originBefore(cctx)
}
return nil
}
}
app := &cli.App{
Name: "lotus-provider",
Usage: "Filecoin decentralized storage network provider",
Version: build.UserVersion(),
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.BoolFlag{
// examined in the Before above
Name: "color",
Usage: "use color in display output",
DefaultText: "depends on output being a TTY",
},
&cli.StringFlag{
Name: "panic-reports",
EnvVars: []string{"LOTUS_PANIC_REPORT_PATH"},
Hidden: true,
Value: "~/.lotusprovider", // should follow --repo default
},
&cli.StringFlag{
2023-09-20 03:48:39 +00:00
Name: "db-host",
EnvVars: []string{"LOTUS_DB_HOST"},
Usage: "Command separated list of hostnames for yugabyte cluster",
Value: "yugabyte",
},
&cli.StringFlag{
Name: "db-name",
2023-12-04 16:18:07 +00:00
EnvVars: []string{"LOTUS_DB_NAME", "LOTUS_HARMONYDB_HOSTS"},
2023-09-20 03:48:39 +00:00
Value: "yugabyte",
},
&cli.StringFlag{
Name: "db-user",
2023-12-04 16:18:07 +00:00
EnvVars: []string{"LOTUS_DB_USER", "LOTUS_HARMONYDB_USERNAME"},
2023-09-20 03:48:39 +00:00
Value: "yugabyte",
},
&cli.StringFlag{
Name: "db-password",
2023-12-04 16:18:07 +00:00
EnvVars: []string{"LOTUS_DB_PASSWORD", "LOTUS_HARMONYDB_PASSWORD"},
2023-09-20 03:48:39 +00:00
Value: "yugabyte",
},
&cli.StringFlag{
Name: "db-port",
2023-12-04 16:18:07 +00:00
EnvVars: []string{"LOTUS_DB_PORT", "LOTUS_HARMONYDB_PORT"},
2023-08-23 23:57:34 +00:00
Hidden: true,
2023-09-20 03:48:39 +00:00
Value: "5433",
},
&cli.StringFlag{
Name: "layers",
2023-12-04 16:18:07 +00:00
EnvVars: []string{"LOTUS_LAYERS", "LOTUS_CONFIG_LAYERS"},
2023-09-20 03:48:39 +00:00
Value: "base",
2023-08-23 23:57:34 +00:00
},
2023-09-27 03:06:00 +00:00
&cli.StringFlag{
Name: deps.FlagRepoPath,
2023-09-27 03:06:00 +00:00
EnvVars: []string{"LOTUS_REPO_PATH"},
2023-11-07 04:49:42 +00:00
Value: "~/.lotusprovider",
2023-09-27 03:06:00 +00:00
},
2023-08-23 23:57:34 +00:00
cliutil.FlagVeryVerbose,
},
Commands: append(local, lcli.CommonCommands...),
Before: func(c *cli.Context) error {
return nil
},
After: func(c *cli.Context) error {
if r := recover(); r != nil {
p, err := homedir.Expand(c.String(FlagMinerRepo))
if err != nil {
log.Errorw("could not expand repo path for panic report", "error", err)
panic(r)
}
2023-08-23 23:57:34 +00:00
// Generate report in LOTUS_PATH and re-raise panic
build.GeneratePanicReport(c.String("panic-reports"), p, c.App.Name)
2023-08-23 23:57:34 +00:00
panic(r)
}
return nil
},
}
app.Setup()
app.Metadata["repoType"] = repo.Provider
lcli.RunApp(app)
}