From 78970706c4708ffeef09e596cdced2ec05b1e9d1 Mon Sep 17 00:00:00 2001 From: GSI2022 <2022@groovy-skills.com> Date: Wed, 9 Mar 2022 21:16:30 +0100 Subject: [PATCH] libvirt: add service for controlling guests marked "autostart" --- srcpkgs/libvirt/files/libvirtd-guests/finish | 24 ++++++++++++++++++++ srcpkgs/libvirt/files/libvirtd-guests/run | 11 +++++++++ srcpkgs/libvirt/template | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 srcpkgs/libvirt/files/libvirtd-guests/finish create mode 100755 srcpkgs/libvirt/files/libvirtd-guests/run diff --git a/srcpkgs/libvirt/files/libvirtd-guests/finish b/srcpkgs/libvirt/files/libvirtd-guests/finish new file mode 100755 index 000000000000..3e25b8cd2ce0 --- /dev/null +++ b/srcpkgs/libvirt/files/libvirtd-guests/finish @@ -0,0 +1,24 @@ +#!/bin/sh + +# Command guests to shut down and wait for them to finish. +# A reasonable grace period should be set via the SVWAIT environment variable. +# Example: SVWAIT=300 sv stop libvirtd-guests +# +# Note that the "libvirtd-guests" service only handles guests marked "autostart". + +request_guest_shutdown () { + local guests="${1}" + echo "$guests" | while read g ; do virsh shutdown "$g" ; done +} + +guests=`virsh list --name --autostart | sed '/^$/d'` +request_guest_shutdown "$guests" + +# Wait until guests are powered off. +while [ "$guests" != "" ] ; do + # Apparently certain (Windows) guests want to be asked multiple + # times to shut down. + request_guest_shutdown "$guests" + sleep 1 + guests=`virsh list --name --autostart | sed '/^$/d'` +done diff --git a/srcpkgs/libvirt/files/libvirtd-guests/run b/srcpkgs/libvirt/files/libvirtd-guests/run new file mode 100755 index 000000000000..4ba801fb5f91 --- /dev/null +++ b/srcpkgs/libvirt/files/libvirtd-guests/run @@ -0,0 +1,11 @@ +#!/bin/sh + +guests=`virsh list --name --autostart --state-shutoff` + +echo "$guests" | while read g ; do + if [ "$g" != '' ] ; then + virsh start "$g" + fi +done + +pause diff --git a/srcpkgs/libvirt/template b/srcpkgs/libvirt/template index 1568aa905a56..65071b566485 100644 --- a/srcpkgs/libvirt/template +++ b/srcpkgs/libvirt/template @@ -89,7 +89,7 @@ post_install() { local _services _srv # runit services; libvirtd is for legacy use - _services="libvirt-generic libvirtd virtqemud virtvboxd virtxend + _services="libvirt-generic libvirtd libvirtd-guests virtqemud virtvboxd virtxend virtlxcd virtlockd virtlogd virtproxyd virtinterfaced virtnetworkd virtnodedevd virtnwfilterd virtsecretd virtstoraged" for _srv in $_services; do