Merge pull request #6444 from influxdata/js-config-from-env-var
Allow setting the config path through an environment variablepull/6411/head
commit
5070f69bb2
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
@ -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 ""
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue