-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwait-for-environment.sh
More file actions
executable file
·86 lines (74 loc) · 2.14 KB
/
wait-for-environment.sh
File metadata and controls
executable file
·86 lines (74 loc) · 2.14 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
debug=no
debug() {
if [ "$debug" == "yes" ]
then
echo $1
fi
}
info=yes
info() {
if [ "$info" == "yes" ]
then
echo $1
fi
}
[ -z "$1" ] && echo "Usage: $0 <environment>" && exit 1
if [ -n "$2" ]
then
branch=$2
else
branch=master
fi
pushd $(dirname $0)/../.. &>/dev/null && BASE_DIR=$(pwd) && popd &>/dev/null
environment=$1
interval=1
found="no"
while [ "$found" == "no" ]
do
debug "sleeping for $interval seconds..."
sleep $interval
# pull git repo
pushd $BASE_DIR &>/dev/null
git reset --hard &>/dev/null
git clean -df &>/dev/null
git checkout $branch &>/dev/null
git pull origin $branch &>/dev/null
popd &>/dev/null
found="yes" # be optimistic
for ip_file in $( find $BASE_DIR/state/$environment -name public-ipv4 )
do
instance=$(echo $ip_file | sed 's/.*\/\([^\/]*\)\/meta-data\/.*/\1/g')
if [[ $instance == i-* ]]
then
node=$(echo $ip_file | sed 's/.*\/\([^\/]*\)\/i-[^\/].*/\1/g')
instance_commit=$(cat $BASE_DIR/state/$environment/$node/$instance/commit 2>/dev/null)
[ "$instance_commit" == "" ] && instance_commit="unset"
else
node=$(echo $ip_file | sed 's/.*\/\([^\/]*\)\/meta-data\/.*/\1/g')
instance_commit=$(cat $BASE_DIR/state/$environment/$node/commit 2>/dev/null)
[ "$instance_commit" == "" ] && instance_commit="unset"
fi
ip=$(cat $ip_file)
environment_commit=$(cat $BASE_DIR/state/$environment/commit 2>/dev/null)
debug "$node has commit: \"$instance_commit\""
if [ "$environment_commit" != "$instance_commit" ]
then
debug "$node is a suspect with \"$instance_commit\" not equal to \"$environment_commit\""
if ping -q -w 4 -c 1 $ip &>/dev/null
then
# it does not match and the server is alive, so it is not yet ok
debug "$node is alive and does not match, so we will continue waiting"
info "waiting for $node..."
found="no"
break
else
debug "but $node is not alive, so we are not going to worry about the discrepancy"
fi
else
debug "$node looks good, will continue"
fi
done #for
let interval=interval+1
done #while
exit 0