API: add "signal" parameter to container stop and restart endpoints#43206
Conversation
f876056 to
36caa69
Compare
|
@AkihiroSuda @cpuguy83 ptal |
api/types/container/config.go
Outdated
| // StopConfig holds the options to stop, or restart a container. | ||
| type StopConfig struct { | ||
| StopSignal string `json:",omitempty"` // Signal to stop the container. | ||
| StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop the container, or '-1' to wait indefinitely. | ||
| } |
There was a problem hiding this comment.
🙈 and I just realised why I probably didn't push it as a PR before; I see that I didn't change the client code to allow the new options to be set.
Looking at that, I'm a bit on the fence if StopConfig should be used for both stop and restart (or if separate types should be used).
Let me temporarily move this PR back to draft, and work on the client bits
36caa69 to
24957b4
Compare
24957b4 to
e41a0bf
Compare
|
@tianon @AkihiroSuda - Rebased, pushed the commits with the client-side changes that I didn't include, PTAL |
e9d8f5f to
0aebf51
Compare
| daemon.statsCollector.StopCollection(container) | ||
|
|
||
| if err := daemon.containerStop(container, 3); err != nil { | ||
| var stopTimeout = 3 |
There was a problem hiding this comment.
IMO a good (unrelated) follow-up here would be to add a comment of some kind here explaining what this is and why we chose "3" as the hard-coded override value 😬
There was a problem hiding this comment.
alright; as I also had to address @samuelkarp's comments, I added a comment; the "bad" news; "who knows??" (but I left references to the commits that set this duration). The good news: you can earn yourself a picture of a cute animal!
samuelkarp
left a comment
There was a problem hiding this comment.
Two nits (one in-line, one here) and one minor comment.
nit: commit "daemon: move default stop-timeout to containerStop()" has a typo in the commit message ("determin")
But aside from those, LGTM!
- daemon/delete: rename var that collided with import, remove output var - daemon: fix inconsistent receiver name and package aliases - daemon/stop: rename imports and variables to standard naming This is in preparation of some changes, but keeping it in a separate commit to make review of other changes easier. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
We already have this config, so might as well pass it, instead of passing each option as a separate argument. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This avoids having to determine what the default is in various parts of the code. If no custom timeout is passed (nil), the default will be used. Also remove the named return variable from cleanupContainer(), as it wasn't used. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
While we're modifying the interface, also add a context to both. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Containers can have a default stop-signal (`--stop-signal` / `STOPSIGNAL`) and
timeout (`--stop-timeout`). It is currently not possible to update either of
these after the container is created (`docker update` does not allow updating
them), and while either of these can be overridden through some commands, we
currently do not have a command that can override *both*:
command | stop-signal | stop-timeout | notes
----------------|-------------|--------------|----------------------------
docker kill | yes | DNA | only sends a single signal
docker restart | no | yes |
docker stop | no | yes |
As a result, if a user wants to stop a container with a custom signal and
timeout, the only option is to do this manually:
docker kill -s <custom signal> mycontainer
# wait <desired timeout>
# press ^C to cancel the graceful stop
# forcibly kill the container
docker kill mycontainer
This patch adds a new `signal` query parameter to the container "stop" and
"restart" endpoints. This parameter can be added as a new flag on the CLI,
which would allow stopping and restarting with a custom timeout and signal,
for example:
docker stop --signal=SIGWINCH --time=120 mycontainer
docker restart --signal=SIGWINCH --time=120 mycontainer
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…onger used Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
0aebf51 to
90647e2
Compare
|
Updated; fixed the typo in the commit message; changed |
|
thx! Looking at the review comments, I think they've been addressed; let me get this one in, and work on docker/cli changes to expose these options 👍 |
When reviewing #41548, I recalled I had this branch, but never opened it as a PR, as I was planning to do so after #42774 was merged.
depends on / includes:
API: add "signal" parameter to container stop and restart endpoints
Containers can have a default stop-signal (
--stop-signal/STOPSIGNAL) andtimeout (
--stop-timeout). It is currently not possible to update either ofthese after the container is created (
docker updatedoes not allow updatingthem), and while either of these can be overridden through some commands, we
currently do not have a command that can override both:
As a result, if a user wants to stop a container with a custom signal and
timeout, the only option is to do this manually:
This patch adds a new
signalquery parameter to the container "stop" and"restart" endpoints. This parameter can be added as a new flag on the CLI,
which would allow stopping and restarting with a custom timeout and signal,
for example:
Refactoring / cleanup commits
daemon/delete: rename var that collided with import, remove output var (part of #42774)
Renamed a variable that collided with an import.
Also remove the named return variable from cleanupContainer(), as it wasn't used.
daemon: cleanupContainer(): pass ContainerRmConfig as parameter (part of #42774)
We already have this config, so might as well pass it, instead of passing each option as a separate argument.
daemon: fix inconsistent receiver name and package aliases
My IDE kept complaining about this one, so let's rename it
daemon/stop: rename imports and variables to standard naming
This is in preparation of some changes, but keeping it in a separate commit to make review of other changes easier.
daemon: move default stop-timeout to containerStop()
This avoids having to determine what the default is in various parts of the code. If no custom timeout is passed (nil), the default will be used.
Also remove the named return variable from cleanupContainer(), as it wasn't used.
daemon: containerStop(): use a regular "defer" to log container event
backend: add StopConfig to ContainerRestart and ContainerStop
And while we're modifying the interface, also add a context to both