From e477620dc57d80ce07346abc01a8a8d429806145 Mon Sep 17 00:00:00 2001 From: Peter Murray Date: Thu, 15 Sep 2016 11:22:05 +0100 Subject: [PATCH] Making '-service' flags work from a non-interactive session, i.e. Ansible, related to #1760 --- cmd/telegraf/telegraf.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 022280d6b..38ae1b00a 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -182,15 +182,6 @@ func reloadLoop(stop chan struct{}, s service.Service) { } } return - case *fService != "" && runtime.GOOS == "windows": - if *fConfig != "" { - (*svcConfig).Arguments = []string{"-config", *fConfig} - } - err := service.Control(s, *fService) - if err != nil { - log.Fatal(err) - } - return } // If no other options are specified, load the config file and run. @@ -320,9 +311,22 @@ func main() { if err != nil { log.Fatal(err) } - err = s.Run() - if err != nil { - logger.Error(err) + // Handle the -service flag here to prevent any issues with tooling that may not have an interactive + // session, e.g. installing from Ansible + flag.Parse() + if *fService != "" { + if *fConfig != "" { + (*svcConfig).Arguments = []string{"-config", *fConfig} + } + err := service.Control(s, *fService) + if err != nil { + log.Fatal(err) + } + } else { + err = s.Run() + if err != nil { + logger.Error(err) + } } } else { stop = make(chan struct{})