Browse code

Merge pull request #12400 from coolljt0725/kill_all_containers_on_daemon_shutdown

Ensure all the running containers are killed on daemon shutdown

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