Allow force sigint and allow sigquit after sigint

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
This commit is contained in:
Guillaume J. Charmes 2014-04-02 18:00:13 -07:00
parent 3b3f4bf052
commit cd910cb685
No known key found for this signature in database
GPG Key ID: B33E4642CB6E3FF3
1 changed files with 22 additions and 8 deletions

View File

@ -54,15 +54,29 @@ func InitServer(job *engine.Job) engine.Status {
c := make(chan os.Signal, 1)
gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
interruptCount := 0
for sig := range c {
log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
switch sig {
case os.Interrupt, syscall.SIGTERM:
utils.RemovePidFile(srv.runtime.Config().Pidfile)
srv.Close()
case syscall.SIGQUIT:
}
os.Exit(128 + int(sig.(syscall.Signal)))
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)