Merge pull request #4980 from creack/update_signal_management

Return correct exit code upon signal + SIGQUIT now quits without cleanup
This commit is contained in:
Michael Crosby 2014-04-03 11:58:19 -07:00
commit 5864a3ff77
1 changed files with 24 additions and 5 deletions

View File

@ -54,11 +54,30 @@ func InitServer(job *engine.Job) engine.Status {
c := make(chan os.Signal, 1)
gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
sig := <-c
log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
utils.RemovePidFile(srv.runtime.Config().Pidfile)
srv.Close()
os.Exit(0)
interruptCount := 0
for sig := range c {
go func() {
log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
switch sig {
case os.Interrupt, syscall.SIGTERM:
// If the user really wants to interrupt, let him do so.
if interruptCount < 3 {
interruptCount++
// Initiate the cleanup only once
if interruptCount == 1 {
utils.RemovePidFile(srv.runtime.Config().Pidfile)
srv.Close()
} else {
return
}
} else {
log.Printf("Force shutdown of docker, interrupting cleanup\n")
}
case syscall.SIGQUIT:
}
os.Exit(128 + int(sig.(syscall.Signal)))
}()
}
}()
job.Eng.Hack_SetGlobalVar("httpapi.server", srv)
job.Eng.Hack_SetGlobalVar("httpapi.runtime", srv.runtime)