Skip to content

Commit

Permalink
Merge pull request #6444 from influxdata/js-config-from-env-var
Browse files Browse the repository at this point in the history
Allow setting the config path through an environment variable
  • Loading branch information
jsternberg committed Apr 22, 2016
2 parents d22af70 + 9c09023 commit 5070f69
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [#3166](https://github.com/influxdata/influxdb/issues/3166): Sort the series keys inside of a tag set so output is deterministic.
- [#1856](https://github.com/influxdata/influxdb/issues/1856): Add `elapsed` function that returns the time delta between subsequent points.
- [#5502](https://github.com/influxdata/influxdb/issues/5502): Add checksum verification to TSM inspect tool
- [#6444](https://github.com/influxdata/influxdb/pull/6444): Allow setting the config path through an environment variable and default config path.

### Bugfixes

Expand Down
27 changes: 26 additions & 1 deletion cmd/influxd/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (cmd *Command) Run(args ...string) error {
runtime.SetBlockProfileRate(int(1 * time.Second))

// Parse config
config, err := cmd.ParseConfig(options.ConfigPath)
config, err := cmd.ParseConfig(options.GetConfigPath())
if err != nil {
return fmt.Errorf("parse config: %s", err)
}
Expand Down Expand Up @@ -239,3 +239,28 @@ type Options struct {
CPUProfile string
MemProfile string
}

// GetConfigPath returns the config path from the options.
// It will return a path by searching in this order:
// 1. The CLI option in ConfigPath
// 2. The environment variable INFLUXDB_CONFIG_PATH
// 3. The first influxdb.conf file on the path:
// - ~/.influxdb
// - /etc/influxdb
func (opt *Options) GetConfigPath() string {
if opt.ConfigPath != "" {
return opt.ConfigPath
} else if envVar := os.Getenv("INFLUXDB_CONFIG_PATH"); envVar != "" {
return envVar
}

for _, path := range []string{
os.ExpandEnv("${HOME}/.influxdb/influxdb.conf"),
"/etc/influxdb/influxdb.conf",
} {
if _, err := os.Stat(path); err == nil {
return path
}
}
return ""
}
3 changes: 2 additions & 1 deletion cmd/influxd/run/config_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func (cmd *PrintConfigCommand) Run(args ...string) error {
}

// Parse config from path.
config, err := cmd.parseConfig(*configPath)
opt := Options{ConfigPath: *configPath}
config, err := cmd.parseConfig(opt.GetConfigPath())
if err != nil {
return fmt.Errorf("parse config: %s", err)
}
Expand Down

0 comments on commit 5070f69

Please sign in to comment.