From c57ba6110d0f01b61f694a8046d5bfd63f92d72d Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Tue, 26 Mar 2019 18:17:27 -0700 Subject: [PATCH] Exit after running --test without requiring --console (#5631) --- cmd/telegraf/telegraf.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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() +}