aboutsummaryrefslogtreecommitdiff
path: root/pkg/spec/createconfig.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-04-01 15:22:32 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-05-03 10:36:16 -0400
commit0d73ee40b2e95ec7d50c7ee72fcb24cae0e190a7 (patch)
tree665382c42613e99258536536d61b00462a67ae53 /pkg/spec/createconfig.go
parent3fb52f4fbb04781e32f72888c9e509dea5d7b434 (diff)
downloadpodman-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 'pkg/spec/createconfig.go')
-rw-r--r--pkg/spec/createconfig.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go
index 90e7accf3..f1861dd19 100644
--- a/pkg/spec/createconfig.go
+++ b/pkg/spec/createconfig.go
@@ -108,6 +108,7 @@ type CreateConfig struct {
ReadOnlyRootfs bool //read-only
ReadOnlyTmpfs bool //read-only-tmpfs
Resources CreateResourceConfig
+ RestartPolicy string
Rm bool //rm
StopSignal syscall.Signal // stop-signal
StopTimeout uint // stop-timeout
@@ -359,6 +360,26 @@ func (c *CreateConfig) getContainerCreateOptions(runtime *libpod.Runtime, pod *l
options = append(options, libpod.WithCgroupParent(c.CgroupParent))
}
+ if c.RestartPolicy != "" {
+ if c.RestartPolicy == "unless-stopped" {
+ return nil, errors.Wrapf(libpod.ErrInvalidArg, "the unless-stopped restart policy is not supported")
+ }
+
+ split := strings.Split(c.RestartPolicy, ":")
+ if len(split) > 1 {
+ numTries, err := strconv.Atoi(split[1])
+ if err != nil {
+ return nil, errors.Wrapf(err, "%s is not a valid number of retries for restart policy", split[1])
+ }
+ if numTries < 0 {
+ return nil, errors.Wrapf(libpod.ErrInvalidArg, "restart policy requires a positive number of retries")
+ }
+ options = append(options, libpod.WithRestartRetries(uint(numTries)))
+ }
+
+ options = append(options, libpod.WithRestartPolicy(c.RestartPolicy))
+ }
+
// Always use a cleanup process to clean up Podman after termination
exitCmd, err := c.createExitCommand(runtime)
if err != nil {