mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
commit
5864a3ff77
1 changed files with 24 additions and 5 deletions
|
@ -54,11 +54,30 @@ func InitServer(job *engine.Job) engine.Status {
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
|
gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
|
||||||
go func() {
|
go func() {
|
||||||
sig := <-c
|
interruptCount := 0
|
||||||
|
for sig := range c {
|
||||||
|
go func() {
|
||||||
log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
|
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)
|
utils.RemovePidFile(srv.runtime.Config().Pidfile)
|
||||||
srv.Close()
|
srv.Close()
|
||||||
os.Exit(0)
|
} 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.server", srv)
|
||||||
job.Eng.Hack_SetGlobalVar("httpapi.runtime", srv.runtime)
|
job.Eng.Hack_SetGlobalVar("httpapi.runtime", srv.runtime)
|
||||||
|
|
Loading…
Add table
Reference in a new issue