summary refs log tree commit diff
path: root/nixos/modules/virtualisation/containers.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-02-28 19:20:13 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-02-28 19:23:00 +0100
commit307064ceb512d700a2979b7850082036969cb0ae (patch)
tree3ad742932b972c586045b5d0b7d094e6e2318485 /nixos/modules/virtualisation/containers.nix
parente3c2b4ecbfd97bee5b749fadea3bc3b25fbfcfdb (diff)
downloadnixpkgs-307064ceb512d700a2979b7850082036969cb0ae.tar
nixpkgs-307064ceb512d700a2979b7850082036969cb0ae.tar.gz
nixpkgs-307064ceb512d700a2979b7850082036969cb0ae.tar.bz2
nixpkgs-307064ceb512d700a2979b7850082036969cb0ae.tar.lz
nixpkgs-307064ceb512d700a2979b7850082036969cb0ae.tar.xz
nixpkgs-307064ceb512d700a2979b7850082036969cb0ae.tar.zst
nixpkgs-307064ceb512d700a2979b7850082036969cb0ae.zip
Don't use machinectl to shut down containers
If the host is shutting down, machinectl may fail because it's
bus-activated and D-Bus will be shutting down. So just send a signal
to the leader process directly.

Fixes #6212.
Diffstat (limited to 'nixos/modules/virtualisation/containers.nix')
-rw-r--r--nixos/modules/virtualisation/containers.nix14
1 files changed, 12 insertions, 2 deletions
diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix
index 018e79ae823..da39dda8535 100644
--- a/nixos/modules/virtualisation/containers.nix
+++ b/nixos/modules/virtualisation/containers.nix
@@ -203,7 +203,7 @@ in
         script =
           ''
             mkdir -p -m 0755 "$root/etc" "$root/var/lib"
-            mkdir -p -m 0700 "$root/var/lib/private" "$root/root"
+            mkdir -p -m 0700 "$root/var/lib/private" "$root/root" /run/containers
             if ! [ -e "$root/etc/os-release" ]; then
               touch "$root/etc/os-release"
             fi
@@ -261,11 +261,21 @@ in
                 ip route add $LOCAL_ADDRESS dev $ifaceHost
               fi
             fi
+
+            # Get the leader PID so that we can signal it in
+            # preStop. We can't use machinectl there because D-Bus
+            # might be shutting down. FIXME: in systemd 219 we can
+            # just signal systemd-nspawn to do a clean shutdown.
+            machinectl show "$INSTANCE" | sed 's/Leader=\(.*\)/\1/;t;d' > "/run/containers/$INSTANCE.pid"
           '';
 
         preStop =
           ''
-            machinectl poweroff "$INSTANCE" || true
+            pid="$(cat /run/containers/$INSTANCE.pid)"
+            if [ -n "$pid" ]; then
+              kill -RTMIN+4 "$pid"
+            fi
+            rm -f "/run/containers/$INSTANCE.pid"
           '';
 
         restartIfChanged = false;