about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorAlbert Peschar <albert@peschar.net>2023-08-10 08:24:26 +0000
committerAlbert Peschar <albert@peschar.net>2023-10-26 12:52:59 +0000
commit6ed6953e22ec8648f566c9a459e84e5b90a71806 (patch)
tree628aa5a5fe960eafa99341810fcfba86b7379511 /nixos
parent1ce5a446bb17c4d440c1159660eff6cdea7f66a4 (diff)
downloadnixlib-6ed6953e22ec8648f566c9a459e84e5b90a71806.tar
nixlib-6ed6953e22ec8648f566c9a459e84e5b90a71806.tar.gz
nixlib-6ed6953e22ec8648f566c9a459e84e5b90a71806.tar.bz2
nixlib-6ed6953e22ec8648f566c9a459e84e5b90a71806.tar.lz
nixlib-6ed6953e22ec8648f566c9a459e84e5b90a71806.tar.xz
nixlib-6ed6953e22ec8648f566c9a459e84e5b90a71806.tar.zst
nixlib-6ed6953e22ec8648f566c9a459e84e5b90a71806.zip
nixos/oci-containers: stop container using backend
Make systemd actually call `podman stop` when stopping a container unit.

Fixes #249332
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/virtualisation/oci-containers.nix7
-rw-r--r--nixos/tests/oci-containers.nix5
2 files changed, 9 insertions, 3 deletions
diff --git a/nixos/modules/virtualisation/oci-containers.nix b/nixos/modules/virtualisation/oci-containers.nix
index 71f5d7a752c8..29d287afbdd2 100644
--- a/nixos/modules/virtualisation/oci-containers.nix
+++ b/nixos/modules/virtualisation/oci-containers.nix
@@ -296,9 +296,10 @@ let
     );
 
     preStop = if cfg.backend == "podman"
-      then "[ $SERVICE_RESULT = success ] || podman stop --ignore --cidfile=/run/podman-${escapedName}.ctr-id"
-      else "[ $SERVICE_RESULT = success ] || ${cfg.backend} stop ${name}";
-    postStop =  if cfg.backend == "podman"
+      then "podman stop --ignore --cidfile=/run/podman-${escapedName}.ctr-id"
+      else "${cfg.backend} stop ${name}";
+
+    postStop = if cfg.backend == "podman"
       then "podman rm -f --ignore --cidfile=/run/podman-${escapedName}.ctr-id"
       else "${cfg.backend} rm -f ${name} || true";
 
diff --git a/nixos/tests/oci-containers.nix b/nixos/tests/oci-containers.nix
index 1afa9df36dfa..e5029d3799f6 100644
--- a/nixos/tests/oci-containers.nix
+++ b/nixos/tests/oci-containers.nix
@@ -24,6 +24,10 @@ let
             ports = ["8181:80"];
           };
         };
+
+        # Stop systemd from killing remaining processes if ExecStop script
+        # doesn't work, so that proper stopping can be tested.
+        systemd.services."${backend}-nginx".serviceConfig.KillSignal = "SIGCONT";
       };
     };
 
@@ -32,6 +36,7 @@ let
       ${backend}.wait_for_unit("${backend}-nginx.service")
       ${backend}.wait_for_open_port(8181)
       ${backend}.wait_until_succeeds("curl -f http://localhost:8181 | grep Hello")
+      ${backend}.succeed("systemctl stop ${backend}-nginx.service", timeout=10)
     '';
   };