From eeb781583acd3761a5cab5e9cf1f48b755125982 Mon Sep 17 00:00:00 2001 From: siozosdr Date: Mon, 24 Jun 2019 20:26:25 +0200 Subject: [PATCH] (MODE-11365) Testing local-exec command. --- deployment/modules/tileserver/autoscaling.tf | 31 ++++++++++++++++++- .../modules/tileserver/files/user-data.sh | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/deployment/modules/tileserver/autoscaling.tf b/deployment/modules/tileserver/autoscaling.tf index 1e1b6d5..956cc82 100644 --- a/deployment/modules/tileserver/autoscaling.tf +++ b/deployment/modules/tileserver/autoscaling.tf @@ -47,7 +47,36 @@ resource "aws_autoscaling_group" "autoscalinggroup" { provisioner "local-exec" { # Wait until the number of "ok" instance status checks is equal to 1 - command = "sleep 15; i=0; while [[ $(/usr/bin/aws ec2 describe-instances --filters 'Name=tag:aws:autoscaling:groupName,Values=${aws_autoscaling_group.autoscalinggroup.name}' --query 'Reservations[*].Instances[*].InstanceId' --output text | xargs aws ec2 describe-instance-status --query 'InstanceStatuses[*].SystemStatus.Status' --instance-ids | jq 'map(select(. == \"ok\")) | length') -lt 1 ]]; do i=$(echo $((++i))); echo ''; echo retrying $i; sleep 5;if [[ $i -eq 60 ]]; then exit 1; fi; done; sleep 45" + command = "sleep 15; \ + expected=2; \ + current=0; \ + retries=0; \ + instances=$(aws autoscaling describe-auto-scaling-groups \ + --auto-scaling-group-name "${aws_autoscaling_group.autoscalinggroup.name}" \ + --query 'AutoScalingGroups[*].Instances[*].InstanceId' --output text); \ + while [ "$current" -lt "$expected" ]; do \ + for i in $(echo $instances); do \ + check=$(aws elbv2 describe-target-health \ + --target-group-arn "${aws_alb_target_group.target_group_this.arn}" \ + --query "TargetHealthDescriptions[?Target.Id == '$i'].TargetHealth.State" --output text); \ + echo "$check"; \ + if [[ "$check" -eq "healthy" ]]; then \ + current="$(echo $((++current)))"; \ + else \ + current="$(echo $((--current)))"; \ + fi \ + done; \ + if [[ "$($current)" -eq "$expected" ]]; then \ + break; \ + else \ + current="0"; + retries="$((++retries))" + fi; \ + if [[ "$retries" -eq "3" ]]; then \ + break;\ + fi + done + " } } diff --git a/deployment/modules/tileserver/files/user-data.sh b/deployment/modules/tileserver/files/user-data.sh index 7da0ebf..e364b73 100644 --- a/deployment/modules/tileserver/files/user-data.sh +++ b/deployment/modules/tileserver/files/user-data.sh @@ -12,6 +12,7 @@ DEPLOYABLE="tileserver-gl-$REPO_VERSION.tar.gz" FULL_BUCKET_URI="s3://$BUCKET/tileserver-gl/$DEPLOYABLE" DATA_VERSION="2019-05-20" # Setup dependencies +sudo service nginx stop sudo rm /var/lib/dpkg/lock curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt install -y apt-transport-https \