I installed libvirt from slackbuilds.org and it has been working great except for one thing: it does not work once we switch to run level 6 or 0.
I'll explain further

I would like to shutdown all running VMs before shutting down the host.
To accomplish this, I made a script named /etc/rc.d/rc.vm_shutdown and tried to call it from /etc/rc.d/rc.local_shutdown, but it doesn't work.
My script is very simple, and works as intended if called directly:
Code:
#!/bin/bash
# number of seconds to wait for VMs to shutdown, before killing them
MAX_TIMEOUT=30
RUNNING_VM_LIST=$(virsh list|grep running|cut -d " " -f 4-4)
for RUNNING_VM in $RUNNING_VM_LIST; do
virsh shutdown $RUNNING_VM
done
TIMEOUT_COUNTER=0
while true; do
RUNNING_VM_LIST=$(virsh list|grep running|cut -d " " -f 4-4)
if [ -z "$RUNNING_VM_LIST" ]; then
exit 0
else
if [ $TIMEOUT_COUNTER -lt $MAX_TIMEOUT ]; then
sleep 1
TIMEOUT_COUNTER=$[$TIMEOUT_COUNTER+1]
else
for RUNNING_VM in $RUNNING_VM_LIST; do
virsh destroy RUNNING_VM
done
fi
fi
done
As you can see, I use "virsh list" to check for running VMs... the problem is that "virsh list" reports an empty list when called from within rc.local_shutdown
Can anyone explain why this happens and how to solve it?
As a workaround, I edited inittab so it calls my script BEFORE rc.6, but I would rather avoid editing system files if I can.