Remove pidfile when program exits (closes #495)

This commit is contained in:
Matthew Holt 2016-01-09 21:48:07 -07:00
parent dab679df86
commit 0830c728fe
2 changed files with 14 additions and 0 deletions

View file

@ -32,10 +32,18 @@ func trapSignalsCrossPlatform() {
if i > 0 {
log.Println("[INFO] SIGINT: Force quit")
if PidFile != "" {
os.Remove(PidFile)
}
os.Exit(1)
}
log.Println("[INFO] SIGINT: Shutting down")
if PidFile != "" {
os.Remove(PidFile)
}
go os.Exit(executeShutdownCallbacks("SIGINT"))
}
}()

View file

@ -20,6 +20,9 @@ func trapSignalsPosix() {
switch sig {
case syscall.SIGTERM:
log.Println("[INFO] SIGTERM: Terminating process")
if PidFile != "" {
os.Remove(PidFile)
}
os.Exit(0)
case syscall.SIGQUIT:
@ -30,6 +33,9 @@ func trapSignalsPosix() {
log.Printf("[ERROR] SIGQUIT stop: %v", err)
exitCode = 1
}
if PidFile != "" {
os.Remove(PidFile)
}
os.Exit(exitCode)
case syscall.SIGHUP: