Skip to content

Commit

Permalink
feat(influxd): refactor run command to use cli.Program to respect con…
Browse files Browse the repository at this point in the history
…fig file
  • Loading branch information
jsteenb2 committed Jun 18, 2020
1 parent 8d9e3bb commit 4e4c509
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. [18595](https://github.com/influxdata/influxdb/pull/18595): Add ability to skip resources in a template by kind or by metadata.name
1. [18600](https://github.com/influxdata/influxdb/pull/18600): Extend influx apply with resource filter capabilities
1. [18601](https://github.com/influxdata/influxdb/pull/18601): Provide active config running influx config without args
1. [18606](https://github.com/influxdata/influxdb/pull/18606): Enable influxd binary to look for a config file on startup

## v2.0.0-beta.12 [2020-06-12]

Expand Down
39 changes: 28 additions & 11 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ const (
// NewCommand creates the command to run influxdb.
func NewCommand() *cobra.Command {
l := NewLauncher()
cmd := &cobra.Command{
Use: "run",
Short: "Start the influxd server (default)",
Run: func(cmd *cobra.Command, args []string) {

prog := cli.Program{
Name: "run",
Opts: launcherOpts(l),
Run: func() error {
// exit with SIGINT and SIGTERM
ctx := context.Background()
ctx = signals.WithStandardSignals(ctx)

if err := l.run(ctx); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
return err
} else if !l.Running() {
os.Exit(1)
return errors.New("the daemon is already running")
}

var wg sync.WaitGroup
Expand All @@ -120,23 +120,37 @@ func NewCommand() *cobra.Command {
defer cancel()
l.Shutdown(ctx)
wg.Wait()

return nil
},
}

buildLauncherCommand(l, cmd)
cmd := cli.NewCommand(&prog)
cmd.Long = `
Start up the daemon configured with flags/env vars/config file.
The order of precedence for config options are as follows (1 highest, 3 lowest):
1. flags
2. env vars
3. config file
A config file can be provided via the INFLUXD_CONFIG_FILE env var. If a file is
not provided via an env var, influxd will look in the current directory for a
config.yaml file. If one does not exist, then it will continue unchanged.
`
cmd.AddCommand(inspect.NewCommand())
return cmd
}

var vaultConfig vault.Config

func buildLauncherCommand(l *Launcher, cmd *cobra.Command) {
func launcherOpts(l *Launcher) []cli.Opt {
dir, err := fs.InfluxDir()
if err != nil {
panic(fmt.Errorf("failed to determine influx directory: %v", err))
}

opts := []cli.Opt{
return []cli.Opt{
{
DestP: &l.logLevel,
Flag: "log-level",
Expand Down Expand Up @@ -312,7 +326,10 @@ func buildLauncherCommand(l *Launcher, cmd *cobra.Command) {
Desc: "feature flag overrides",
},
}
cli.BindOptions(cmd, opts)
}

func buildLauncherCommand(l *Launcher, cmd *cobra.Command) {
cli.BindOptions(cmd, launcherOpts(l))
cmd.AddCommand(inspect.NewCommand())
}

Expand Down

0 comments on commit 4e4c509

Please sign in to comment.