summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-04-01 19:20:03 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-05-03 10:36:16 -0400
commitf4db6d5cf61741f9b0de163b158ecdc2bcfa6669 (patch)
tree5fe2d6ca45412231af907946e4a31d6efb0c4305 /libpod/container_api.go
parentdc42304f3804632d01345478ab9b1f122b48d516 (diff)
downloadpodman-f4db6d5cf61741f9b0de163b158ecdc2bcfa6669.tar.gz
podman-f4db6d5cf61741f9b0de163b158ecdc2bcfa6669.tar.bz2
podman-f4db6d5cf61741f9b0de163b158ecdc2bcfa6669.zip
Add support for retry count with --restart flag
The on-failure restart option supports restarting only a given number of times. To do this, we need one additional field in the DB to track restart count (which conveniently fills a field in Inspect we weren't populating), plus some plumbing logic. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 8b3dd4186..7132a82c2 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -57,11 +57,11 @@ func (c *Container) Init(ctx context.Context) (err error) {
if c.state.State == ContainerStateStopped {
// Reinitialize the container
- return c.reinit(ctx)
+ return c.reinit(ctx, false)
}
// Initialize the container for the first time
- return c.init(ctx)
+ return c.init(ctx, false)
}
// Start starts a container.
@@ -605,13 +605,13 @@ func (c *Container) Cleanup(ctx context.Context) error {
// 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-failure" && 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 == "on-error" && c.state.ExitCode == 0) || c.config.RestartPolicy == "always" {
+ if (c.config.RestartPolicy == "on-failure" && c.state.ExitCode != 0 &&
+ (c.config.RestartRetries > 0 && c.state.RestartCount < c.config.RestartRetries)) ||
+ c.config.RestartPolicy == "always" {
// The container stopped. We need to restart it.
return c.handleRestartPolicy(ctx)
}
@@ -780,7 +780,7 @@ func (c *Container) Refresh(ctx context.Context) error {
if err := c.prepare(); err != nil {
return err
}
- if err := c.init(ctx); err != nil {
+ if err := c.init(ctx, false); err != nil {
return err
}
}