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"
|
2023-12-18 17:46:37 +00:00
|
|
|
"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"
|
2024-03-15 21:38:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/deps"
|
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/guidedsetup"
|
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")
|
|
|
|
|
2024-03-28 09:09:41 +00:00
|
|
|
const (
|
|
|
|
FlagMinerRepo = "miner-repo"
|
|
|
|
)
|
|
|
|
|
2024-03-15 21:38:13 +00:00
|
|
|
func setupCloseHandler() {
|
2023-10-16 15:28:58 +00:00
|
|
|
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() {
|
|
|
|
|
|
|
|
lotuslog.SetupLogLevels()
|
|
|
|
|
|
|
|
local := []*cli.Command{
|
|
|
|
//initCmd,
|
2024-02-08 12:27:46 +00:00
|
|
|
cliCmd,
|
2023-08-23 23:57:34 +00:00
|
|
|
runCmd,
|
|
|
|
stopCmd,
|
2023-08-28 16:37:36 +00:00
|
|
|
configCmd,
|
2023-11-21 00:05:59 +00:00
|
|
|
testCmd,
|
2023-12-18 22:02:54 +00:00
|
|
|
webCmd,
|
2024-03-15 21:38:13 +00:00
|
|
|
guidedsetup.GuidedsetupCmd,
|
2024-02-12 17:03:47 +00:00
|
|
|
sealCmd,
|
2024-04-03 16:31:43 +00:00
|
|
|
marketCmd,
|
2023-08-23 23:57:34 +00:00
|
|
|
}
|
|
|
|
|
2024-03-15 21:38:13 +00:00
|
|
|
jaeger := tracing.SetupJaegerTracing("curio")
|
2023-08-23 23:57:34 +00:00
|
|
|
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)
|
|
|
|
}
|
2024-03-15 21:38:13 +00:00
|
|
|
jaeger = tracing.SetupJaegerTracing("curio/" + cmd.Name)
|
2023-08-23 23:57:34 +00:00
|
|
|
|
|
|
|
if cctx.IsSet("color") {
|
|
|
|
color.NoColor = !cctx.Bool("color")
|
|
|
|
}
|
|
|
|
|
|
|
|
if originBefore != nil {
|
|
|
|
return originBefore(cctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
app := &cli.App{
|
2024-03-15 21:38:13 +00:00
|
|
|
Name: "curio",
|
2023-08-23 23:57:34 +00:00
|
|
|
Usage: "Filecoin decentralized storage network provider",
|
|
|
|
Version: build.UserVersion(),
|
|
|
|
EnableBashCompletion: true,
|
2024-03-15 21:38:13 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
setupCloseHandler()
|
|
|
|
return nil
|
|
|
|
},
|
2023-08-23 23:57:34 +00:00
|
|
|
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",
|
2024-03-15 21:38:13 +00:00
|
|
|
EnvVars: []string{"CURIO_PANIC_REPORT_PATH"},
|
2023-08-23 23:57:34 +00:00
|
|
|
Hidden: true,
|
2024-03-15 21:38:13 +00:00
|
|
|
Value: "~/.curio", // should follow --repo default
|
2023-08-23 23:57:34 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2023-09-20 03:48:39 +00:00
|
|
|
Name: "db-host",
|
2024-03-15 21:38:13 +00:00
|
|
|
EnvVars: []string{"CURIO_DB_HOST", "CURIO_HARMONYDB_HOSTS"},
|
2023-09-20 03:48:39 +00:00
|
|
|
Usage: "Command separated list of hostnames for yugabyte cluster",
|
2024-04-03 20:00:14 +00:00
|
|
|
Value: "127.0.0.1",
|
2023-09-20 03:48:39 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "db-name",
|
2024-03-15 21:38:13 +00:00
|
|
|
EnvVars: []string{"CURIO_DB_NAME", "CURIO_HARMONYDB_NAME"},
|
2023-09-20 03:48:39 +00:00
|
|
|
Value: "yugabyte",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "db-user",
|
2024-03-15 21:38:13 +00:00
|
|
|
EnvVars: []string{"CURIO_DB_USER", "CURIO_HARMONYDB_USERNAME"},
|
2023-09-20 03:48:39 +00:00
|
|
|
Value: "yugabyte",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "db-password",
|
2024-03-15 21:38:13 +00:00
|
|
|
EnvVars: []string{"CURIO_DB_PASSWORD", "CURIO_HARMONYDB_PASSWORD"},
|
2023-09-20 03:48:39 +00:00
|
|
|
Value: "yugabyte",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "db-port",
|
2024-03-15 21:38:13 +00:00
|
|
|
EnvVars: []string{"CURIO_DB_PORT", "CURIO_HARMONYDB_PORT"},
|
2023-09-20 03:48:39 +00:00
|
|
|
Value: "5433",
|
|
|
|
},
|
2023-09-27 03:06:00 +00:00
|
|
|
&cli.StringFlag{
|
2023-12-05 04:30:40 +00:00
|
|
|
Name: deps.FlagRepoPath,
|
2024-03-15 21:38:13 +00:00
|
|
|
EnvVars: []string{"CURIO_REPO_PATH"},
|
|
|
|
Value: "~/.curio",
|
2023-09-27 03:06:00 +00:00
|
|
|
},
|
2023-08-23 23:57:34 +00:00
|
|
|
cliutil.FlagVeryVerbose,
|
|
|
|
},
|
|
|
|
Commands: append(local, lcli.CommonCommands...),
|
|
|
|
After: func(c *cli.Context) error {
|
|
|
|
if r := recover(); r != nil {
|
2023-12-18 17:46:37 +00:00
|
|
|
p, err := homedir.Expand(c.String(FlagMinerRepo))
|
|
|
|
if err != nil {
|
|
|
|
log.Errorw("could not expand repo path for panic report", "error", err)
|
|
|
|
panic(r)
|
|
|
|
}
|
|
|
|
|
2024-03-15 21:38:13 +00:00
|
|
|
// Generate report in CURIO_PATH and re-raise panic
|
2023-12-18 17:46:37 +00:00
|
|
|
build.GeneratePanicReport(c.String("panic-reports"), p, c.App.Name)
|
2023-08-23 23:57:34 +00:00
|
|
|
panic(r)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
app.Setup()
|
2024-03-15 21:38:13 +00:00
|
|
|
app.Metadata["repoType"] = repo.Curio
|
2023-08-23 23:57:34 +00:00
|
|
|
lcli.RunApp(app)
|
|
|
|
}
|