diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-04-01 15:22:32 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-05-03 10:36:16 -0400 |
commit | 0d73ee40b2e95ec7d50c7ee72fcb24cae0e190a7 (patch) | |
tree | 665382c42613e99258536536d61b00462a67ae53 /libpod/container_api.go | |
parent | 3fb52f4fbb04781e32f72888c9e509dea5d7b434 (diff) | |
download | podman-0d73ee40b2e95ec7d50c7ee72fcb24cae0e190a7.tar.gz podman-0d73ee40b2e95ec7d50c7ee72fcb24cae0e190a7.tar.bz2 podman-0d73ee40b2e95ec7d50c7ee72fcb24cae0e190a7.zip |
Add container restart policy to Libpod & Podman
This initial version does not support restart count, but it works
as advertised otherwise.
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r-- | libpod/container_api.go | 19 |
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()) |