Procházet zdrojové kódy

Allow force sigint and allow sigquit after sigint

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
Guillaume J. Charmes před 11 roky
rodič
revize
cd910cb685
1 změnil soubory, kde provedl 22 přidání a 8 odebrání
  1. 22 8
      server/server.go

+ 22 - 8
server/server.go

@@ -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)