|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 | profile="cirunner"
|
4 |
| -runner_vpc_id="vpc-0323d32f82edcdec7" |
| 4 | +runner_vpc_id1="vpc-8bdf97ec" |
| 5 | +runner_vpc_id2="vpc-1176d875" |
5 | 6 | region_opt="--region us-west-2"
|
6 | 7 |
|
7 | 8 | # Get runner status
|
8 |
| -runner1=$(aws ec2 describe-instances --profile $profile --filters Name=tag:Name,Values=[super1] Name=network-interface.vpc-id,Values=[$runner_vpc_id] --query "Reservations[*].Instances[*][InstanceId]" ${region_opt} --output text | xargs) |
9 |
| -runner2=$(aws ec2 describe-instances --profile $profile --filters Name=tag:Name,Values=[super2] Name=network-interface.vpc-id,Values=[$runner_vpc_id] --query "Reservations[*].Instances[*][InstanceId]" ${region_opt} --output text | xargs) |
| 9 | +runner1=$(aws ec2 describe-instances --profile $profile --filters Name=tag:Name,Values=[jenkins] Name=network-interface.vpc-id,Values=[$runner_vpc_id1] --query "Reservations[*].Instances[*][InstanceId]" ${region_opt} --output text | xargs) |
| 10 | +runner2=$(aws ec2 describe-instances --profile $profile --filters Name=tag:Name,Values=[jenkins] Name=network-interface.vpc-id,Values=[$runner_vpc_id2] --query "Reservations[*].Instances[*][InstanceId]" --output text | xargs) |
10 | 11 |
|
11 |
| -# start runner1 |
12 |
| -while true; do |
13 |
| - runner_status=$(aws ec2 describe-instances --profile $profile --instance-ids $runner1 --query "Reservations[*].Instances[*].State.[Name]" ${region_opt} --output text) |
14 |
| - echo 'runner1 - '$runner_status |
15 |
| - if [[ $runner_status = "stopped" ]]; then |
16 |
| - aws ec2 start-instances --profile $profile --instance-ids $runner1 ${region_opt} |
17 |
| - break |
18 |
| - elif [[ $runner_status = "running" ]]; then |
19 |
| - echo 'waiting for runner1 restore' |
20 |
| - sleep 30 |
| 12 | +{ |
| 13 | + while true; do |
21 | 14 | runner_status=$(aws ec2 describe-instances --profile $profile --instance-ids $runner1 --query "Reservations[*].Instances[*].State.[Name]" ${region_opt} --output text)
|
22 |
| - if [[ $runner_status = "running" ]]; then |
| 15 | + echo 'runner1 - '$runner_status |
| 16 | + if [[ $runner_status = "stopped" ]]; then |
| 17 | + aws ec2 start-instances --profile $profile --instance-ids $runner1 ${region_opt} |
23 | 18 | break
|
| 19 | + elif [[ $runner_status = "running" ]]; then |
| 20 | + echo 'waiting for runner1 restore' |
| 21 | + sleep 30 |
| 22 | + runner_status=$(aws ec2 describe-instances --profile $profile --instance-ids $runner1 --query "Reservations[*].Instances[*].State.[Name]" ${region_opt} --output text) |
| 23 | + if [[ $runner_status = "running" ]]; then |
| 24 | + break |
| 25 | + fi |
| 26 | + else |
| 27 | + sleep 30 |
24 | 28 | fi
|
25 |
| - else |
26 |
| - sleep 30 |
27 |
| - fi |
28 |
| -done |
29 |
| - |
30 |
| -# start runner2 |
| 29 | + done |
| 30 | +}& |
31 | 31 | while true; do
|
32 |
| - runner_status=$(aws ec2 describe-instances --profile $profile --instance-ids $runner2 --query "Reservations[*].Instances[*].State.[Name]" ${region_opt} --output text) |
| 32 | + runner_status=$(aws ec2 describe-instances --profile $profile --instance-ids $runner2 --query "Reservations[*].Instances[*].State.[Name]" --output text) |
33 | 33 | echo 'runner2 - '$runner_status
|
34 | 34 | if [[ $runner_status = "stopped" ]]; then
|
35 |
| - aws ec2 start-instances --profile $profile --instance-ids $runner2 ${region_opt} |
| 35 | + aws ec2 start-instances --profile $profile --instance-ids $runner2 |
36 | 36 | break
|
37 | 37 | elif [[ $runner_status = "running" ]]; then
|
38 | 38 | echo 'waiting for runner2 restore'
|
39 | 39 | sleep 30
|
40 |
| - runner_status=$(aws ec2 describe-instances --profile $profile --instance-ids $runner2 --query "Reservations[*].Instances[*].State.[Name]" ${region_opt} --output text) |
| 40 | + runner_status=$(aws ec2 describe-instances --profile $profile --instance-ids $runner2 --query "Reservations[*].Instances[*].State.[Name]" --output text) |
41 | 41 | if [[ $runner_status = "running" ]]; then
|
42 | 42 | break
|
43 | 43 | fi
|
44 | 44 | else
|
45 | 45 | sleep 30
|
46 | 46 | fi
|
47 | 47 | done
|
| 48 | + |
| 49 | +exit 0 |
0 commit comments