Skip to content

Commit

Permalink
Remove pidfile if pidfile was created (influxdata#2358)
Browse files Browse the repository at this point in the history
Also, ensure pidfile perms are 644
  • Loading branch information
nfirvine authored and sparrc committed Feb 3, 2017
1 parent b3537ef commit dfb4038
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 @@ -194,14 +194,21 @@ func reloadLoop(
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 dfb4038

Please sign in to comment.