Permalink
Browse files

Handle times when the instance name cannot be set.

This was occurring when the instance id was reported as invalid by the
EC2 client. We're assuming this is a timing issue as it's a new image.
  • Loading branch information...
1 parent 25a8139 commit abb47ec09cc5df0e2f60f60757d93881c184fcbd @MarkBennett committed Apr 8, 2013
Showing with 18 additions and 1 deletion.
  1. +18 −1 bin/pave
View
@@ -54,6 +54,23 @@ bail() {
exit 1
}
+# Sets the name of the EC2 instance to the supplied name.
+#
+# $1 = ECS instance id
+# $2 = name
+set_instance_name() {
+ local INSTANCE_ID=$1
+ local NAME_TAG=$2
+
+ local TOTAL_TIME=0
+ local MAX_TIME=181
+ while [ $MAX_TIME -gt $TOTAL_TIME ] && ! ec2-create-tags $INSTANCE_ID --tag "Name=$NAME_TAG"; do
+ TOTAL_TIME=$(( $TOTAL_TIME + 5 ))
+ echo "$INSTANCE_ID not provisioned. Waiting 5 seconds before checking again..."
+ sleep 5
+ done
+}
+
[[ $(which ec2-run-instances) ]] || bail "No EC2 AMI Tools found"
if [ $LAUNCH ]; then
@@ -76,7 +93,7 @@ if [ $LAUNCH ]; then
EC2_RUN_RESULT=$(ec2-run-instances --instance-type $INSTANCE_TYPE --group default --region $REGION --key $KEYPAIR $AMI)
INSTANCE_NAME=$(echo ${EC2_RUN_RESULT} | sed 's/RESERVATION.*INSTANCE //' | sed 's/ .*//')
- ec2-create-tags $INSTANCE_NAME --tag "Name=$TAG"
+ set_instance_name $INSTANCE_NAME $TAG
TOTAL_TIME=0
MAX_TIME=181

0 comments on commit abb47ec

Please sign in to comment.