瀏覽代碼

Merge pull request #35355 from x1022as/unless-stop

fix unless-stopped unexpected behavior
Vincent Demeester 6 年之前
父節點
當前提交
e7a9a7cdbc
共有 3 個文件被更改,包括 15 次插入5 次删除
  1. 1 0
      daemon/kill.go
  2. 1 1
      daemon/start.go
  3. 13 4
      integration-cli/docker_cli_daemon_test.go

+ 1 - 0
daemon/kill.go

@@ -87,6 +87,7 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
 
 
 	if !daemon.IsShuttingDown() {
 	if !daemon.IsShuttingDown() {
 		container.HasBeenManuallyStopped = true
 		container.HasBeenManuallyStopped = true
+		container.CheckpointTo(daemon.containersReplica)
 	}
 	}
 
 
 	// if the container is currently restarting we do not need to send the signal
 	// if the container is currently restarting we do not need to send the signal

+ 1 - 1
daemon/start.go

@@ -158,6 +158,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
 
 
 	if resetRestartManager {
 	if resetRestartManager {
 		container.ResetRestartManager(true)
 		container.ResetRestartManager(true)
+		container.HasBeenManuallyStopped = false
 	}
 	}
 
 
 	if daemon.saveApparmorConfig(container); err != nil {
 	if daemon.saveApparmorConfig(container); err != nil {
@@ -194,7 +195,6 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
 	}
 	}
 
 
 	container.SetRunning(pid, true)
 	container.SetRunning(pid, true)
-	container.HasBeenManuallyStopped = false
 	container.HasBeenStartedBefore = true
 	container.HasBeenStartedBefore = true
 	daemon.setStateCounter(container)
 	daemon.setStateCounter(container)
 
 

+ 13 - 4
integration-cli/docker_cli_daemon_test.go

@@ -124,6 +124,9 @@ func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) {
 	out, err = s.d.Cmd("run", "-d", "--name", "top2", "--restart", "unless-stopped", "busybox:latest", "top")
 	out, err = s.d.Cmd("run", "-d", "--name", "top2", "--restart", "unless-stopped", "busybox:latest", "top")
 	c.Assert(err, check.IsNil, check.Commentf("run top2: %v", out))
 	c.Assert(err, check.IsNil, check.Commentf("run top2: %v", out))
 
 
+	out, err = s.d.Cmd("run", "-d", "--name", "exit", "--restart", "unless-stopped", "busybox:latest", "false")
+	c.Assert(err, check.IsNil, check.Commentf("run exit: %v", out))
+
 	testRun := func(m map[string]bool, prefix string) {
 	testRun := func(m map[string]bool, prefix string) {
 		var format string
 		var format string
 		for name, shouldRun := range m {
 		for name, shouldRun := range m {
@@ -139,7 +142,10 @@ func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) {
 	}
 	}
 
 
 	// both running
 	// both running
-	testRun(map[string]bool{"top1": true, "top2": true}, "")
+	testRun(map[string]bool{"top1": true, "top2": true, "exit": true}, "")
+
+	out, err = s.d.Cmd("stop", "exit")
+	c.Assert(err, check.IsNil, check.Commentf(out))
 
 
 	out, err = s.d.Cmd("stop", "top1")
 	out, err = s.d.Cmd("stop", "top1")
 	c.Assert(err, check.IsNil, check.Commentf("%s", out))
 	c.Assert(err, check.IsNil, check.Commentf("%s", out))
@@ -148,20 +154,23 @@ func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) {
 	c.Assert(err, check.IsNil, check.Commentf("%s", out))
 	c.Assert(err, check.IsNil, check.Commentf("%s", out))
 
 
 	// both stopped
 	// both stopped
-	testRun(map[string]bool{"top1": false, "top2": false}, "")
+	testRun(map[string]bool{"top1": false, "top2": false, "exit": false}, "")
 
 
 	s.d.Restart(c)
 	s.d.Restart(c)
 
 
 	// restart=always running
 	// restart=always running
-	testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ")
+	testRun(map[string]bool{"top1": true, "top2": false, "exit": false}, "After daemon restart: ")
 
 
 	out, err = s.d.Cmd("start", "top2")
 	out, err = s.d.Cmd("start", "top2")
 	c.Assert(err, check.IsNil, check.Commentf("start top2: %v", out))
 	c.Assert(err, check.IsNil, check.Commentf("start top2: %v", out))
 
 
+	out, err = s.d.Cmd("start", "exit")
+	c.Assert(err, check.IsNil, check.Commentf("start exit: %v", out))
+
 	s.d.Restart(c)
 	s.d.Restart(c)
 
 
 	// both running
 	// both running
-	testRun(map[string]bool{"top1": true, "top2": true}, "After second daemon restart: ")
+	testRun(map[string]bool{"top1": true, "top2": true, "exit": true}, "After second daemon restart: ")
 
 
 }
 }