summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 5bfd869b3..46c913e99 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -583,6 +583,7 @@ func (c *Container) Cleanup(ctx context.Context) error {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
+
if err := c.syncContainer(); err != nil {
return err
}
@@ -593,6 +594,24 @@ func (c *Container) Cleanup(ctx context.Context) error {
return errors.Wrapf(ErrCtrStateInvalid, "container %s is running or paused, refusing to clean up", c.ID())
}
+ // If we have a restart policy match when updating the state, we need to
+ // restart the container.
+ // However, perform a full validation of restart policy first.
+ if c.state.RestartPolicyMatch {
+ // if restart policy is on-error and exit code is 0, we do
+ // nothing.
+ // TODO: if restart retries is set, handle that here.
+ if c.config.RestartRetries != 0 {
+ return errors.Wrapf(ErrNotImplemented, "restart retries not yet implemented")
+ }
+ if (c.config.RestartPolicy == "on-error" && c.state.ExitCode == 0) || c.config.RestartPolicy == "always" {
+ // The container stopped. We need to restart it.
+ return c.handleRestartPolicy(ctx)
+ }
+ }
+
+ // If we aren't hitting restart policy, we perform a normal cleanup
+
// Check if we have active exec sessions
if len(c.state.ExecSessions) != 0 {
return errors.Wrapf(ErrCtrStateInvalid, "container %s has active exec sessions, refusing to clean up", c.ID())