diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index a3fae740c..5dd29cef7 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -342,7 +342,7 @@ func main() { log.Println("Telegraf version already configured to: " + internal.Version()) } - if runtime.GOOS == "windows" && !(*fRunAsConsole) { + if runtime.GOOS == "windows" && windowsRunAsService() { svcConfig := &service.Config{ Name: *fServiceName, DisplayName: "Telegraf Data Collector Service", @@ -392,3 +392,16 @@ func main() { ) } } + +// Return true if Telegraf should create a Windows service. +func windowsRunAsService() bool { + if *fService != "" { + return true + } + + if *fRunAsConsole { + return false + } + + return !service.Interactive() +}