summary refs log tree commit diff
diff options
context:
space:
mode:
authorCRTified <carl.schneider+github@ruhr-uni-bochum.de>2020-02-15 20:44:36 +0100
committerCRTified <carl.schneider+github@ruhr-uni-bochum.de>2020-02-15 23:16:43 +0100
commitc83cc9c364649560a7a0dafc610c09cf24e39408 (patch)
tree2cbc2c8b045ee2eed1ff6235f8307b86b71a2f73
parent3dabe3024264477cecf9303055df142432ca6bdf (diff)
downloadnixpkgs-c83cc9c364649560a7a0dafc610c09cf24e39408.tar
nixpkgs-c83cc9c364649560a7a0dafc610c09cf24e39408.tar.gz
nixpkgs-c83cc9c364649560a7a0dafc610c09cf24e39408.tar.bz2
nixpkgs-c83cc9c364649560a7a0dafc610c09cf24e39408.tar.lz
nixpkgs-c83cc9c364649560a7a0dafc610c09cf24e39408.tar.xz
nixpkgs-c83cc9c364649560a7a0dafc610c09cf24e39408.tar.zst
nixpkgs-c83cc9c364649560a7a0dafc610c09cf24e39408.zip
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.
-rw-r--r--nixos/modules/virtualisation/docker-containers.nix18
1 files changed, 11 insertions, 7 deletions
diff --git a/nixos/modules/virtualisation/docker-containers.nix b/nixos/modules/virtualisation/docker-containers.nix
index cae39a56f52..5ab990a3d7c 100644
--- a/nixos/modules/virtualisation/docker-containers.nix
+++ b/nixos/modules/virtualisation/docker-containers.nix
@@ -210,7 +210,16 @@ let
     wantedBy = [] ++ optional (container.autoStart) "multi-user.target";
     after = [ "docker.service" "docker.socket" ] ++ mkAfter;
     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 = {
       ExecStart = concatStringsSep " \\\n  " ([
         "${pkgs.docker}/bin/docker run"
@@ -229,12 +238,7 @@ let
         ++ map escapeShellArg container.cmd
       );
 
-      ExecStartPre =
-        ["-${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}";
+      ExecStop = ''${pkgs.bash}/bin/sh -c "[ $SERVICE_RESULT = success ] || docker stop ${name}"'';
 
       ### There is no generalized way of supporting `reload` for docker
       ### containers. Some containers may respond well to SIGHUP sent to their