Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
2  
I think I can see what you're trying to do: You want your database to be up before your application, which depends on the database, comes up. The problem with your solution is that simply starting the VMs in a particular order does not guarantee anything about when the services they provide will actually become available. You could start the db VM well before the app VM, and it could still happen that the database is not yet ready when the application attempts to connect to it. A better solution would be to design the application to wait for the database to become available. –  Steven Monday Oct 13 '13 at 18:37
    
Thanks @Steven, However I kinda think that just shun the problem. I agree we should design the application that way. But there are situtions we have to ensure the starting order of VMs due to some uncontrollable/stupid reasons –  John Wang Oct 14 '13 at 2:02

1 Answer 1

It's an application level problem, not in infrastructure level.

Actually boot up 2 KVM instance means you power them on, there's no guarantee on the boot up sequence of the 2 operation systems inside those 2 KVM instance in the KVM perspective.

However, you can make it on your own. here's the logic:

  1. boot up VM named db, make sure the database application inside this vm works
  2. then boot up VM named app. Maybe you need to make sure the apps connected to your database.

Take mysql for example, here's a simple bash script:

#!/bin/bash

# start the database VM
sudo virsh start db

# make sure the database is started
IS_DB_DOWN=true
while $IS_DB_DOWN; do
  # test if the DB is up
  nc -z <your-db-host> 3306 > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    IS_DB_DOWN=true
  fi
  sleep 5 # use 5 sec as internal
done

# start your VM that runs application
sudo virsh start app
share|improve this answer
    
Thanks Shawn, my orgininal idea is similiar with yours, i.e., using shell script to control the order. However my init script doesn't work, it doesn't start up the VMs at all. Could you please help me check the script in my question? –  John Wang Oct 14 '13 at 2:12
    
the virsh tool needs the libvirtd daemon running. would u please make sure it works? –  shawnzhu Oct 14 '13 at 4:44
    
I've also suspected that, but the libvirtd init script is indeed put at a higher starting index. i.e., in my /etc/rc2.d/ folder(my default runlevel is 2), I explicitly set my script run after the libvirtd as ... S20libvirt-bin , S30my-kvm-guests, ... –  John Wang Oct 14 '13 at 5:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.