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
Docker-containers: Consider the exit status of docker run in ExecStop #76444
Conversation
We don't need to stop the container if it already exited sucessfully
clone nixpkgs repo && cd there That's it. |
See also https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type= It is unset currently for declarative docker containers, which means it has type You may set it with:
Also, you may use |
That's exactly what I was looking for, thank you! I'm still learning how to properly interface with the Nix language, so basic things like these are still not obvious to me.
The
* You could to it that way but having to fiddle with systemd services to get your docker containers to behave the way you want is a bit unclean IMO and actually not at all obvious to someone who doesn't know how
That sounds cleaner, I'll take a look. Thanks! |
I tried it out and it does indeed look a bit cleaner but I have a few issues with it:
|
okay, this sounds reasonable. What about removing ExecStop entirely? Looking at https://docs.docker.com/engine/reference/commandline/stop/:
But this is almost systemd behavior when no ExecStop present (https://www.freedesktop.org/software/systemd/man/systemd.service.html):
The last bit (kill only main process instead of all subprocesses) can be achieved with KillMode=mixed (https://www.freedesktop.org/software/systemd/man/systemd.kill.html#KillMode=) |
Yeah, I also thought about that and assumed they were added for good reason. I the author didn't include a comment on these parameters in their commit message or PR unfortunately but they do mention that reload isn't implemented because docker containers might not respond well to some kill signals (https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/docker-containers.nix#L192), so maybe |
+1, agree
we can try =) |
I didn't know about If I recall correctly, the redundant |
That makes sense, thanks a lot! Maybe we should investigate that in a separate PR/Issue though, this one works for now. |
We don't need to stop the container if it already exited sucessfully (cherry picked from commit a461f3f)
Motivation for this change
If the docker run command exits with a positive exit status we don't need to stop it.
In fact, if we try to stop it, the
docker stop
command will fail which then makes the service fail and that obviously shouldn't happen (see #73114).I am aware that checking things with a shell script like that seems hacky but the systemd manual states that
ExecStop
needs to account for exit status by itself and there is no simpler way to make it do that afaik.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after) ~5KI have no idea how I would go about using NixOS tests and a link to the source of a bunch of tests doesn't help. If someone could give me an example for this, that'd teach me a lot. (I did test it manually though.)
I tried the nixpkgs-review command but I don't think I used it properly, how do I do that? Is this even relevant for modules?
This is my first PR, I am pretty sure I missed something else too. Please tell me if I did and what.
Notify maintainers
cc @