|
38 | 38 | # check that the CoreOS user-data file is valid |
39 | 39 | $CONTRIB_DIR/util/check-user-data.sh |
40 | 40 |
|
| 41 | +# Prepare bailout function to prevent us polluting the namespace |
| 42 | +bailout() { |
| 43 | + aws cloudformation delete-stack --stack-name $STACK_NAME |
| 44 | +} |
| 45 | + |
41 | 46 | # create an EC2 cloudformation stack based on CoreOS's default template |
42 | 47 | aws cloudformation create-stack \ |
43 | 48 | --template-body "$($THIS_DIR/gen-json.py)" \ |
44 | 49 | --stack-name $STACK_NAME \ |
45 | 50 | --parameters "$(<$THIS_DIR/cloudformation.json)" |
46 | 51 |
|
47 | 52 | # loop until the instances are created |
48 | | -ATTEMPTS=45 |
| 53 | +ATTEMPTS=60 |
49 | 54 | SLEEPTIME=10 |
50 | 55 | COUNTER=1 |
51 | 56 | INSTANCE_IDS="" |
52 | | -until [ `wc -w <<< $INSTANCE_IDS` -eq $DEIS_NUM_INSTANCES -a "$STACK_STATUS" = "CREATE_COMPLETE" ]; do |
53 | | - if [ $COUNTER -gt $ATTEMPTS ]; then echo "Timed out waiting for instances..." ; exit 1; fi # timeout after 7 1/2 minutes |
54 | | - echo "Waiting for instances to be created... $STACK_STATUS" |
55 | | - sleep $SLEEPTIME |
| 57 | +until [ $(wc -w <<< $INSTANCE_IDS) -eq $DEIS_NUM_INSTANCES -a "$STACK_STATUS" = "CREATE_COMPLETE" ]; do |
| 58 | + if [ $COUNTER -gt $ATTEMPTS ]; then |
| 59 | + echo "Provisioning instances failed (timeout, $(wc -w <<< $INSTANCE_IDS) of $DEIS_NUM_INSTANCES provisioned after 10m)" |
| 60 | + echo "Destroying stack $STACK_NAME" |
| 61 | + bailout |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + |
56 | 65 | STACK_STATUS=$(aws --output text cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[].StackStatus') |
57 | 66 | if [ $STACK_STATUS != "CREATE_IN_PROGRESS" -a $STACK_STATUS != "CREATE_COMPLETE" ] ; then |
58 | 67 | echo "error creating stack: " |
59 | 68 | aws --output text cloudformation describe-stack-events \ |
60 | 69 | --stack-name $STACK_NAME \ |
61 | 70 | --query 'StackEvents[?ResourceStatus==`CREATE_FAILED`].[LogicalResourceId,ResourceStatusReason]' |
| 71 | + bailout |
62 | 72 | exit 1 |
63 | 73 | fi |
| 74 | + |
64 | 75 | INSTANCE_IDS=$(aws ec2 describe-instances \ |
65 | 76 | --filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \ |
66 | 77 | --query 'Reservations[].Instances[].[ InstanceId ]' \ |
67 | 78 | --output text) |
| 79 | + |
| 80 | + echo "Waiting for instances to be provisioned ($STACK_STATUS, $(expr 61 - $COUNTER)0s) ..." |
| 81 | + sleep $SLEEPTIME |
| 82 | + |
68 | 83 | let COUNTER=COUNTER+1 |
69 | 84 | done |
70 | 85 |
|
71 | 86 | # loop until the instances pass health checks |
72 | 87 | COUNTER=1 |
73 | 88 | INSTANCE_STATUSES="" |
74 | 89 | until [ `wc -w <<< $INSTANCE_STATUSES` -eq $DEIS_NUM_INSTANCES ]; do |
75 | | - if [ $COUNTER -gt $ATTEMPTS ]; then echo "Timed out waiting for instances..." ; exit 1; fi # timeout after 7 1/2 minutes |
| 90 | + if [ $COUNTER -gt $ATTEMPTS ]; |
| 91 | + then echo "Health checks not passed after 10m, giving up" |
| 92 | + echo "Destroying stack $STACK_NAME" |
| 93 | + bailout |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | +
|
76 | 97 | if [ $COUNTER -ne 1 ]; then sleep $SLEEPTIME; fi |
77 | | - echo "Waiting for instances to pass initial health checks..." |
| 98 | + echo "Waiting for instances to pass initial health checks ($(expr 61 - $COUNTER)0s) ..." |
78 | 99 | INSTANCE_STATUSES=$(aws ec2 describe-instance-status \ |
79 | 100 | --filters Name=instance-status.reachability,Values=passed \ |
80 | 101 | --instance-ids $INSTANCE_IDS \ |
|
0 commit comments