2018-05-15 18:27:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-18 17:48:52 +00:00
|
|
|
"context"
|
2019-12-30 19:53:52 +00:00
|
|
|
"fmt"
|
2018-05-15 18:27:32 +00:00
|
|
|
"os"
|
2019-12-31 00:56:58 +00:00
|
|
|
"time"
|
2018-05-15 18:27:32 +00:00
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
2020-11-12 04:28:31 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/cmd/influxd/inspect"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/cmd/influxd/launcher"
|
2021-10-06 16:37:36 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/cmd/influxd/recovery"
|
2020-09-03 21:23:51 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/cmd/influxd/upgrade"
|
2020-08-26 17:46:47 +00:00
|
|
|
_ "github.com/influxdata/influxdb/v2/tsdb/engine/tsm1"
|
|
|
|
_ "github.com/influxdata/influxdb/v2/tsdb/index/tsi1"
|
2019-03-13 23:06:50 +00:00
|
|
|
"github.com/spf13/cobra"
|
2020-11-12 04:28:31 +00:00
|
|
|
"github.com/spf13/viper"
|
2018-05-15 18:27:32 +00:00
|
|
|
)
|
|
|
|
|
2019-01-18 13:38:58 +00:00
|
|
|
var (
|
|
|
|
version = "dev"
|
|
|
|
commit = "none"
|
2020-07-07 21:17:47 +00:00
|
|
|
date = ""
|
2019-01-18 13:38:58 +00:00
|
|
|
)
|
|
|
|
|
2020-06-18 17:48:52 +00:00
|
|
|
func main() {
|
2020-07-07 21:17:47 +00:00
|
|
|
if len(date) == 0 {
|
|
|
|
date = time.Now().UTC().Format(time.RFC3339)
|
|
|
|
}
|
|
|
|
|
2019-03-13 23:06:50 +00:00
|
|
|
influxdb.SetBuildInfo(version, commit, date)
|
2020-06-18 17:48:52 +00:00
|
|
|
|
2021-01-19 21:26:44 +00:00
|
|
|
ctx := context.Background()
|
2020-11-12 04:28:31 +00:00
|
|
|
v := viper.New()
|
2021-01-19 21:26:44 +00:00
|
|
|
|
2021-03-04 22:18:21 +00:00
|
|
|
rootCmd, err := launcher.NewInfluxdCommand(ctx, v)
|
|
|
|
if err != nil {
|
|
|
|
handleErr(err.Error())
|
|
|
|
}
|
2020-10-01 14:42:19 +00:00
|
|
|
// upgrade binds options to env variables, so it must be added after rootCmd is initialized
|
2021-03-04 22:18:21 +00:00
|
|
|
upgradeCmd, err := upgrade.NewCommand(ctx, v)
|
|
|
|
if err != nil {
|
|
|
|
handleErr(err.Error())
|
|
|
|
}
|
|
|
|
rootCmd.AddCommand(upgradeCmd)
|
|
|
|
inspectCmd, err := inspect.NewCommand(v)
|
|
|
|
if err != nil {
|
|
|
|
handleErr(err.Error())
|
|
|
|
}
|
|
|
|
rootCmd.AddCommand(inspectCmd)
|
2020-11-11 21:37:36 +00:00
|
|
|
rootCmd.AddCommand(versionCmd())
|
2021-10-06 16:37:36 +00:00
|
|
|
rootCmd.AddCommand(recovery.NewCommand())
|
2020-10-01 14:42:19 +00:00
|
|
|
|
2020-11-11 21:37:36 +00:00
|
|
|
rootCmd.SilenceUsage = true
|
2020-06-18 17:48:52 +00:00
|
|
|
if err := rootCmd.Execute(); err != nil {
|
2021-03-04 22:18:21 +00:00
|
|
|
handleErr(fmt.Sprintf("See '%s -h' for help", rootCmd.CommandPath()))
|
2019-03-13 23:06:50 +00:00
|
|
|
}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
2020-11-11 21:37:36 +00:00
|
|
|
|
2021-03-04 22:18:21 +00:00
|
|
|
func handleErr(err string) {
|
|
|
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2020-11-11 21:37:36 +00:00
|
|
|
func versionCmd() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "version",
|
|
|
|
Short: "Print the influxd server version",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
fmt.Printf("InfluxDB %s (git: %s) build_date: %s\n", version, commit, date)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|