summaryrefslogtreecommitdiff
path: root/libpod/container_internal.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-11-23 13:44:37 +0100
committerGitHub <noreply@github.com>2020-11-23 13:44:37 +0100
commitdd343418ce5a3fd6c6238d7e2edc132826756051 (patch)
tree8f6f33d7e8faed4bf8201d655a54a7277282820f /libpod/container_internal.go
parentac55bd1f673156cbb60b568b65f7bf4918daf152 (diff)
parentdc8996ec84ffd6f272361edbf7c19e91c52519d9 (diff)
downloadpodman-dd343418ce5a3fd6c6238d7e2edc132826756051.tar.gz
podman-dd343418ce5a3fd6c6238d7e2edc132826756051.tar.bz2
podman-dd343418ce5a3fd6c6238d7e2edc132826756051.zip
Merge pull request #8263 from rhatdan/restart
Allow containers to --restart on-failure with --rm
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r--libpod/container_internal.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 823e5fb3a..b6a3244ea 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -206,37 +206,39 @@ func (c *Container) handleExitFile(exitFile string, fi os.FileInfo) error {
return nil
}
-// Handle container restart policy.
-// This is called when a container has exited, and was not explicitly stopped by
-// an API call to stop the container or pod it is in.
-func (c *Container) handleRestartPolicy(ctx context.Context) (_ bool, retErr error) {
- // If we did not get a restart policy match, exit immediately.
+func (c *Container) shouldRestart() bool {
+ // If we did not get a restart policy match, return false
// Do the same if we're not a policy that restarts.
if !c.state.RestartPolicyMatch ||
c.config.RestartPolicy == RestartPolicyNo ||
c.config.RestartPolicy == RestartPolicyNone {
- return false, nil
+ return false
}
// If we're RestartPolicyOnFailure, we need to check retries and exit
// code.
if c.config.RestartPolicy == RestartPolicyOnFailure {
if c.state.ExitCode == 0 {
- return false, nil
+ return false
}
// If we don't have a max retries set, continue
if c.config.RestartRetries > 0 {
- if c.state.RestartCount < c.config.RestartRetries {
- logrus.Debugf("Container %s restart policy trigger: on retry %d (of %d)",
- c.ID(), c.state.RestartCount, c.config.RestartRetries)
- } else {
- logrus.Debugf("Container %s restart policy trigger: retries exhausted", c.ID())
- return false, nil
+ if c.state.RestartCount >= c.config.RestartRetries {
+ return false
}
}
}
+ return true
+}
+// Handle container restart policy.
+// This is called when a container has exited, and was not explicitly stopped by
+// an API call to stop the container or pod it is in.
+func (c *Container) handleRestartPolicy(ctx context.Context) (_ bool, retErr error) {
+ if !c.shouldRestart() {
+ return false, nil
+ }
logrus.Debugf("Restarting container %s due to restart policy %s", c.ID(), c.config.RestartPolicy)
// Need to check if dependencies are alive.