-
Notifications
You must be signed in to change notification settings - Fork 342
/
docker-healthcheck.sh
executable file
·171 lines (152 loc) · 4.47 KB
/
docker-healthcheck.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
171
#!/bin/bash
# shellcheck disable=SC2154
if [[ ${healthcheck} != "true" ]]; then
exit 0
fi
dt () {
date +%FT%T.%3N
}
logger () {
# shellcheck disable=SC2154
if [[ ${log_to_file} != 'true' ]]; then
echo "$1" >> /proc/1/fd/1
else
echo "$1" >> "${CHIA_ROOT}/log/debug.log"
fi
}
# Set default to false for all components
# Gets reset to true individually depending on ${service} variable
node_check=false
farmer_check=false
harvester_check=false
wallet_check=false
timelord_check=false
crawler_check=false
# Determine which services to healthcheck based on ${service}
# shellcheck disable=SC2154,SC2206
services_array=($service)
for option in "${services_array[@]}"
do
case "${option}" in
all)
node_check=true
farmer_check=true
harvester_check=true
wallet_check=true
timelord_check=true
crawler_check=true
;;
node)
node_check=true
;;
harvester)
harvester_check=true
;;
farmer)
node_check=true
farmer_check=true
harvester_check=true
wallet_check=true
;;
farmer-no-wallet)
node_check=true
farmer_check=true
harvester_check=true
;;
farmer-only)
farmer_check=true
;;
timelord)
timelord_check=true
;;
timelord-only)
timelord_check=true
;;
crawler)
crawler_check=true
;;
seeder)
crawler_check=true
;;
wallet)
wallet_check=true
;;
esac
done
# Always check the daemon
nc -z -v -w1 localhost 55400
# shellcheck disable=SC2181
if [[ "$?" -ne 0 ]]; then
logger "$(dt) Daemon healthcheck failed"
exit 1
fi
if [[ ${node_check} == "true" ]]; then
curl -X POST --fail \
--cert "${CHIA_ROOT}/config/ssl/full_node/private_full_node.crt" \
--key "${CHIA_ROOT}/config/ssl/full_node/private_full_node.key" \
-d '{}' -k -H "Content-Type: application/json" https://localhost:8555/healthz
# shellcheck disable=SC2181
if [[ "$?" -ne 0 ]]; then
logger "$(dt) Node healthcheck failed"
exit 1
fi
fi
if [[ ${farmer_check} == "true" ]]; then
curl -X POST --fail \
--cert "${CHIA_ROOT}/config/ssl/farmer/private_farmer.crt" \
--key "${CHIA_ROOT}/config/ssl/farmer/private_farmer.key" \
-d '{}' -k -H "Content-Type: application/json" https://localhost:8559/healthz
# shellcheck disable=SC2181
if [[ "$?" -ne 0 ]]; then
logger "$(dt) Farmer healthcheck failed"
exit 1
fi
fi
if [[ ${harvester_check} == "true" ]]; then
curl -X POST --fail \
--cert "${CHIA_ROOT}/config/ssl/harvester/private_harvester.crt" \
--key "${CHIA_ROOT}/config/ssl/harvester/private_harvester.key" \
-d '{}' -k -H "Content-Type: application/json" https://localhost:8560/healthz
# shellcheck disable=SC2181
if [[ "$?" -ne 0 ]]; then
logger "$(dt) Harvester healthcheck failed"
exit 1
fi
fi
if [[ ${timelord_check} == "true" ]]; then
curl -X POST --fail \
--cert "${CHIA_ROOT}/config/ssl/timelord/private_timelord.crt" \
--key "${CHIA_ROOT}/config/ssl/timelord/private_timelord.key" \
-d '{}' -k -H "Content-Type: application/json" https://localhost:8557/healthz
# shellcheck disable=SC2181
if [[ "$?" -ne 0 ]]; then
logger "$(dt) Timelord healthcheck failed"
exit 1
fi
fi
if [[ ${crawler_check} == "true" ]]; then
curl -X POST --fail \
--cert "${CHIA_ROOT}/config/ssl/crawler/private_crawler.crt" \
--key "${CHIA_ROOT}/config/ssl/crawler/private_crawler.key" \
-d '{}' -k -H "Content-Type: application/json" https://localhost:8561/healthz
# shellcheck disable=SC2181
if [[ "$?" -ne 0 ]]; then
logger "$(dt) Crawler healthcheck failed"
exit 1
fi
fi
if [[ ${wallet_check} == "true" ]]; then
curl -X POST --fail \
--cert "${CHIA_ROOT}/config/ssl/wallet/private_wallet.crt" \
--key "${CHIA_ROOT}/config/ssl/wallet/private_wallet.key" \
-d '{}' -k -H "Content-Type: application/json" https://localhost:9256/healthz
# shellcheck disable=SC2181
if [[ "$?" -ne 0 ]]; then
logger "$(dt) Wallet healthcheck failed"
exit 1
fi
fi
# shellcheck disable=SC2154
if [[ ${log_level} == 'INFO' ]]; then
logger "$(dt) Healthcheck(s) completed successfully"
fi