Now and then the VMs (kvm, libvirt + vmbuilder) I was cranking out would start up too fast, and the “first boot” script would run before the host got an IP address and had internet access. Since the first thing I was doing was downloading the Rubygems source using wget (to install chef), and since wget lacks a retry for dns failure, I hacked up this script to wait for the internet a bit.
#!/bin/bash # Wait for internet to come up (DHCP) MAXWAIT=60 WAITTIME=0 host production.cf.rubygems.org > /dev/null while [ $? == 1 ] && [ $WAITTIME -le $MAXWAIT ] ; do WAITTIME=$(($WAITTIME + 10)) sleep 10 echo -n . host production.cf.rubygems.org > /dev/null done