Browse code

Ensure all the running containers are killed on daemon shutdown

Signed-off-by: Lei Jitang <leijitang@huawei.com>

Lei Jitang authored on 2015/05/26 10:25:34
Showing 2 changed files
... ...
@@ -1003,8 +1003,9 @@ func (daemon *Daemon) Shutdown() error {
1003 1003
 
1004 1004
 				go func() {
1005 1005
 					defer group.Done()
1006
-					if err := c.KillSig(15); err != nil {
1007
-						logrus.Debugf("kill 15 error for %s - %s", c.ID, err)
1006
+					// If container failed to exit in 10 seconds of SIGTERM, then using the force
1007
+					if err := c.Stop(10); err != nil {
1008
+						logrus.Errorf("Stop container %s with error: %v", c.ID, err)
1008 1009
 					}
1009 1010
 					c.WaitStop(-1 * time.Second)
1010 1011
 					logrus.Debugf("container stopped %s", c.ID)
... ...
@@ -1165,3 +1165,19 @@ func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) {
1165 1165
 	c.Assert(strings.Contains(out, "eth0"), check.Equals, false,
1166 1166
 		check.Commentf("There shouldn't be eth0 in container when network is disabled: %s", out))
1167 1167
 }
1168
+
1169
+func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) {
1170
+	if err := s.d.StartWithBusybox(); err != nil {
1171
+		t.Fatal(err)
1172
+	}
1173
+	if out, err := s.d.Cmd("run", "-ti", "-d", "--name", "test", "busybox"); err != nil {
1174
+		t.Fatal(out, err)
1175
+	}
1176
+	if err := s.d.Restart(); err != nil {
1177
+		t.Fatal(err)
1178
+	}
1179
+	// Container 'test' should be removed without error
1180
+	if out, err := s.d.Cmd("rm", "test"); err != nil {
1181
+		t.Fatal(out, err)
1182
+	}
1183
+}