Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for the config files relative to the path.config flag #2245

Merged
merged 1 commit into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha5...master[Check the HEAD d
*Affecting all Beats*
- Change Elasticsearch output index configuration to be based on format strings. If index has been configured, no date will be appended anymore to the index name. {pull}2119[2119]
- Replace `output.kafka.use_type` by `output.kafka.topic` accepting a format string. {pull}2188[2188]
- If the path specified by the `-c` flag is not absolute and `-path.config` is not specified, it
is considered relative to the current working directory. {pull}2245[2245]

*Metricbeat*
- Change field type system.process.cpu.start_time from keyword to date. {issue}1565[1565]
Expand All @@ -36,6 +38,8 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha5...master[Check the HEAD d
*Affecting all Beats*
- Fix Elasticsearch structured error response parsing error. {issue}2229[2229]

- Fixed the run script to allow the overriding of the configuration file. {issue}2171[2171]

*Metricbeat*

*Packetbeat*
Expand All @@ -51,6 +55,7 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha5...master[Check the HEAD d
==== Added

*Affecting all Beats*

- Add script to generate the Kibana index-pattern from fields.yml. {pull}2122[2122]
- Enhance redis output key selection based on format string. {pull}2169[2169]
- Configurable redis `keys` using filters and format strings. {pull}2169[2169]
Expand All @@ -63,6 +68,7 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha5...master[Check the HEAD d
- Add kafka version setting (optional) enabling kafka broker version support. {pull}2190[2190]
- Add kafka message timestamp if at least version 0.10 is configured. {pull}2190[2190]
- Enhance contains condition to work on fields that are arrays of strings. {issue}2237[2237]
- Lookup the configuration file relative to the `-path.config` CLI flag. {pull}2245[2245]

*Metricbeat*

Expand Down
3 changes: 1 addition & 2 deletions dev-tools/packer/platforms/debian/beatname.sh.j2
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash

# Script to run {.beat_name} in foreground with the same path settings that
# Script to run {{.beat_name}} in foreground with the same path settings that
# the init script / systemd unit file would do.

/usr/share/{{.beat_name}}/bin/{{.beat_name}} -e \
-c /etc/{{.beat_name}}/{{.beat_name}}.yml \
-path.home /usr/share/{{.beat_name}} \
-path.config /etc/{{.beat_name}} \
-path.data /var/lib/{{.beat_name}} \
Expand Down
37 changes: 24 additions & 13 deletions libbeat/cfgfile/cfgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
// The default config cannot include the beat name as it is not initialized
// when this variable is created. See ChangeDefaultCfgfileFlag which should
// be called prior to flags.Parse().
configfiles = flagArgList("c", "beat.yml", "Configuration file `path`")
configfiles = flagArgList("c", "beat.yml", "Configuration file, relative to path.config")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An absolute path also works, correct?

overwrites = common.NewFlagConfig(nil, nil, "E", "Configuration overwrite")
testConfig = flag.Bool("configtest", false, "Test configuration and exit.")

Expand All @@ -29,7 +29,8 @@ var (
})

// home-path CLI flag (initialized in init)
homePath *string
homePath *string
configPath *string
)

func init() {
Expand All @@ -39,7 +40,7 @@ func init() {
}

homePath = makePathFlag("path.home", "Home path")
makePathFlag("path.config", "Configuration path")
configPath = makePathFlag("path.config", "Configuration path")
makePathFlag("path.data", "Data path")
makePathFlag("path.logs", "Logs path")
}
Expand All @@ -55,15 +56,7 @@ func mustNewConfigFrom(from interface{}) *common.Config {
// ChangeDefaultCfgfileFlag replaces the value and default value for the `-c`
// flag so that it reflects the beat name.
func ChangeDefaultCfgfileFlag(beatName string) error {
path, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return fmt.Errorf("Failed to set default config file location because "+
"the absolute path to %s could not be obtained. %v",
os.Args[0], err)
}

path = filepath.Join(path, beatName+".yml")
configfiles.SetDefault(path)
configfiles.SetDefault(beatName + ".yml")
return nil
}

Expand Down Expand Up @@ -105,9 +98,27 @@ func Load(path string) (*common.Config, error) {
var config *common.Config
var err error

cfgpath := ""
if *configPath != "" {
cfgpath = *configPath
} else if *homePath != "" {
cfgpath = *homePath
}

if path == "" {
config, err = common.LoadFiles(configfiles.list...)
list := []string{}
for _, cfg := range configfiles.list {
if !filepath.IsAbs(cfg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, still works :-)

list = append(list, filepath.Join(cfgpath, cfg))
} else {
list = append(list, cfg)
}
}
config, err = common.LoadFiles(list...)
} else {
if !filepath.IsAbs(path) {
path = filepath.Join(cfgpath, path)
}
config, err = common.LoadFile(path)
}
if err != nil {
Expand Down