1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #21839 from WeiZhang555/add-start-event

Add missing "start" event back for auto-restart container
This commit is contained in:
Sebastiaan van Stijn 2016-04-08 17:52:22 -07:00
commit eaa1e8a8c4
3 changed files with 45 additions and 1 deletions

View file

@ -83,6 +83,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
c.Reset(false)
return err
}
daemon.LogContainerEvent(c, "start")
case libcontainerd.StatePause:
c.Paused = true
daemon.LogContainerEvent(c, "pause")

View file

@ -131,7 +131,6 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error)
return err
}
defer daemon.LogContainerEvent(container, "start") // this is logged even on error
if err := daemon.containerd.Create(container.ID, *spec, libcontainerd.WithRestartManager(container.RestartManager(true))); err != nil {
// if we receive an internal error from the initial start of a container then lets
// return it instead of entering the restart loop
@ -149,6 +148,9 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error)
}
container.Reset(false)
// start event is logged even on error
daemon.LogContainerEvent(container, "start")
return err
}

View file

@ -617,3 +617,44 @@ func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *check.C) {
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(events), checker.GreaterThan, 1, check.Commentf(out))
}
func (s *DockerSuite) TestEventsContainerRestart(c *check.C) {
dockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false")
// wait until test2 is auto removed.
waitTime := 10 * time.Second
if daemonPlatform == "windows" {
// nslookup isn't present in Windows busybox. Is built-in.
waitTime = 90 * time.Second
}
err := waitInspect("testEvent", "{{ .State.Restarting }} {{ .State.Running }}", "false false", waitTime)
c.Assert(err, checker.IsNil)
var (
createCount int
startCount int
dieCount int
)
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "-f", "container=testEvent")
events := strings.Split(strings.TrimSpace(out), "\n")
nEvents := len(events)
c.Assert(nEvents, checker.GreaterOrEqualThan, 1) //Missing expected event
actions := eventActionsByIDAndType(c, events, "testEvent", "container")
for _, a := range actions {
switch a {
case "create":
createCount++
case "start":
startCount++
case "die":
dieCount++
}
}
c.Assert(createCount, checker.Equals, 1, check.Commentf("testEvent should be created 1 times: %v", actions))
c.Assert(startCount, checker.Equals, 4, check.Commentf("testEvent should start 4 times: %v", actions))
c.Assert(dieCount, checker.Equals, 4, check.Commentf("testEvent should die 4 times: %v", actions))
}