Remove pidfile if pidfile was created (#2358)

Also, ensure pidfile perms are 644
This commit is contained in:
Nick Irvine 2017-02-03 02:02:19 -08:00 committed by Cameron Sparr
parent 510b750da4
commit 4816615deb
1 changed files with 13 additions and 6 deletions

View File

@ -194,14 +194,21 @@ func reloadLoop(
log.Printf("I! Tags enabled: %s", c.ListTags()) log.Printf("I! Tags enabled: %s", c.ListTags())
if *fPidfile != "" { if *fPidfile != "" {
f, err := os.Create(*fPidfile) f, err := os.OpenFile(*fPidfile, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil { 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()) fmt.Fprintf(f, "%d\n", os.Getpid())
f.Close() f.Close()
defer func() {
err := os.Remove(*fPidfile)
if err != nil {
log.Printf("E! Unable to remove pidfile: %s", err)
}
}()
}
} }
ag.Run(shutdown) ag.Run(shutdown)