Jelajahi Sumber

Clean up the docker socket on termination of the daemon.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
Erik Hollensbe 11 tahun lalu
induk
melakukan
96f1a99034
1 mengubah file dengan 14 tambahan dan 0 penghapusan
  1. 14 0
      server/server.go

+ 14 - 0
server/server.go

@@ -83,6 +83,18 @@ func InitPidfile(job *engine.Job) engine.Status {
 	return engine.StatusOK
 	return engine.StatusOK
 }
 }
 
 
+func (srv *Server) removeUnixSockets() {
+	for _, sock := range srv.daemon.Config().Sockets {
+		parts := strings.SplitN(sock, "://", 2)
+		if parts[0] == "unix" {
+			err := os.Remove(parts[1])
+			if err != nil {
+				utils.Debugf("Got error removing unix socket: %s", err.Error())
+			}
+		}
+	}
+}
+
 // jobInitApi runs the remote api server `srv` as a daemon,
 // jobInitApi runs the remote api server `srv` as a daemon,
 // Only one api server can run at the same time - this is enforced by a pidfile.
 // Only one api server can run at the same time - this is enforced by a pidfile.
 // The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
 // The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
@@ -121,6 +133,8 @@ func InitServer(job *engine.Job) engine.Status {
 					}
 					}
 				case syscall.SIGQUIT:
 				case syscall.SIGQUIT:
 				}
 				}
+
+				srv.removeUnixSockets()
 				os.Exit(128 + int(sig.(syscall.Signal)))
 				os.Exit(128 + int(sig.(syscall.Signal)))
 			}(sig)
 			}(sig)
 		}
 		}