mirror of
https://github.com/containers/podman.git
synced 2025-10-18 19:53:58 +08:00
Merge pull request #2621 from mheon/event_on_death
Add event on container death
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 ...
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user