Fix restart monitor stopping on manual restart

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 20390f65c4)
This commit is contained in:
Tonis Tiigi 2016-04-07 16:12:05 -07:00 committed by Tibor Vass
parent 52b8adea4d
commit 716b5b2547
2 changed files with 31 additions and 0 deletions

View file

@ -909,6 +909,7 @@ func (container *Container) FullHostname() string {
func (container *Container) RestartManager(reset bool) restartmanager.RestartManager {
if reset {
container.RestartCount = 0
container.restartManager = nil
}
if container.restartManager == nil {
container.restartManager = restartmanager.New(container.HostConfig.RestartPolicy)

View file

@ -188,3 +188,33 @@ func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *check.C) {
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo")
c.Assert(err, check.IsNil)
}
func (s *DockerSuite) TestRestartPolicyAfterRestart(c *check.C) {
testRequires(c, SameHostDaemon)
out, _ := runSleepingContainer(c, "-d", "--restart=always")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
dockerCmd(c, "restart", id)
c.Assert(waitRun(id), check.IsNil)
pidStr := inspectField(c, id, "State.Pid")
pid, err := strconv.Atoi(pidStr)
c.Assert(err, check.IsNil)
p, err := os.FindProcess(pid)
c.Assert(err, check.IsNil)
c.Assert(p, check.NotNil)
err = p.Kill()
c.Assert(err, check.IsNil)
err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second)
c.Assert(err, check.IsNil)
err = waitInspect(id, "{{.State.Status}}", "running", 30*time.Second)
c.Assert(err, check.IsNil)
}