forked from quarkusio/quarkus-super-heroes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch-services.sh
executable file
·155 lines (129 loc) · 3.75 KB
/
watch-services.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash -e
# 0 - event-statistics
# 1 - villains
# 2 - heroes
# 3 - fights
# 4 - ui
# 5 - apicurio
# 6 - rest-narration
# 7 - locations-service
statuses=("0", "0", "0", "0", "0", "0", "0", "0")
max_tries=100
tries=1
interval=2
# Display help
help() {
echo "This script watches the services started by Docker Compose and reports when all services are up."
echo
echo "Syntax: watch-services.sh [options]"
echo "options:"
echo " -h Prints this help message"
echo " -i <interval_between_tries> The interval in seconds between tries. Default is 2."
echo " -m <max_tries> The number of times to retry to see if the services are up. Default is 100."
}
exit_abnormal() {
echo
help
exit 1
}
get_status() {
local port=$1
local index=$2
local path=$3
case "$index" in
0) local service_name="event-statistics" ;;
1) local service_name="rest-villains" ;;
2) local service_name="rest-heroes" ;;
3) local service_name="rest-fights" ;;
4) local service_name="ui-super-heroes" ;;
5) local service_name="apicurio" ;;
6) local service_name="rest-narration" ;;
7) local service_name="grpc-locations" ;;
esac
local url="http:https://localhost:${port}${path}"
local command="curl -s -o /dev/null -w \"%{http_code}\" $url"
local result=$($command)
echo "Pinging $service_name: $url"
# echo "result of \"$command\"=\"$result\""
statuses[$index]=$result
}
get_statuses() {
if [[ "${statuses[0]}" != "\"200\"" ]]; then
get_status 8085 0 "/q/health/ready"
fi
if [[ "${statuses[1]}" != "\"200\"" ]]; then
get_status 8084 1 "/q/health/ready"
fi
if [[ "${statuses[2]}" != "\"200\"" ]]; then
get_status 8083 2 "/q/health/ready"
fi
if [[ "${statuses[3]}" != "\"200\"" ]]; then
get_status 8082 3 "/q/health/ready"
fi
if [[ "${statuses[4]}" != "\"200\"" ]]; then
get_status 8080 4 "/q/health/ready"
fi
if [[ "${statuses[5]}" != "\"200\"" ]]; then
get_status 8086 5 "/health/ready"
fi
if [[ "${statuses[6]}" != "\"200\"" ]]; then
get_status 8087 6 "/q/health/ready"
fi
if [[ "${statuses[7]}" != "\"200\"" ]]; then
get_status 8089 7 "/q/health/ready"
fi
}
print_statuses() {
echo "event_stats_status=${statuses[0]}"
echo "villains_status=${statuses[1]}"
echo "heroes_status=${statuses[2]}"
echo "fights_status=${statuses[3]}"
echo "narration_status=${statuses[6]}"
echo "location_status=${statuses[7]}"
echo "ui_status=${statuses[4]}"
echo "apicurio=${statuses[5]}"
}
# Process the input options
while getopts "hi::m::" option; do
case $option in
m) max_tries=$OPTARG
;;
h) help
exit 1
;;
i) interval=$OPTARG
;;
*) exit_abnormal
;;
esac
done
while [[ "${statuses[0]}" != "\"200\"" ]] || [[ "${statuses[1]}" != "\"200\"" ]] || [[ "${statuses[2]}" != "\"200\"" ]] || [[ "${statuses[3]}" != "\"200\"" ]] || [[ "${statuses[4]}" != "\"200\"" ]] || [[ "${statuses[5]}" != "\"200\"" ]] || [[ "${statuses[6]}" != "\"200\"" ]] || [[ "${statuses[7]}" != "\"200\"" ]]
do
if [[ "$tries" -gt $max_tries ]]; then
break
fi
echo ""
echo "-----------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Try #$tries"
echo "-----------------------------------"
get_statuses
# print_statuses
((tries++))
sleep $interval
done
echo ""
if [[ "$tries" -gt $max_tries ]]; then
echo "Not all services started within $max_tries tries!!!!!!!"
print_statuses
exit 1
else
echo "All services are now up :)"
echo "Super Heroes UI: http:https://localhost:8080"
echo "Event stats: http:https://localhost:8085"
echo "Apicurio Schema Registry: http:https://localhost:8086"
echo
echo "---- Monitoring (if started) ----"
echo "Prometheus: http:https://localhost:9090"
echo "Jaeger: http:https://localhost:16686"
fi
exit 0