Comment 0 for bug 308530

Revision history for this message
Eric Hammond (esh) wrote : vmbuilder EC2: wait for network before downloading ssh credentials or user-data

When an instance boots quickly on Amazon EC2 the init code can occasionally try to use the network before the network is working.

This may not happen on most boots, but it is definitely worth adding in some code to check for the network before attempting to do critical tasks like:
- download ssh public key
- download user-data

Here is a sample of the script I use to download ssh credentials on the existing Ubuntu EC2 images:

  http://ec2ubuntu.googlecode.com/svn/trunk/etc/init.d/ec2-get-credentials

Note the following code which waits until the network is working before it continues:

perl -MIO::Socket::INET -e '
 until(new IO::Socket::INET("169.254.169.254:80")){print"Waiting for network...\n";sleep 1}
' | $logger

Until this check was added, people experienced random failures where an AMI would boot ok, but they were unable to ssh in because the ssh credentials download had failed.

Many non-Ubuntu AMIs do not experience this problem because they boot so slowly :)