Skip to content

Commit

Permalink
Remove pidfile if pidfile was created
Browse files Browse the repository at this point in the history
Also, ensure pidfile perms are 644
  • Loading branch information
Nick Irvine committed Feb 2, 2017
1 parent f7d551a commit 1a79b61
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,21 @@ func reloadLoop(stop chan struct{}, s service.Service) {
log.Printf("I! Tags enabled: %s", c.ListTags())

if *fPidfile != "" {
f, err := os.Create(*fPidfile)
f, err := os.OpenFile(*fPidfile, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("E! Unable to create pidfile: %s", err)
log.Printf("E! Unable to create pidfile: %s", err)
} else {
fmt.Fprintf(f, "%d\n", os.Getpid())

f.Close()

defer func() {
err := os.Remove(*fPidfile)
if err != nil {
log.Printf("E! Unable to remove pidfile: %s", err)
}
}()
}

fmt.Fprintf(f, "%d\n", os.Getpid())

f.Close()
}

ag.Run(shutdown)
Expand Down

0 comments on commit 1a79b61

Please sign in to comment.