瀏覽代碼

Fix update clear the restart policy of monitor

Signed-off-by: Lei Jitang <leijitang@huawei.com>
Lei Jitang 8 年之前
父節點
當前提交
737b5b1781
共有 2 個文件被更改,包括 34 次插入1 次删除
  1. 3 1
      daemon/update.go
  2. 31 0
      integration-cli/docker_cli_update_unix_test.go

+ 3 - 1
daemon/update.go

@@ -67,7 +67,9 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
 	}
 	}
 
 
 	// if Restart Policy changed, we need to update container monitor
 	// if Restart Policy changed, we need to update container monitor
-	container.UpdateMonitor(hostConfig.RestartPolicy)
+	if hostConfig.RestartPolicy.Name != "" {
+		container.UpdateMonitor(hostConfig.RestartPolicy)
+	}
 
 
 	// If container is not running, update hostConfig struct is enough,
 	// If container is not running, update hostConfig struct is enough,
 	// resources will be updated when the container is started again.
 	// resources will be updated when the container is started again.

+ 31 - 0
integration-cli/docker_cli_update_unix_test.go

@@ -5,7 +5,10 @@ package main
 import (
 import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	"github.com/kr/pty"
+	"os/exec"
 	"strings"
 	"strings"
+	"time"
 
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/docker/docker/pkg/integration/checker"
@@ -250,3 +253,31 @@ func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) {
 
 
 	dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
 	dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
 }
 }
+
+func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *check.C) {
+	testRequires(c, DaemonIsLinux, cpuShare)
+
+	out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh")
+	id := strings.TrimSpace(string(out))
+	dockerCmd(c, "update", "--cpu-shares", "512", id)
+
+	cpty, tty, err := pty.Open()
+	c.Assert(err, checker.IsNil)
+	defer cpty.Close()
+
+	cmd := exec.Command(dockerBinary, "attach", id)
+	cmd.Stdin = tty
+
+	c.Assert(cmd.Start(), checker.IsNil)
+	defer cmd.Process.Kill()
+
+	_, err = cpty.Write([]byte("exit\n"))
+	c.Assert(err, checker.IsNil)
+
+	c.Assert(cmd.Wait(), checker.IsNil)
+
+	// container should restart again and keep running
+	err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second)
+	c.Assert(err, checker.IsNil)
+	c.Assert(waitRun(id), checker.IsNil)
+}