Ensure libvirtd is started after vswitch and add ability to configure how libvirtd guests are shutdown

This commit is contained in:
Chris Farmiloe 2014-06-16 16:45:08 +02:00 committed by Michael Raskin
parent 76a4de68c1
commit 08534000a4
2 changed files with 23 additions and 2 deletions

View File

@ -57,6 +57,20 @@ in
'';
};
virtualisation.libvirtd.onShutdown =
mkOption {
type = types.enum ["shutdown" "suspend" ];
default = "suspend";
description =
''
When shutting down / restarting the host what method should
be used to gracefully halt the guests. Setting to "shutdown"
will cause an ACPI shutdown of each guest. "suspend" will
attempt to save the state of the guests ready to restore on boot.
'';
};
};
@ -74,7 +88,8 @@ in
{ description = "Libvirt Virtual Machine Management Daemon";
wantedBy = [ "multi-user.target" ];
after = [ "systemd-udev-settle.service" ];
after = [ "systemd-udev-settle.service" ]
++ optional vswitch.enable "vswitchd.service";
path = [
pkgs.bridge_utils
@ -157,7 +172,12 @@ in
${pkgs.libvirt}/etc/rc.d/init.d/libvirt-guests start || true
'';
postStop = "${pkgs.libvirt}/etc/rc.d/init.d/libvirt-guests stop";
postStop =
''
export PATH=${pkgs.gettext}/bin:$PATH
export ON_SHUTDOWN=${cfg.onShutdown}
${pkgs.libvirt}/etc/rc.d/init.d/libvirt-guests stop
'';
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;

View File

@ -39,6 +39,7 @@ stdenv.mkDerivation rec {
];
postInstall = ''
sed -i 's/ON_SHUTDOWN=suspend/ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}/' $out/libexec/libvirt-guests.sh
substituteInPlace $out/libexec/libvirt-guests.sh \
--replace "$out/bin" "${gettext}/bin"
wrapProgram $out/sbin/libvirtd \