Use environment variables to locate Program Files on Windows (#6317)
This commit is contained in:
parent
9f612fd52d
commit
08b903a646
|
@ -403,12 +403,16 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" && windowsRunAsService() {
|
if runtime.GOOS == "windows" && windowsRunAsService() {
|
||||||
|
programFiles := os.Getenv("ProgramFiles")
|
||||||
|
if programFiles == "" { // Should never happen
|
||||||
|
programFiles = "C:\\Program Files"
|
||||||
|
}
|
||||||
svcConfig := &service.Config{
|
svcConfig := &service.Config{
|
||||||
Name: *fServiceName,
|
Name: *fServiceName,
|
||||||
DisplayName: *fServiceDisplayName,
|
DisplayName: *fServiceDisplayName,
|
||||||
Description: "Collects data using a series of plugins and publishes it to" +
|
Description: "Collects data using a series of plugins and publishes it to" +
|
||||||
"another series of plugins.",
|
"another series of plugins.",
|
||||||
Arguments: []string{"--config", "C:\\Program Files\\Telegraf\\telegraf.conf"},
|
Arguments: []string{"--config", programFiles + "\\Telegraf\\telegraf.conf"},
|
||||||
}
|
}
|
||||||
|
|
||||||
prg := &program{
|
prg := &program{
|
||||||
|
|
|
@ -641,7 +641,11 @@ func getDefaultConfigPath() (string, error) {
|
||||||
homefile := os.ExpandEnv("${HOME}/.telegraf/telegraf.conf")
|
homefile := os.ExpandEnv("${HOME}/.telegraf/telegraf.conf")
|
||||||
etcfile := "/etc/telegraf/telegraf.conf"
|
etcfile := "/etc/telegraf/telegraf.conf"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
etcfile = `C:\Program Files\Telegraf\telegraf.conf`
|
programFiles := os.Getenv("ProgramFiles")
|
||||||
|
if programFiles == "" { // Should never happen
|
||||||
|
programFiles = `C:\Program Files`
|
||||||
|
}
|
||||||
|
etcfile = programFiles + `\Telegraf\telegraf.conf`
|
||||||
}
|
}
|
||||||
for _, path := range []string{envfile, homefile, etcfile} {
|
for _, path := range []string{envfile, homefile, etcfile} {
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
|
Loading…
Reference in New Issue