Skip to content

Commit

Permalink
Fix update clear the restart policy of monitor
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Jitang <leijitang@huawei.com>
  • Loading branch information
coolljt0725 committed Dec 17, 2016
1 parent a59625d commit 737b5b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion daemon/update.go
Expand Up @@ -67,7 +67,9 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
}

// 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,
// resources will be updated when the container is started again.
Expand Down
31 changes: 31 additions & 0 deletions integration-cli/docker_cli_update_unix_test.go
Expand Up @@ -5,7 +5,10 @@ package main
import (
"encoding/json"
"fmt"
"github.com/kr/pty"
"os/exec"
"strings"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/integration/checker"
Expand Down Expand Up @@ -250,3 +253,31 @@ func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) {

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)
}

0 comments on commit 737b5b1

Please sign in to comment.