|
5 | 5 |
|
6 | 6 | if [ -z "$1" ] |
7 | 7 | then |
8 | | - NAME=deis |
| 8 | + STACK_NAME=deis |
9 | 9 | else |
10 | | - NAME=$1 |
| 10 | + STACK_NAME=$1 |
11 | 11 | fi |
12 | 12 |
|
13 | 13 | set -e |
@@ -41,8 +41,60 @@ $CONTRIB_DIR/util/check-user-data.sh |
41 | 41 | # create an EC2 cloudformation stack based on CoreOS's default template |
42 | 42 | aws cloudformation create-stack \ |
43 | 43 | --template-body "$($THIS_DIR/gen-json.py)" \ |
44 | | - --stack-name $NAME \ |
| 44 | + --stack-name $STACK_NAME \ |
45 | 45 | --parameters "$(<$THIS_DIR/cloudformation.json)" |
46 | 46 |
|
47 | | -echo_green "Your Deis cluster has been successfully deployed to AWS CloudFormation and is currently starting." |
| 47 | +# loop until the instances are created |
| 48 | +ATTEMPTS=45 |
| 49 | +SLEEPTIME=10 |
| 50 | +COUNTER=1 |
| 51 | +INSTANCE_IDS="" |
| 52 | +until [ `wc -w <<< $INSTANCE_IDS` -eq $DEIS_NUM_INSTANCES ]; do |
| 53 | + if [ $COUNTER -gt $ATTEMPTS ]; then exit 1; fi # timeout after 7 1/2 minutes |
| 54 | + if [ $COUNTER -ne 1 ]; then sleep $SLEEPTIME; fi |
| 55 | + echo "Waiting for instances to be created..." |
| 56 | + INSTANCE_IDS=$(aws ec2 describe-instances \ |
| 57 | + --filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \ |
| 58 | + --query 'Reservations[].Instances[].[ InstanceId ]' \ |
| 59 | + --output text) |
| 60 | + let COUNTER=COUNTER+1 |
| 61 | +done |
| 62 | +
|
| 63 | +# loop until the instances pass health checks |
| 64 | +COUNTER=1 |
| 65 | +INSTANCE_STATUSES="" |
| 66 | +until [ `wc -w <<< $INSTANCE_STATUSES` -eq $DEIS_NUM_INSTANCES ]; do |
| 67 | + if [ $COUNTER -gt $ATTEMPTS ]; then exit 1; fi # timeout after 7 1/2 minutes |
| 68 | + if [ $COUNTER -ne 1 ]; then sleep $SLEEPTIME; fi |
| 69 | + echo "Waiting for instances to pass initial health checks..." |
| 70 | + INSTANCE_STATUSES=$(aws ec2 describe-instance-status \ |
| 71 | + --filters Name=instance-status.reachability,Values=passed \ |
| 72 | + --instance-ids $INSTANCE_IDS \ |
| 73 | + --query 'InstanceStatuses[].[ InstanceId ]' \ |
| 74 | + --output text) |
| 75 | + let COUNTER=COUNTER+1 |
| 76 | +done |
| 77 | +
|
| 78 | +# print instance info |
| 79 | +echo "Instances are available:" |
| 80 | +aws ec2 describe-instances \ |
| 81 | + --filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \ |
| 82 | + --query 'Reservations[].Instances[].[InstanceId,PublicIpAddress,InstanceType,Placement.AvailabilityZone,State.Name]' \ |
| 83 | + --output text |
| 84 | +
|
| 85 | +# get ELB public DNS name through cloudformation |
| 86 | +# TODO: is "first output value" going to be reliable enough? |
| 87 | +export ELB_DNS_NAME=$(aws cloudformation describe-stacks \ |
| 88 | + --stack-name $STACK_NAME \ |
| 89 | + --max-items 1 \ |
| 90 | + --query 'Stacks[].[ Outputs[0].[ OutputValue ] ]' \ |
| 91 | + --output=text) |
| 92 | +
|
| 93 | +# get ELB friendly name through aws elb |
| 94 | +ELB_NAME=$(aws elb describe-load-balancers \ |
| 95 | + --query 'LoadBalancerDescriptions[].[ DNSName,LoadBalancerName ]' \ |
| 96 | + --output=text | grep -F $ELB_DNS_NAME | head -n1 | cut -f2) |
| 97 | +echo "Using ELB $ELB_NAME at $ELB_DNS_NAME" |
| 98 | +
|
| 99 | +echo_green "Your Deis cluster has been successfully deployed to AWS CloudFormation and is started." |
48 | 100 | echo_green "Please continue to follow the instructions in the documentation." |
0 commit comments