-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathmain.go
79 lines (69 loc) · 1.88 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/cmd/influxd/downgrade"
"github.com/influxdata/influxdb/v2/cmd/influxd/inspect"
"github.com/influxdata/influxdb/v2/cmd/influxd/launcher"
"github.com/influxdata/influxdb/v2/cmd/influxd/recovery"
"github.com/influxdata/influxdb/v2/cmd/influxd/upgrade"
_ "github.com/influxdata/influxdb/v2/tsdb/engine/tsm1"
_ "github.com/influxdata/influxdb/v2/tsdb/index/tsi1"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
version = "dev"
commit = "none"
date = ""
)
func main() {
if len(date) == 0 {
date = time.Now().UTC().Format(time.RFC3339)
}
influxdb.SetBuildInfo(version, commit, date)
ctx := context.Background()
v := viper.New()
rootCmd, err := launcher.NewInfluxdCommand(ctx, v)
if err != nil {
handleErr(err.Error())
}
// upgrade binds options to env variables, so it must be added after rootCmd is initialized
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)
rootCmd.AddCommand(versionCmd())
rootCmd.AddCommand(recovery.NewCommand())
downgradeCmd, err := downgrade.NewCommand(ctx, v)
if err != nil {
handleErr(err.Error())
}
rootCmd.AddCommand(downgradeCmd)
rootCmd.SilenceUsage = true
if err := rootCmd.Execute(); err != nil {
handleErr(fmt.Sprintf("See '%s -h' for help", rootCmd.CommandPath()))
}
}
func handleErr(err string) {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
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)
},
}
}