Skip to content

Instantly share code, notes, and snippets.

@boltronics
Created May 7, 2012 05:01
Show Gist options
  • Save boltronics/2626013 to your computer and use it in GitHub Desktop.
Save boltronics/2626013 to your computer and use it in GitHub Desktop.
Vagrant fix for instances getting stuck on boot due to DHCP failure.
#!/bin/bash
#
# Adam Bolte <[email protected]>
#
# Description:
# Run this if Vagrant gets stuck bringing up an instance due to DHCP failure.
declare -r fix_instance=$(basename $(pwd))
for instance in $(VBoxManage list runningvms | grep ${fix_instance} | \
sed -e 's/^"\([^"]*\)".*/\1/')
do
if [ "${fix_instance}" = "${instance%_*}" ]
then
echo -n "Fixing '${instance}'... "
VBoxManage guestcontrol ${instance} exec "/usr/bin/sudo" \
--username vagrant --password vagrant --wait-stdout \
dhclient -- eth0
if [ "${?}" -eq 0 ]
then
echo "OK."
else
echo "FAIL."
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment