Skip to content
Browse files

Merge pull request #5 from MarkBennett/handle-invalid-id-when-naming-…

…instance

Handle times when the instance name cannot be set.
  • Loading branch information...
2 parents 072ec79 + abb47ec commit 22c65622fc9352f8ab1fd61fdc95760ab8410d5a @mm53bar committed Apr 8, 2013
Showing with 18 additions and 1 deletion.
  1. +18 −1 bin/pave
View
19 bin/pave
@@ -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
@@ -87,7 +104,7 @@ if [ $LAUNCH ]; then
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 22c6562

Please sign in to comment.
Something went wrong with that request. Please try again.