commit: 5ed04d55b9a56c932128d867b596bebc6e3ff4ce
Author: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 28 13:35:39 2015 +0000
Commit: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
CommitDate: Fri Aug 28 13:47:55 2015 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5ed04d55
app-emulation/libvirt: tweak libvirt-guests init script
After discussing the new init script on bug #558034 there are two tweaks
being added:
* shift the first argument so that future uses can pass in more arguments
to virsh and the wrapper commands.
* Added LIBVIRT_IGNORE_AUTOSTART to ignore domains that start marked for
autostart in the libvirt XML.
Signed-off-by: Doug Goldstein <cardoe <AT> gentoo.org>
app-emulation/libvirt/files/libvirt-guests.confd | 10 +++++++
app-emulation/libvirt/files/libvirt-guests.init | 33 +++++++++++++++++++-----
2 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/app-emulation/libvirt/files/libvirt-guests.confd
b/app-emulation/libvirt/files/libvirt-guests.confd
index 6e98dc2..514c8ee 100644
--- a/app-emulation/libvirt/files/libvirt-guests.confd
+++ b/app-emulation/libvirt/files/libvirt-guests.confd
@@ -39,6 +39,16 @@
#LIBVIRT_MAXWAIT="500"
+# LIBVIRT_IGNORE_AUTOSTART
+# If the VM is marked for autostart in its XML configuration then we won't
+# save its start when the init script is stopped. The result is that when
+# the init script starts back up, no attempt will be made to start the VM or
+# confirm it is started.
+# Valid values are yes or no
+
+#LIBVIRT_IGNORE_AUTOSTART="no"
+
+
# LIBVIRT_NET_SHUTDOWN
# If libvirtd created networks for you (e.g. NATed networks) then this init
# script will shut them down for you if this is set to 'yes'. Otherwise,
diff --git a/app-emulation/libvirt/files/libvirt-guests.init
b/app-emulation/libvirt/files/libvirt-guests.init
index 045f04d..2b63dea 100644
--- a/app-emulation/libvirt/files/libvirt-guests.init
+++ b/app-emulation/libvirt/files/libvirt-guests.init
@@ -38,20 +38,32 @@ do_virsh() {
libvirtd_dom_list() {
# Only work with domains by their UUIDs
- do_virsh "$1" list --uuid $2
+ local hvuri=$1
+ shift
+
+ do_virsh "${hvuri}" list --uuid $@
}
libvirtd_dom_count() {
- libvirtd_dom_list "$1" $2 | wc -l
+ local hvuri=$1
+ shift
+
+ libvirtd_dom_list "${hvuri}" $@ | wc -l
}
libvirtd_net_list() {
# Only work with networks by their UUIDs
- do_virsh "$1" net-list --uuid $2
+ local hvuri=$1
+ shift
+
+ do_virsh "${hvuri}" net-list --uuid $@
}
libvirtd_net_count() {
- libvirtd_net_list "$1" $2 | wc -l
+ local hvuri=$1
+ shift
+
+ libvirtd_net_list "${hvuri}" $@ | wc -l
}
libvirtd_dom_stop() {
@@ -64,6 +76,7 @@ libvirtd_dom_stop() {
local shutdown_type=${LIBVIRT_SHUTDOWN}
local counter=${LIBVIRT_MAXWAIT}
local dom_name=
+ local dom_as=
local dom_ids=
local uuid=
local dom_count=
@@ -80,10 +93,18 @@ libvirtd_dom_stop() {
# Get the name
dom_name=$(do_virsh ${uri} domname ${uuid})
einfo " ${dom_name}"
+ # Get autostart state
+ dom_as=$(do_virsh ${uri} dominfo ${uuid} | \
+ awk '$1 == "Autostart:" { print $2 }')
if [ "${persist}" = "--persistent" ]; then
- # Save our running state
- echo "${uri} ${uuid}" >> ${gueststatefile}
+ # Save our running state only if
LIBVIRT_IGNORE_AUTOSTART != yes
+ if [ "x${LIBVIRT_IGNORE_AUTOSTART}" = "xyes" ] && \
+ [ ${dom_as} = "enabled" ]; then
+ :
+ else
+ echo "${uri} ${uuid}" >> ${gueststatefile}
+ fi
fi