Add missing "start" event back for auto-restart container
| ... | ... |
@@ -131,7 +131,6 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error) |
| 131 | 131 |
return err |
| 132 | 132 |
} |
| 133 | 133 |
|
| 134 |
- defer daemon.LogContainerEvent(container, "start") // this is logged even on error |
|
| 135 | 134 |
if err := daemon.containerd.Create(container.ID, *spec, libcontainerd.WithRestartManager(container.RestartManager(true))); err != nil {
|
| 136 | 135 |
// if we receive an internal error from the initial start of a container then lets |
| 137 | 136 |
// return it instead of entering the restart loop |
| ... | ... |
@@ -149,6 +148,9 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error) |
| 149 | 149 |
} |
| 150 | 150 |
|
| 151 | 151 |
container.Reset(false) |
| 152 |
+ |
|
| 153 |
+ // start event is logged even on error |
|
| 154 |
+ daemon.LogContainerEvent(container, "start") |
|
| 152 | 155 |
return err |
| 153 | 156 |
} |
| 154 | 157 |
|
| ... | ... |
@@ -617,3 +617,44 @@ func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *check.C) {
|
| 617 | 617 |
events := strings.Split(strings.TrimSpace(out), "\n") |
| 618 | 618 |
c.Assert(len(events), checker.GreaterThan, 1, check.Commentf(out)) |
| 619 | 619 |
} |
| 620 |
+ |
|
| 621 |
+func (s *DockerSuite) TestEventsContainerRestart(c *check.C) {
|
|
| 622 |
+ dockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false") |
|
| 623 |
+ |
|
| 624 |
+ // wait until test2 is auto removed. |
|
| 625 |
+ waitTime := 10 * time.Second |
|
| 626 |
+ if daemonPlatform == "windows" {
|
|
| 627 |
+ // nslookup isn't present in Windows busybox. Is built-in. |
|
| 628 |
+ waitTime = 90 * time.Second |
|
| 629 |
+ } |
|
| 630 |
+ |
|
| 631 |
+ err := waitInspect("testEvent", "{{ .State.Restarting }} {{ .State.Running }}", "false false", waitTime)
|
|
| 632 |
+ c.Assert(err, checker.IsNil) |
|
| 633 |
+ |
|
| 634 |
+ var ( |
|
| 635 |
+ createCount int |
|
| 636 |
+ startCount int |
|
| 637 |
+ dieCount int |
|
| 638 |
+ ) |
|
| 639 |
+ out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "-f", "container=testEvent")
|
|
| 640 |
+ events := strings.Split(strings.TrimSpace(out), "\n") |
|
| 641 |
+ |
|
| 642 |
+ nEvents := len(events) |
|
| 643 |
+ c.Assert(nEvents, checker.GreaterOrEqualThan, 1) //Missing expected event |
|
| 644 |
+ actions := eventActionsByIDAndType(c, events, "testEvent", "container") |
|
| 645 |
+ |
|
| 646 |
+ for _, a := range actions {
|
|
| 647 |
+ switch a {
|
|
| 648 |
+ case "create": |
|
| 649 |
+ createCount++ |
|
| 650 |
+ case "start": |
|
| 651 |
+ startCount++ |
|
| 652 |
+ case "die": |
|
| 653 |
+ dieCount++ |
|
| 654 |
+ } |
|
| 655 |
+ } |
|
| 656 |
+ c.Assert(createCount, checker.Equals, 1, check.Commentf("testEvent should be created 1 times: %v", actions))
|
|
| 657 |
+ c.Assert(startCount, checker.Equals, 4, check.Commentf("testEvent should start 4 times: %v", actions))
|
|
| 658 |
+ c.Assert(dieCount, checker.Equals, 4, check.Commentf("testEvent should die 4 times: %v", actions))
|
|
| 659 |
+ |
|
| 660 |
+} |