Skip to content

Commit

Permalink
Making '-service' flags work from a non-interactive session, i.e. Ans…
Browse files Browse the repository at this point in the history
…ible, related to #1760
  • Loading branch information
peter-murray authored and sparrc committed Sep 28, 2016
1 parent 32268fb commit e477620
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{})
Expand Down

0 comments on commit e477620

Please sign in to comment.