Browse Source

Return correct exit code upon signal + SIGQUIT now quits without cleanup

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
Guillaume J. Charmes 11 years ago
parent
commit
3b3f4bf052
1 changed files with 10 additions and 5 deletions
  1. 10 5
      server/server.go

+ 10 - 5
server/server.go

@@ -54,11 +54,16 @@ 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
-		log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
-		utils.RemovePidFile(srv.runtime.Config().Pidfile)
-		srv.Close()
-		os.Exit(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)))
+		}
 	}()
 	}()
 	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)