mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
Add event on container death
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -89,7 +89,6 @@ func (c *Container) Start(ctx context.Context, recursive bool) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the container
|
// Start the container
|
||||||
defer c.newContainerEvent(events.Start)
|
|
||||||
return c.start()
|
return c.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +126,6 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *AttachStreams,
|
|||||||
}
|
}
|
||||||
close(attachChan)
|
close(attachChan)
|
||||||
}()
|
}()
|
||||||
c.newContainerEvent(events.Start)
|
|
||||||
c.newContainerEvent(events.Attach)
|
c.newContainerEvent(events.Attach)
|
||||||
return attachChan, nil
|
return attachChan, nil
|
||||||
}
|
}
|
||||||
|
@ -211,6 +211,9 @@ func (c *Container) handleExitFile(exitFile string, fi os.FileInfo) error {
|
|||||||
|
|
||||||
c.state.Exited = true
|
c.state.Exited = true
|
||||||
|
|
||||||
|
// Write an event for the container's death
|
||||||
|
c.newContainerExitedEvent(c.state.ExitCode)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -948,6 +951,8 @@ func (c *Container) start() error {
|
|||||||
|
|
||||||
c.state.State = ContainerStateRunning
|
c.state.State = ContainerStateRunning
|
||||||
|
|
||||||
|
defer c.newContainerEvent(events.Start)
|
||||||
|
|
||||||
return c.save()
|
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
|
// newPodEvent creates a new event for a libpod pod
|
||||||
func (p *Pod) newPodEvent(status events.Status) {
|
func (p *Pod) newPodEvent(status events.Status) {
|
||||||
e := events.NewEvent(status)
|
e := events.NewEvent(status)
|
||||||
|
@ -60,6 +60,8 @@ const (
|
|||||||
Create Status = "create"
|
Create Status = "create"
|
||||||
// Exec ...
|
// Exec ...
|
||||||
Exec Status = "exec"
|
Exec Status = "exec"
|
||||||
|
// Exited indicates that a container's process died
|
||||||
|
Exited Status = "died"
|
||||||
// Export ...
|
// Export ...
|
||||||
Export Status = "export"
|
Export Status = "export"
|
||||||
// History ...
|
// 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 not using runc, we don't need to do most of this.
|
||||||
if !useRunc {
|
if !useRunc {
|
||||||
// If the container's not running, nothing to do.
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user