Here is a small patch for libvirtd init and sysconfig script. Before
killing libvirtd, we virsh shutdown any running domains. We also have
a maximum time limit for shutdown (300 sec default), just in case the
VM will not shut down.
Any thoughts as to whether this is the right place to put this
functionality? Is the shutdown script proper, or since libvirtd
handles autostarts domains internally, should libvirtd shut down
active domains upon SIGTERM all by itself?
-Richard
--- /etc/init.d/libvirtd.orig 2009-01-13 19:31:47.000000000 -0500
+++ /etc/init.d/libvirtd 2009-01-13 19:53:25.000000000 -0500
@@ -47,6 +47,11 @@
LIBVIRTD_CONFIG_ARGS="--config $LIBVIRTD_CONFIG"
fi
+if [ -z "$LIBVIRTD_SHUTDOWN_TIMEOUT" ]
+then
+ LIBVIRTD_SHUTDOWN_TIMEOUT=300
+fi
+
RETVAL=0
start() {
@@ -62,6 +67,15 @@
stop() {
echo -n $"Stopping $SERVICE daemon: "
+ starttime=`date '+%s'`
+ for VM in $(virsh list | grep running | gawk '{print $2}'); do
virsh -q shutdown $VM; done
+ while ( virsh list | grep -qc running ); do
+ sleep 5;
+ nowtime=`date '+%s'`
+ elapsed=$(($nowtime-$starttime))
+ [[ $elapsed -ge $LIBVIRTD_SHUTDOWN_TIMEOUT ]] && break
+ done
+
killproc $PROCESS
RETVAL=$?
echo
--- /etc/sysconfig/libvirtd.orig 2009-01-13 19:56:09.000000000 -0500
+++ /etc/sysconfig/libvirtd 2009-01-13 19:41:27.000000000 -0500
@@ -8,4 +8,7 @@
# Override Kerberos service keytab for SASL/GSSAPI
#KRB5_KTNAME=/etc/libvirt/krb5.tab
+# Shutdown timeout in seconds - Default is 300 seconds (or 5 minutes)
+#LIBVIRTD_SHUTDOWN_TIMEOUT=300
--
-Sir Woody Hackswell