diff options
-rw-r--r-- | libpod/container_api.go | 2 | ||||
-rw-r--r-- | libpod/container_internal.go | 5 | ||||
-rw-r--r-- | libpod/events.go | 13 | ||||
-rw-r--r-- | libpod/events/events.go | 2 | ||||
-rw-r--r-- | libpod/oci.go | 2 |
5 files changed, 21 insertions, 3 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go index 33ec938f7..96435c2ff 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -89,7 +89,6 @@ func (c *Container) Start(ctx context.Context, recursive bool) (err error) { } // Start the container - defer c.newContainerEvent(events.Start) return c.start() } @@ -127,7 +126,6 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams, } close(attachChan) }() - c.newContainerEvent(events.Start) c.newContainerEvent(events.Attach) return attachChan, nil } diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 330745314..bea7acd69 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -211,6 +211,9 @@ func (c *Container) handleExitFile(exitFile string, fi os.FileInfo) error { c.state.Exited = true + // Write an event for the container's death + c.newContainerExitedEvent(c.state.ExitCode) + return nil } @@ -948,6 +951,8 @@ func (c *Container) start() error { c.state.State = ContainerStateRunning + defer c.newContainerEvent(events.Start) + return c.save() } diff --git a/libpod/events.go b/libpod/events.go index 9806c117b..879aeb6c5 100644 --- a/libpod/events.go +++ b/libpod/events.go @@ -19,6 +19,19 @@ func (c *Container) newContainerEvent(status events.Status) { } } +// newContainerExitedEvent creates a new event for a container's death +func (c *Container) newContainerExitedEvent(exitCode int32) { + e := events.NewEvent(events.Exited) + e.ID = c.ID() + e.Name = c.Name() + e.Image = c.config.RootfsImageName + e.Type = events.Container + e.ContainerExitCode = int(exitCode) + if err := e.Write(c.runtime.config.EventsLogFilePath); err != nil { + logrus.Errorf("unable to write event to %s", c.runtime.config.EventsLogFilePath) + } +} + // newPodEvent creates a new event for a libpod pod func (p *Pod) newPodEvent(status events.Status) { e := events.NewEvent(status) diff --git a/libpod/events/events.go b/libpod/events/events.go index 186790500..48bbbb00e 100644 --- a/libpod/events/events.go +++ b/libpod/events/events.go @@ -60,6 +60,8 @@ const ( Create Status = "create" // Exec ... Exec Status = "exec" + // Exited indicates that a container's process died + Exited Status = "died" // Export ... Export Status = "export" // History ... diff --git a/libpod/oci.go b/libpod/oci.go index c3b5f9af2..30360d289 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -477,7 +477,7 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container, useRunc bool) error { // If not using runc, we don't need to do most of this. if !useRunc { // If the container's not running, nothing to do. - if ctr.state.State != ContainerStateRunning { + if ctr.state.State != ContainerStateRunning && ctr.state.State != ContainerStatePaused { return nil } |