diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-05-03 10:35:48 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-05-03 10:36:16 -0400 |
commit | d7c367aa61850936249fc99461a92185cb6ba8aa (patch) | |
tree | bc07f5c401638ce59e107a5f13f8b87a06f6fd95 /libpod/container_api.go | |
parent | e1443fe05d146def61a5bb882ed0aafea5730d64 (diff) | |
download | podman-d7c367aa61850936249fc99461a92185cb6ba8aa.tar.gz podman-d7c367aa61850936249fc99461a92185cb6ba8aa.tar.bz2 podman-d7c367aa61850936249fc99461a92185cb6ba8aa.zip |
Address review comments on restart policy
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r-- | libpod/container_api.go | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go index faf01eccb..5bb610aab 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -601,23 +601,18 @@ 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 c.config.RestartPolicy == RestartPolicyOnFailure && c.state.ExitCode != 0 { - logrus.Debugf("Container %s restart policy trigger: on retry %d (of %d)", - c.ID(), c.state.RestartCount, c.config.RestartRetries) - } - if (c.config.RestartPolicy == RestartPolicyOnFailure && c.state.ExitCode != 0 && - (c.config.RestartRetries > 0 && c.state.RestartCount < c.config.RestartRetries)) || - c.config.RestartPolicy == RestartPolicyAlways { - // The container stopped. We need to restart it. - return c.handleRestartPolicy(ctx) - } + // Handle restart policy. + // Returns a bool indicating whether we actually restarted. + // If we did, don't proceed to cleanup - just exit. + didRestart, err := c.handleRestartPolicy(ctx) + if err != nil { + return err + } + if didRestart { + return nil } - // If we aren't hitting restart policy, we perform a normal cleanup + // If we didn't restart, we perform a normal cleanup // Check if we have active exec sessions if len(c.state.ExecSessions) != 0 { |