Browse code

Fix api servers creation and daemon start order

* daemon creation wasn't parallel to request buffering
* it was possible that empty volume will be created in
/var/run/docker.sock by some container

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2015/05/08 07:35:12
Showing 2 changed files
... ...
@@ -98,31 +98,6 @@ func mainDaemon() {
98 98
 		}()
99 99
 	}
100 100
 
101
-	if err := migrateKey(); err != nil {
102
-		logrus.Fatal(err)
103
-	}
104
-	daemonCfg.TrustKeyPath = *flTrustKey
105
-
106
-	registryService := registry.NewService(registryCfg)
107
-	d, err := daemon.NewDaemon(daemonCfg, registryService)
108
-	if err != nil {
109
-		if pfile != nil {
110
-			if err := pfile.Remove(); err != nil {
111
-				logrus.Error(err)
112
-			}
113
-		}
114
-		logrus.Fatalf("Error starting daemon: %v", err)
115
-	}
116
-
117
-	logrus.Info("Daemon has completed initialization")
118
-
119
-	logrus.WithFields(logrus.Fields{
120
-		"version":     dockerversion.VERSION,
121
-		"commit":      dockerversion.GITCOMMIT,
122
-		"execdriver":  d.ExecutionDriver().Name(),
123
-		"graphdriver": d.GraphDriver().String(),
124
-	}).Info("Docker daemon")
125
-
126 101
 	serverConfig := &apiserver.ServerConfig{
127 102
 		Logging:     true,
128 103
 		EnableCors:  daemonCfg.EnableCors,
... ...
@@ -151,6 +126,31 @@ func mainDaemon() {
151 151
 		serveAPIWait <- nil
152 152
 	}()
153 153
 
154
+	if err := migrateKey(); err != nil {
155
+		logrus.Fatal(err)
156
+	}
157
+	daemonCfg.TrustKeyPath = *flTrustKey
158
+
159
+	registryService := registry.NewService(registryCfg)
160
+	d, err := daemon.NewDaemon(daemonCfg, registryService)
161
+	if err != nil {
162
+		if pfile != nil {
163
+			if err := pfile.Remove(); err != nil {
164
+				logrus.Error(err)
165
+			}
166
+		}
167
+		logrus.Fatalf("Error starting daemon: %v", err)
168
+	}
169
+
170
+	logrus.Info("Daemon has completed initialization")
171
+
172
+	logrus.WithFields(logrus.Fields{
173
+		"version":     dockerversion.VERSION,
174
+		"commit":      dockerversion.GITCOMMIT,
175
+		"execdriver":  d.ExecutionDriver().Name(),
176
+		"graphdriver": d.GraphDriver().String(),
177
+	}).Info("Docker daemon")
178
+
154 179
 	signal.Trap(func() {
155 180
 		api.Close()
156 181
 		<-serveAPIWait
... ...
@@ -1160,3 +1160,13 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) {
1160 1160
 	args = append(dargs, "rm", "-f", "container1")
1161 1161
 	runCommand(exec.Command(dockerBinary, args...))
1162 1162
 }
1163
+
1164
+func (s *DockerDaemonSuite) TestDaemonRestartWithSockerAsVolume(c *check.C) {
1165
+	c.Assert(s.d.StartWithBusybox(), check.IsNil)
1166
+
1167
+	socket := filepath.Join(s.d.folder, "docker.sock")
1168
+
1169
+	out, err := s.d.Cmd("run", "-d", "-v", socket+":/sock", "busybox")
1170
+	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
1171
+	c.Assert(s.d.Restart(), check.IsNil)
1172
+}