Why don't the symbolic links in kvm autostart not work
I've deployed 2 kvm guests( db and app) on a Debian7 host.
I can set them autostart by
root@mhost:~# virsh autostart db
root@mhost:~# virsh autostart app
This actually creates 2 symbolic links at the /etc/libvirt/qemu/autostart/
:
root@mhost:~# ls /etc/libvirt/qemu/autostart/
db.xml app.xml
Then I thought I can ensure the two guests starting order by simply changing the links name:
root@mhost:/etc/libvirt/qemu/autostart# mv db.xml 10db.xml
root@mhost:/etc/libvirt/qemu/autostart# mv app.xml 20app.xml
but it turns out this doesn't work. Actually after changing the links name, they even don't autostart anymore. What's the problem?
There is a similiar question with answer, but it didn't explain why the symbolic links method not work.
Also, I've tried to use init start script to ensure the order, but it didn't work either. I'm not a shell script guy, so there might be some problem in my script, i.e., the following:
#! /bin/sh
# /etc/init.d/kvmguests
case "$1" in
start)
echo "Starting all kvm guests ..."
virsh start db
virsh start app
echo "Done."
;;
stop)
echo "Stopping all kvm guests ..."
virsh shutdown app
virsh shutdown db
echo "Done."
;;
*)
echo "Usage: /etc/init.d/kvmguests {start|stop}"
exit 1
;;
esac
exit 0
Solution 1:
IMHO I don't think you can control the boot order by changing the names of the symlinks. but there is a workaround
In /etc/sysconfig/libvirt-guests
option START_DELAY
you can set the delay between boots (so not all vms will start at the same time)
To (sort of) control the order you can change <emulator>
tag in domain XML and point to your script, which will start domain after some delay
e.g. something like this:
<domain type='kvm'>
<name>test</name>
...
<devices>
<emulator>/usr/local/bin/qemu-kvm-delay</emulator>
<devices>
</domain>
the content of /usr/local/bin/qemu-kvm-delay
could be as simple as:
sleep 1000
exec /usr/bin/qemu-kvm $*
or something fancy as testing for some service availability and calculating the delay for each vm