I've written this code to automatically start KVM Virtual Machine at boot of host system, and stop Virtual Machine at shutdown or reboot of host system.
start on startup
start on started networking and started qemu-kvm and started libvirt-bin
stop on runlevel [016]
kill timeout 70
expect fork
pre-start exec /KVM/luc.sh prepara
exec /KVM/luc.sh avvia
pre-stop script
/KVM/luc.sh ferma
/bin/sleep 20
end script
luc.sh is a script with these functions:
- prepara() - prepare the environment
- avvia() - start KVM
- ferma() - shutdown KVM
It works except for the sleep
command. I need to delay the shutdown/reboot operation of the host system to wait for the guest shutdown to complete. In other words, I want insert a wait of ~20 sec after the /KVM/luc.sh ferma
command. It seems that the sleep
call in the upstart script is asynchronous. Is it possible to make a synchronous call in the upstart script?