我在我的Ubuntu上设置了libvirt / KVM,在关闭机器之前,我希望它尝试使用ACPI断电(virsh关闭)来关闭VM,然后我希望它停止关闭至少60秒以给出VM有机会将所有内容同步到磁盘,这就是我所拥有的:
pre-stop script SHUTDOWN_LOG=/var/log/libvirt/qemu/shutdown_vms.log for RUNNING_VM in `virsh list | grep -E running | awk -F" " '{ print $2 }'` do echo "Shutting down ${RUNNING_VM} on `date`" >> $SHUTDOWN_LOG virsh shutdown ${RUNNING_VM} done echo -n "Waiting for VM's to shut down: " >> $SHUTDOWN_LOG for I in `seq 1 10` do RUNNING=`virsh list | grep running | wc -l` if [[ "$RUNNING" == "0" ]] then echo "done." >> $SHUTDOWN_LOG exit 0 else /bin/sleep 6 && echo -n " ${RUNNING} " >> $SHUTDOWN_LOG fi done echo " Cleaning up..." >> $SHUTDOWN_LOG end script
我遇到的问题是,由于一些奇怪的原因,它永远不会回应“完成”.即使VM都正确关闭,它也会保持循环并因此停止60秒,或者它似乎完全忽略睡眠,将总数写入$SHUTDOWN_LOG并在我的VM同步到磁盘的过程中立即退出.
Shutting down FreeBSD-services on Mon Aug 22 02:07:42 MDT 2011 Shutting down FreeBSD-pgsql on Mon Aug 22 02:07:42 MDT 2011 Waiting for VM's to shut down: 1 [EOF]
最近修复了
https://bugs.launchpad.net/ubuntu/lucid/+source/libvirt/+bug/350936,所以很快就会有一个更新的libvirt.