libvirt: make guest suspend work, use upstream units

This commit is contained in:
Franz Pletz 2017-03-25 14:59:01 +01:00
parent ddb608814a
commit d545772640
No known key found for this signature in database
GPG Key ID: 846FDED7792617B4
2 changed files with 24 additions and 12 deletions

View File

@ -90,14 +90,16 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
environment.systemPackages = environment.systemPackages = with pkgs;
[ pkgs.libvirt pkgs.netcat-openbsd ] [ libvirt netcat-openbsd ]
++ optional cfg.enableKVM pkgs.qemu_kvm; ++ optional cfg.enableKVM qemu_kvm;
boot.kernelModules = [ "tun" ]; boot.kernelModules = [ "tun" ];
users.extraGroups.libvirtd.gid = config.ids.gids.libvirtd; users.extraGroups.libvirtd.gid = config.ids.gids.libvirtd;
systemd.packages = [ pkgs.libvirt ];
systemd.services.libvirtd = { systemd.services.libvirtd = {
description = "Libvirt Virtual Machine Management Daemon"; description = "Libvirt Virtual Machine Management Daemon";
@ -105,13 +107,17 @@ in {
after = [ "systemd-udev-settle.service" ] after = [ "systemd-udev-settle.service" ]
++ optional vswitch.enable "vswitchd.service"; ++ optional vswitch.enable "vswitchd.service";
path = [ environment = {
pkgs.bridge-utils LIBVIRTD_ARGS = ''--config "${configFile}" ${concatStringsSep " " cfg.extraOptions}'';
pkgs.dmidecode };
pkgs.dnsmasq
pkgs.ebtables path = with pkgs; [
bridge-utils
dmidecode
dnsmasq
ebtables
] ]
++ optional cfg.enableKVM pkgs.qemu_kvm ++ optional cfg.enableKVM qemu_kvm
++ optional vswitch.enable vswitch.package; ++ optional vswitch.enable vswitch.package;
preStart = '' preStart = ''
@ -153,13 +159,17 @@ in {
''; # */ ''; # */
serviceConfig = { serviceConfig = {
ExecStart = ''@${pkgs.libvirt}/sbin/libvirtd libvirtd --config "${configFile}" ${concatStringsSep " " cfg.extraOptions}'';
Type = "notify"; Type = "notify";
KillMode = "process"; # when stopping, leave the VMs alone KillMode = "process"; # when stopping, leave the VMs alone
Restart = "on-failure"; Restart = "on-failure";
}; };
}; };
systemd.services.libvirt-guests = {
wantedBy = [ "multi-user.target" ];
path = with pkgs; [ coreutils libvirt gawk ];
};
systemd.sockets.virtlogd = { systemd.sockets.virtlogd = {
description = "Virtual machine log manager socket"; description = "Virtual machine log manager socket";
wantedBy = [ "sockets.target" ]; wantedBy = [ "sockets.target" ];

View File

@ -58,7 +58,7 @@ stdenv.mkDerivation rec {
"--with-numad" "--with-numad"
"--with-macvtap" "--with-macvtap"
"--with-virtualport" "--with-virtualport"
"--with-init-script=redhat" "--with-init-script=systemd+redhat"
"--with-storage-zfs" "--with-storage-zfs"
] ++ optionals stdenv.isDarwin [ ] ++ optionals stdenv.isDarwin [
"--with-init-script=none" "--with-init-script=none"
@ -72,7 +72,9 @@ stdenv.mkDerivation rec {
postInstall = '' postInstall = ''
sed -i 's/ON_SHUTDOWN=suspend/ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}/' $out/libexec/libvirt-guests.sh sed -i 's/ON_SHUTDOWN=suspend/ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}/' $out/libexec/libvirt-guests.sh
substituteInPlace $out/libexec/libvirt-guests.sh \ substituteInPlace $out/libexec/libvirt-guests.sh \
--replace "$out/bin" "${gettext}/bin" --replace "$out/bin" "${gettext}/bin" \
--replace "lock/subsys" "lock"
rm $out/lib/systemd/system/{virtlockd,virtlogd}.*
'' + optionalString stdenv.isLinux '' '' + optionalString stdenv.isLinux ''
wrapProgram $out/sbin/libvirtd \ wrapProgram $out/sbin/libvirtd \
--prefix PATH : ${makeBinPath [ iptables iproute pmutils numad numactl ]} --prefix PATH : ${makeBinPath [ iptables iproute pmutils numad numactl ]}