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 58b7203
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 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
29 changes: 17 additions & 12 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("already running...")
}

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

return nil
},
}

buildLauncherCommand(l, cmd)

cmd := cli.NewCommand(&prog)
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 +314,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 58b7203

Please sign in to comment.