-
Notifications
You must be signed in to change notification settings - Fork 3k
Add restart policy for containers #2826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add restart policy for containers #2826
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mheon The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Added support for retry count with the |
|
Manpages are in |
|
I'm going to drop the WIP. Tests are still missing, though. Need to think about how we can test this in a way that doesn't introduce a half dozen more race conditions. |
|
bot, retest this please |
|
Restart policy is not allowed to be specified if user also specifies --rm. |
libpod/container.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docker also supports unless-stopped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- **RestartPolicy** – The behavior to apply when the container exits. The
value is an object with a `Name` property of either `"always"` to
always restart, `"unless-stopped"` to restart always except when
user has manually stopped the container or `"on-failure"` to restart only when the container
exit code is non-zero. If `on-failure` is used, `MaximumRetryCount`
controls the number of times to retry before giving up.
The default is not to restart. (optional)
An ever increasing delay (double the previous delay, starting at 100mS)
is added before each restart to prevent flooding the server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless-stopped is very much a "restarted the daemon" thing, so I just throw an error about it in pkg/spec if they try to pass it.
We still want to point people to systemd for cases like that, where the container will be restarted after system reboot, for example. The manpages make this clear, but it might be good to add the warning to Podman itself too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reading of unless-stopped, seems to be exactly what you are designing. IE If a user stops a container then it will not restart, otherwise if the container fails, it will be restarted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the interpretation depends on where we look. The man page is referring to the daemon start only while the docs state:
Similar to always, except that when the container is stopped (manually or otherwise), it is not restarted even after Docker daemon restarts
This makes me believe that we can support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From that description, it's identical to always - restart policy never triggers after the container is stopped via an API call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Minus the daemon restart aspect)
|
Unless stopped only makes sense with a Daemon. We detect it being passed in
and error that it's not supported.
…On Tue, Apr 2, 2019, 09:04 Daniel J Walsh ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In libpod/container.go
<#2826 (comment)>:
> @@ -102,6 +102,20 @@ func (ns LinuxNS) String() string {
}
}
+// Valid restart policy types.
+const (
+ // RestartPolicyNone indicates that no restart policy has been requested
+ // by a container.
+ RestartPolicyNone = ""
+ // RestartPolicyNo is identical in function to RestartPolicyNone.
+ RestartPolicyNo = "no"
+ // RestartPolicyAlways unconditionally restarts the container.
+ RestartPolicyAlways = "always"
+ // RestartPolicyOnFailure restarts the container on non-0 exit code,
+ // with an optional maximum number of retries.
+ RestartPolicyOnFailure = "on-failure"
Docker also supports unless-stopped
------------------------------
In libpod/container.go
<#2826 (comment)>:
> @@ -102,6 +102,20 @@ func (ns LinuxNS) String() string {
}
}
+// Valid restart policy types.
+const (
+ // RestartPolicyNone indicates that no restart policy has been requested
+ // by a container.
+ RestartPolicyNone = ""
+ // RestartPolicyNo is identical in function to RestartPolicyNone.
+ RestartPolicyNo = "no"
+ // RestartPolicyAlways unconditionally restarts the container.
+ RestartPolicyAlways = "always"
+ // RestartPolicyOnFailure restarts the container on non-0 exit code,
+ // with an optional maximum number of retries.
+ RestartPolicyOnFailure = "on-failure"
- **RestartPolicy** – The behavior to apply when the container exits. The
value is an object with a `Name` property of either `"always"` to
always restart, `"unless-stopped"` to restart always except when
user has manually stopped the container or `"on-failure"` to restart only when the container
exit code is non-zero. If `on-failure` is used, `MaximumRetryCount`
controls the number of times to retry before giving up.
The default is not to restart. (optional)
An ever increasing delay (double the previous delay, starting at 100mS)
is added before each restart to prevent flooding the server.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2826 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHYHCMVjeZm32hMbFQh4irBy-LiWuE14ks5vc1VCgaJpZM4cWdiC>
.
|
|
|
|
/retest |
|
I tested the PR locally with all condition.. working fine as expected. One question regarding flow of control for triggering |
|
In short, it's not. This version of restart policy takes effect when the Podman cleanup process fires. When a Podman container exits, We can't actually detect if a restart is required there, though, as in some cases ( There are limitations to this approach - most notably, we cannot restart containers after a system reboot, because we don't have a running daemon to handle restart policy, and we don't know when a Podman process will first run. For use cases requiring that, using systemd unit files is still recommended - @baude was discussing writing a |
|
@mheon The information you just typed, should probably be added to the man page, and perhaps a troublshoot.md (Minus the stuff about podman generate systemd, (Until it exists.) |
|
bot, retest this please |
|
LGTM |
|
Working on tests now. Once they're in, I'll rebase to pick up Cirrus fixes and we can merge |
2da2bce to
73c1446
Compare
This initial version does not support restart count, but it works as advertised otherwise. Signed-off-by: Matthew Heon <[email protected]>
Noticed this when testing some behavior with Docker. Signed-off-by: Matthew Heon <[email protected]>
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 <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
|
Comments addressed, let's see if CI starts to behave |
Ensure that we can decode the restart event with the new journald events. Signed-off-by: Matthew Heon <[email protected]>
Signed-off-by: Matthew Heon <[email protected]>
|
/retest |
docs/podman-create.1.md
Outdated
| - `always` : Restart containers when they exit, regardless of status, retrying indefinitely | ||
|
|
||
| Please note that restart will not restart containers after a system reboot. | ||
| This this functionality is required in your environment, you can invoke Podman from a systemd unit file, or create an init script for whichever init system is in use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/This this/If this/
docs/podman-run.1.md
Outdated
| - `always` : Restart containers when they exit, regardless of status, retrying indefinitely | ||
|
|
||
| Please note that restart will not restart containers after a system reboot. | ||
| This this functionality is required in your environment, you can invoke Podman from a systemd unit file, or create an init script for whichever init system is in use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto This this
Signed-off-by: Matthew Heon <[email protected]>
|
LGTM, but would like another head nod or two. |
|
Once this passes test, I will merge. |
Theory: it's SELinux blowing up and preventing us from creating files as the container. Try and use a fresh dir and :Z to fix. Signed-off-by: Matthew Heon <[email protected]>
|
Tests are finally starting to pass |
|
I'll beat @rhatdan to the punch. |
Cooked this up after lunch. Implements most of Docker's
--restartflag. We can't implementunless-stopped(we don't have a daemon and as such never experience a daemon restart), and I haven't coded up restart counts yet (another half hour or so of work), butalwaysandon-errorwith infinite restarts work as advertised.Needs tests, bash completions, and for me to stop being lazy and code up restart count.