|
8 | 8 |
|
9 | 9 | set -e
|
10 | 10 |
|
11 |
| -TARGET_GROUP_NAME="<%= @target_group_name %>" |
| 11 | +TARGET_GROUP_NAMES=<%= @target_group_names %> |
12 | 12 | REGION="<%= @region %>"
|
13 | 13 |
|
14 |
| -# Get Target Group ARN |
15 |
| -target_group_arn=$(aws elbv2 describe-target-groups \ |
16 |
| - --names ${TARGET_GROUP_NAME} \ |
17 |
| - --query "TargetGroups[0].TargetGroupArn" \ |
18 |
| - --output text \ |
19 |
| - --region ${REGION}) |
20 |
| - |
21 |
| -# Exit if Target Group is not found |
22 |
| -if [[ -n "${target_group_arn}" ]]; then |
23 |
| - echo "TargetGroup ARN found: ${target_group_arn}" |
24 |
| -else |
25 |
| - echo "No Target Group found for the specified Load Balancer ${load_balancer_arn}." |
26 |
| - exit 1 |
27 |
| -fi |
28 |
| - |
29 |
| -# Get the number of healthy and unhealthy targets |
30 |
| -target_healths=$(aws elbv2 describe-target-health \ |
31 |
| - --target-group-arn $target_group_arn \ |
32 |
| - --region ${REGION}) |
33 |
| - |
34 |
| -healthy_count=$(echo $target_healths | jq -r '.TargetHealthDescriptions[] | select(.TargetHealth.State == "healthy") | .Target.Id' | wc -l) |
35 |
| -unhealthy_count=$(echo $target_healths | jq -r '.TargetHealthDescriptions[] | select(.TargetHealth.State != "healthy") | .Target.Id' | wc -l) |
36 |
| - |
37 |
| -# Check if there are running login nodes |
38 |
| -total_nodes=$((healthy_count + unhealthy_count)) |
39 |
| -if [[ $total_nodes -gt 0 ]]; then |
40 |
| - echo "Login nodes are running. Please stop them before updating the munge key." |
41 |
| - exit 1 |
42 |
| -fi |
| 14 | +for TARGET_GROUP_NAME in ${TARGET_GROUP_NAMES[@]}; do |
| 15 | + # Get Target Group ARN |
| 16 | + target_group_arn=$(aws elbv2 describe-target-groups \ |
| 17 | + --names ${TARGET_GROUP_NAME} \ |
| 18 | + --query "TargetGroups[0].TargetGroupArn" \ |
| 19 | + --output text \ |
| 20 | + --region ${REGION}) |
| 21 | + |
| 22 | + # Exit if Target Group is not found |
| 23 | + if [[ -n "${target_group_arn}" ]]; then |
| 24 | + echo "TargetGroup ARN found: ${target_group_arn}" |
| 25 | + else |
| 26 | + echo "No Target Group found for the specified Load Balancer ${load_balancer_arn}." |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | + |
| 30 | + # Get the number of healthy and unhealthy targets |
| 31 | + target_healths=$(aws elbv2 describe-target-health \ |
| 32 | + --target-group-arn $target_group_arn \ |
| 33 | + --region ${REGION}) |
| 34 | + |
| 35 | + healthy_count=$(echo $target_healths | jq -r '.TargetHealthDescriptions[] | select(.TargetHealth.State == "healthy") | .Target.Id' | wc -l) |
| 36 | + unhealthy_count=$(echo $target_healths | jq -r '.TargetHealthDescriptions[] | select(.TargetHealth.State != "healthy") | .Target.Id' | wc -l) |
| 37 | + |
| 38 | + # Check if there are running login nodes |
| 39 | + total_nodes=$((healthy_count + unhealthy_count)) |
| 40 | + if [[ $total_nodes -gt 0 ]]; then |
| 41 | + echo "Login nodes are running. Please stop them before updating the munge key." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +done |
43 | 45 |
|
44 | 46 | echo "Login nodes are stopped."
|
45 | 47 | exit 0
|
0 commit comments