forked from evanshortiss/quarkus-super-heroes
/
watch-services.sh
executable file
·90 lines (75 loc) · 2.11 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
#!/bin/bash
# 0 - event-statistics
# 1 - villains
# 2 - heroes
# 3 - fights
# 4 - ui
statuses=("0", "0", "0", "0", "0")
max_tries=100
tries=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" ;;
esac
local url="http://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 "/"
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 "ui_status=${statuses[4]}"
}
while [[ "${statuses[0]}" != "\"200\"" ]] || [[ "${statuses[1]}" != "\"200\"" ]] || [[ "${statuses[2]}" != "\"200\"" ]] || [[ "${statuses[3]}" != "\"200\"" ]] || [[ "${statuses[4]}" != "\"200\"" ]]
do
if [[ "$tries" -gt $max_tries ]]; then
break
fi
echo ""
echo "-----------------------------------"
echo "Try #$tries"
echo "-----------------------------------"
get_statuses
# print_statuses
((tries++))
sleep 2
done
echo ""
if [[ "$tries" -gt $max_tries ]]; then
echo "Not all services started within $max_tries tries!!!!!!!"
print_statuses
else
echo "All services are now up :)"
echo "Super Heroes UI: http://localhost:8080"
echo "Event stats: http://localhost:8085"
echo "Prometheus (if started): http://localhost:9090"
fi