Skip to content

Commit

Permalink
Allow force sigint and allow sigquit after sigint
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <[email protected]> (github: creack)
  • Loading branch information
creack committed Apr 3, 2014
1 parent 3b3f4bf commit cd910cb
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cd910cb

Please sign in to comment.