-
Notifications
You must be signed in to change notification settings - Fork 4
/
watchForInstancesStop.sh
executable file
·50 lines (40 loc) · 1.09 KB
/
watchForInstancesStop.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Awaits once instances fully stop with 8 minuts timeout.
# Load values of
# STOCKHOLM_VANILLA_INSTANCE_ID & FRANKFURT_VANILLA_INSTANCE_ID
[[ -f "VANILLA_IDS.txt" ]] &&
source "VANILLA_IDS.txt" ||
exit 1
TIMEOUT=480 # 8 minues
CZECH_INTERVAL=2
main(){
watchState
}
watchState(){
while true
do
czechInstancesState
sleep ${CZECH_INTERVAL}
done
}
czechInstancesState(){
local COLOR_GREEN=$'\e[1;32m'
local RESET_COLOR=$'\e[0m'
STOCKHOLM_STATE=`aws ec2 describe-instances \
--region "eu-north-1" \
--query "Reservations[*].Instances[*].[State.Name]" \
--filters "Name=instance-state-code,Values=80" \
--o text`
FRANKFURT_STATE=`aws ec2 describe-instances \
--region "eu-central-1" \
--query "Reservations[*].Instances[*].[State.Name]" \
--filters "Name=instance-state-code,Values=80" \
--o text`
[[ ${STOCKHOLM_STATE} == "stopped" ]] && \
[[ ${FRANKFURT_STATE} == "stopped" ]] && \
exit 0
(( TIMEOUT=TIMEOUT-CZECH_INTERVAL ))
(( TIMEOUT <= 0 )) && exit 1
echo -e "${COLOR_GREEN} waiting once instances stop...${RESET_COLOR}"
}
./checkAWS.sh && main || ./awsCliNa.sh