forked from openedx-unsupported/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.sh
executable file
·170 lines (148 loc) · 5.19 KB
/
check.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
# Run checks for the provided service(s).
# To specify multiple services, separate them with spaces or plus signs (+).
# To specify all services, just pass in "all".
#
# Examples:
# ./check.sh lms
# ./check.sh lms+forum
# ./check.sh lms+forum discovery
# ./check.sh all
#
# Exists 0 if successful; non-zero otherwise.
#
# Fails if no services specified.
#
# Note that passing in a non-existent service will not fail if there are
# other successful checks.
set -eu -o pipefail
# Grab all arguments into one string, replacing plus signs with spaces.
# Pad on either side with spaces so that the regex in `should_check` works correctly.
services=" ${*//+/ } "
# Which checks succeeded and failed.
succeeded=""
failed=""
# Returns whether service in first arg should be checked.
should_check() {
local service="$1"
if [[ "$services" == *" all "* ]] || [[ "$services" == *" $service "* ]]; then
return 0 # Note that '0' means 'success' (i.e., true) in bash.
else
return 1
fi
}
# Runs a check named $1 on service $2 using the command $3.
run_check() {
local check_name="$1"
local service="$2"
local cmd="$3"
echo "> $cmd"
set +e # Disable exit-on-error
if bash -c "$cmd"; then # Run the command itself and check if it succeeded.
succeeded="$succeeded $check_name"
else
docker compose logs --tail 500 "$service" # Just show recent logs, not all history
failed="$failed $check_name"
fi
set -e # Re-enable exit-on-error
echo # Newline
}
mysql_run_check() {
container_name="$1"
mysql_probe="SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')"
# The use of `--protocol tcp` forces MySQL to connect over TCP rather than
# via a UNIX socket. This is needed because when MySQL starts for the first
# time in a new container, it starts a "temporary server" that runs for a
# few seconds and then shuts down before the "real" server starts up. The
# temporary server does not listen on the TCP port, but if the mysql
# command is not told which server to use, it will first try the UNIX
# socket and only after that will it try the default TCP port.
#
# By specifying that mysql should use TCP, we won't get an early false
# positive "ready" response while the temporary server is running.
run_check "${container_name}_query" "$container_name" \
"docker compose exec -T $(printf %q "$container_name") mysql --protocol tcp -uroot -se $(printf %q "$mysql_probe")"
}
if should_check mysql57; then
echo "Checking MySQL 5.7 query endpoint:"
mysql_run_check mysql57
fi
if should_check mysql80; then
echo "Checking MySQL 8.0 query endpoint:"
mysql_run_check mysql80
fi
if should_check mongo; then
echo "Checking MongoDB status:"
run_check mongo_status mongo \
"docker compose exec -T mongo mongo --eval \"db.serverStatus()\""
fi
if should_check registrar; then
echo "Checking Registrar heartbeat:"
run_check registrar_heartbeat registrar \
"curl --fail -L http://localhost:18734/health"
fi
if should_check lms; then
echo "Checking LMS heartbeat:"
run_check lms_heartbeat lms \
"curl --fail -L http://localhost:18000/heartbeat"
echo "Validating LMS volume:"
run_check lms_volume lms \
"make validate-lms-volume"
fi
if should_check cms; then
echo "Checking CMS heartbeat:"
run_check cms_heartbeat cms \
"curl --fail -L http://localhost:18010/heartbeat"
fi
if should_check ecommerce; then
echo "Checking ecommerce health:"
run_check ecommerce_heartbeat ecommerce \
"curl --fail -L http://localhost:18130/health/"
fi
if should_check discovery; then
echo "Checking discovery health:"
run_check discovery_heartbeat discovery \
"curl --fail -L http://localhost:18381/health/"
fi
if should_check forum; then
echo "Checking forum heartbeat:"
run_check forum_heartbeat forum \
"curl --fail -L http://localhost:44567/heartbeat"
fi
if should_check edx_notes_api; then
echo "Checking edx_notes_api heartbeat:"
run_check edx_notes_api_heartbeat edx_notes_api \
"curl --fail -L http://localhost:18120/heartbeat"
fi
if should_check credentials; then
echo "Checking credentials heartbeat:"
run_check credentials_heartbeat credentials \
"curl --fail -L http://localhost:18150/health"
fi
if should_check xqueue; then
echo "Checking xqueue status:"
run_check xqueue_heartbeat xqueue \
"curl --fail -L http://localhost:18040/xqueue/status"
fi
if should_check insights; then
echo "Running Analytics Dashboard Devstack tests: "
run_check insights_heartbeat insights \
"curl --fail -L http://localhost:18110/health/"
fi
if should_check analyticsapi; then
echo "Running Analytics Data API Devstack tests: "
run_check analyticsapi_heartbeat analyticsapi \
"curl --fail -L http://localhost:19001/health/"
fi
echo "Successful checks:${succeeded:- NONE}"
echo "Failed checks:${failed:- NONE}"
if [[ -z "$succeeded" ]] && [[ -z "$failed" ]]; then
echo "No checks ran. Exiting as failure."
exit 1
elif [[ -z "$failed" ]]; then
echo "Check result: SUCCESS"
exit 0
else
echo "Check result: FAILURE"
exit 2
fi