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/options.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/options.go')
-rw-r--r-- | libpod/options.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go index 86c04db09..e83515822 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -1239,6 +1239,41 @@ func WithUseImageHosts() CtrCreateOption { } } +// WithRestartPolicy sets the container's restart policy. Valid values are +// "no", "on-failure", and "always". The empty string is allowed, and will be +// equivalent to "no". +func WithRestartPolicy(policy string) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return ErrCtrFinalized + } + + switch policy { + case "", "no", "on-failure", "always": + ctr.config.RestartPolicy = policy + default: + return errors.Wrapf(ErrInvalidArg, "%q is not a valid restart policy", policy) + } + + return nil + } +} + +// WithRestartRetries sets the number of retries to use when restarting a +// container with the "on-failure" restart policy. +// 0 is an allowed value, and indicates infinite retries. +func WithRestartRetries(tries uint) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return ErrCtrFinalized + } + + ctr.config.RestartRetries = tries + + return nil + } +} + // withIsInfra sets the container to be an infra container. This means the container will be sometimes hidden // and expected to be the first container in the pod. func withIsInfra() CtrCreateOption { |