From d64d55eca85232af721859a8cc6f20ff473ce94c Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Fri, 19 Sep 2014 13:54:32 -0700 Subject: [PATCH] After container fails to start, log the event die. Fixes #8135. Docker-DCO-1.1-Signed-off-by: Jessica Frazelle (github: jfrazelle) --- daemon/start.go | 1 + integration-cli/docker_cli_events_test.go | 29 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/daemon/start.go b/daemon/start.go index 0540bda03f..207dff85aa 100644 --- a/daemon/start.go +++ b/daemon/start.go @@ -34,6 +34,7 @@ func (daemon *Daemon) ContainerStart(job *engine.Job) engine.Status { } } if err := container.Start(); err != nil { + container.LogEvent("die") return job.Errorf("Cannot start container %s: %s", name, err) } diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index 4370a17905..98e50d97a2 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -57,6 +57,35 @@ func TestEventsPause(t *testing.T) { logDone("events - pause/unpause is logged") } +func TestEventsContainerFailStartDie(t *testing.T) { + out, _, _ := cmd(t, "images", "-q") + image := strings.Split(out, "\n")[0] + eventsCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testeventdie", image, "blerg") + _, _, err := runCommandWithOutput(eventsCmd) + if err == nil { + t.Fatalf("Container run with command blerg should have failed, but it did not") + } + + eventsCmd = exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", time.Now().Unix())) + out, _, _ = runCommandWithOutput(eventsCmd) + events := strings.Split(out, "\n") + if len(events) <= 1 { + t.Fatalf("Missing expected event") + } + + startEvent := strings.Fields(events[len(events)-3]) + dieEvent := strings.Fields(events[len(events)-2]) + + if startEvent[len(startEvent)-1] != "start" { + t.Fatalf("event should be start, not %#v", startEvent) + } + if dieEvent[len(dieEvent)-1] != "die" { + t.Fatalf("event should be die, not %#v", dieEvent) + } + + logDone("events - container failed to start logs die") +} + func TestEventsLimit(t *testing.T) { for i := 0; i < 30; i++ { cmd(t, "run", "busybox", "echo", strconv.Itoa(i))