forked from openedx-unsupported/devstack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.sh
executable file
·122 lines (106 loc) · 3.28 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
#!/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 -e
set -o pipefail
set -u
# 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 $cmd; then # Run the command itself and check if it succeeded.
succeeded="$succeeded $check_name"
else
docker-compose logs "$service"
failed="$failed $check_name"
fi
set -e # Re-enable exit-on-error
echo # Newline
}
if should_check registrar; then
echo "Checking Registrar heartbeat:"
run_check registrar_heartbeat registrar \
"curl --fail -L http://localhost:18734/heartbeat"
fi
if should_check lms; then
echo "Checking LMS heartbeat:"
run_check lms_heartbeat lms \
"curl --fail -L http://localhost:18000/heartbeat"
echo "Checking Studio heartbeat:"
run_check studio_heartbeat lms \
"curl --fail -L http://localhost:18010/heartbeat"
echo "Validating LMS volume:"
run_check lms_volume lms \
"make validate-lms-volume"
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
echo "Successful checks:${succeeded:- NONE}"
echo "Failed checks:${failed:- NONE}"
if [[ "$succeeded" ]]; then
echo "Check result: SUCCESS"
exit 0
else
echo "Check result: FAILURE"
exit 2
fi