aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-05-03 23:14:12 +0200
committerGitHub <noreply@github.com>2019-05-03 23:14:12 +0200
commit4aa90145bf611a7bc08ddff7e061a630154e8b40 (patch)
tree01dc345c05b6ef2c5416eb169f0388c3afb4feb1 /pkg
parent2658e870d21dc03096740f17fa869463136d3fae (diff)
parentd3286952e6f99b3c1f8ba177d8caddc9544adea4 (diff)
downloadpodman-4aa90145bf611a7bc08ddff7e061a630154e8b40.tar.gz
podman-4aa90145bf611a7bc08ddff7e061a630154e8b40.tar.bz2
podman-4aa90145bf611a7bc08ddff7e061a630154e8b40.zip
Merge pull request #2826 from mheon/restart_policy
Add restart policy for containers
Diffstat (limited to 'pkg')
-rw-r--r--pkg/inspect/inspect.go2
-rw-r--r--pkg/spec/createconfig.go20
2 files changed, 21 insertions, 1 deletions
diff --git a/pkg/inspect/inspect.go b/pkg/inspect/inspect.go
index 6978370ef..693755aa8 100644
--- a/pkg/inspect/inspect.go
+++ b/pkg/inspect/inspect.go
@@ -161,7 +161,7 @@ type ContainerInspectData struct {
LogPath string `json:"LogPath"`
ConmonPidFile string `json:"ConmonPidFile"`
Name string `json:"Name"`
- RestartCount int32 `json:"RestartCount"` //TODO
+ RestartCount int32 `json:"RestartCount"`
Driver string `json:"Driver"`
MountLabel string `json:"MountLabel"`
ProcessLabel string `json:"ProcessLabel"`
diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go
index 90e7accf3..9979e773c 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,25 @@ 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(split[0]))
+ }
+
// Always use a cleanup process to clean up Podman after termination
exitCmd, err := c.createExitCommand(runtime)
if err != nil {