diff --git a/files/libvirt-guests.confd b/files/libvirt-guests.confd index ed2ce58..d794e85 100644 --- a/files/libvirt-guests.confd +++ b/files/libvirt-guests.confd @@ -66,3 +66,12 @@ # NATed network for you. Valid values: 'yes' or 'no' #LIBVIRT_NET_SHUTDOWN="yes" + + +# LIBVIRT_CONWAIT +# The timeout, in seconds, to wait for a connection to LIBVIRT_URIS +# Valid values are any integer greater than or equal to 0 +# 0 means there will be no wait +# +#LIBVIRT_CONWAIT=5 + diff --git a/files/libvirt-guests.init-r4 b/files/libvirt-guests.init-r4 index b29f04c..01b718f 100644 --- a/files/libvirt-guests.init-r4 +++ b/files/libvirt-guests.init-r4 @@ -18,6 +18,10 @@ esac # default to 500 seconds [ -z ${LIBVIRT_MAXWAIT} ] && LIBVIRT_MAXWAIT=500 +# default to 5 seconds +[ -z ${LIBVIRT_CONWAIT} ] && LIBVIRT_CONWAIT=5 + + gueststatefile="/var/lib/libvirt/libvirt-guests.state" netstatefile="/var/lib/libvirt/libvirt-net.state" @@ -165,16 +169,43 @@ libvirtd_net_stop() { fi } +libvirtd_connect_wait() { + # Does up to LIBVIRT_CONWAIT connect attemtpts + # Exits as soon as a successful connection is made + + local hvuri=$1 + local counter=${LIBVIRT_CONWAIT} + local ruri + + einfo " Checking connection to ${hvuri} ..." + + while [ ${counter} -gt 0 ] ; do + ruri=$(do_virsh "${hvuri}" uri) + counter=$((${counter} - 1)) + if [ "${hvuri}" = "${ruri}" ]; then + counter=0 + else + counter=$((${counter} - 1)) + printf "." + sleep 1 + fi + + done + ruri=$(do_virsh "${hvuri}" uri) + if [ "${hvuri}" = "${ruri}" ]; then + einfo " Connection to ${hvuri} OK" + else + eerror "Failed to connect to '${hvuri}'. Domains may not start." + fi +} + start() { local uri= local uuid= local name= for uri in ${LIBVIRT_URIS}; do - do_virsh "${uri}" connect - if [ $? -ne 0 ]; then - eerror "Failed to connect to '${uri}'. Domains may not start." - fi + libvirtd_connect_wait ${uri} done [ ! -e "${netstatefile}" ] && touch "${netstatefile}"