0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-14 06:00:33 +03:00

nixos/docker-containers: Move ExecStartPre/ExecStopPost to preStart/postStop

This commit fixes #76620. It moves ExecStartPre and ExecStopPost to
preStart and postStop, as these options are composable. It thus allows
adding additional initialisation scripts or cleanup scripts to the systemd
unit of the docker container.
This commit is contained in:
CRTified 2020-02-15 20:44:36 +01:00
parent 3dabe30242
commit c83cc9c364

View file

@ -210,7 +210,16 @@ let
wantedBy = [] ++ optional (container.autoStart) "multi-user.target"; wantedBy = [] ++ optional (container.autoStart) "multi-user.target";
after = [ "docker.service" "docker.socket" ] ++ mkAfter; after = [ "docker.service" "docker.socket" ] ++ mkAfter;
requires = after; requires = after;
path = [ pkgs.docker ];
preStart = ''
docker rm -f ${name} || true
${optionalString (container.imageFile != null) ''
docker load -i ${container.imageFile}
''}
'';
postStop = "docker rm -f ${name} || true";
serviceConfig = { serviceConfig = {
ExecStart = concatStringsSep " \\\n " ([ ExecStart = concatStringsSep " \\\n " ([
"${pkgs.docker}/bin/docker run" "${pkgs.docker}/bin/docker run"
@ -229,12 +238,7 @@ let
++ map escapeShellArg container.cmd ++ map escapeShellArg container.cmd
); );
ExecStartPre = ExecStop = ''${pkgs.bash}/bin/sh -c "[ $SERVICE_RESULT = success ] || docker stop ${name}"'';
["-${pkgs.docker}/bin/docker rm -f ${name}"] ++
(optional (container.imageFile != null) "${pkgs.docker}/bin/docker load -i ${container.imageFile}");
ExecStop = ''${pkgs.bash}/bin/sh -c "[ $SERVICE_RESULT = success ] || ${pkgs.docker}/bin/docker stop ${name}"'';
ExecStopPost = "-${pkgs.docker}/bin/docker rm -f ${name}";
### There is no generalized way of supporting `reload` for docker ### There is no generalized way of supporting `reload` for docker
### containers. Some containers may respond well to SIGHUP sent to their ### containers. Some containers may respond well to SIGHUP sent to their