-
-
Notifications
You must be signed in to change notification settings - Fork 453
/
troubleshoot_server.sh
372 lines (306 loc) · 12.5 KB
/
troubleshoot_server.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/usr/bin/env bash
# Tactical RMM install troubleshooting script
# Contributed by https://github.com/dinger1986
# v1.1 1/21/2022 update to include all services
# v 1.2 6/24/2023 changed to add date, easier readability and ipv4 addresses only for checks
# v 1.3 6/24/2024 Adding resolvconf helper
# This script asks for the 3 subdomains, checks they exist, checks they resolve locally and remotely (using google dns for remote),
# checks services are running, checks ports are opened. The only part that will make the script stop is if the sub domains dont exist, theres literally no point in going further if thats the case
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# Function to check if a resolvconf is installed
command_exists() {
command -v "$1" &> /dev/null
}
# Check if resolvconf command is available
if ! command_exists resolvconf; then
echo -e "${RED}Error: resolvconf command not found.${NC}"
echo -e "${YELLOW}Please install it using: ${NC}sudo apt install resolvconf"
exit 1
fi
# Set date at the top of the troubleshooting script
now=$(date)
echo -e -------------- $now -------------- | tee -a checklog.log
osname=$(lsb_release -si)
osname=${osname^}
osname=$(echo "$osname" | tr '[A-Z]' '[a-z]')
relno=$(lsb_release -sr | cut -d. -f1)
# Resolve Locally used DNS server
resolvestatus=$(systemctl is-active systemd-resolved.service)
if [[ "$osname" == "debian" && "$relno" == 12 ]]; then
locdns=$(resolvconf -l | tail -n +1 | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
elif [ $resolvestatus = active ]; then
locdns=$(resolvectl | tail -n +1 | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
else
while ! [[ $resolveconf ]]; do
resolveconf=$(sudo systemctl status systemd-resolved.service | grep "Active: active (running)")
sudo systemctl start systemd-resolved.service
echo -ne "DNS Resolver not ready yet...${NC}\n"
sleep 3
done
locdns=$(resolvectl | tail -n +1 | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
sudo systemctl stop systemd-resolved.service
fi
while [[ $rmmdomain != *[.]*[.]* ]]; do
echo -e "${YELLOW}Enter the subdomain for the backend (e.g. api.example.com)${NC}: "
read rmmdomain
done
if ping -c 1 $rmmdomain &>/dev/null; then
echo -e ${GREEN} Verified $rmmdomain | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} $rmmdomain doesnt exist please create it or check for a typo | tee -a checklog.log
printf >&2 "\n\n"
printf >&2 "You will have a log file called checklog.log in the directory you ran this script from\n\n"
printf >&2 "\n\n"
exit
fi
while [[ $frontenddomain != *[.]*[.]* ]]; do
echo -e "${YELLOW}Enter the subdomain for the frontend (e.g. rmm.example.com)${NC}: "
read frontenddomain
done
if ping -c 1 $frontenddomain &>/dev/null; then
echo -e ${GREEN} Verified $frontenddomain | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} $frontenddomain doesnt exist please create it or check for a typo | tee -a checklog.log
printf >&2 "\n\n"
printf >&2 "You will have a log file called checklog.log in the directory you ran this script from\n\n"
printf >&2 "\n\n"
exit
fi
while [[ $meshdomain != *[.]*[.]* ]]; do
echo -e "${YELLOW}Enter the subdomain for meshcentral (e.g. mesh.example.com)${NC}: "
read meshdomain
done
if ping -c 1 $meshdomain &>/dev/null; then
echo -e ${GREEN} Verified $meshdomain | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} $meshdomain doesnt exist please create it or check for a typo | tee -a checklog.log
printf >&2 "\n\n" | tee -a checklog.log
printf >&2 "You will have a log file called checklog.log in the directory you ran this script from\n\n"
printf >&2 "\n\n"
exit
fi
while [[ $domain != *[.]* ]]; do
echo -e "${YELLOW}Enter yourdomain used for letsencrypt (e.g. example.com)${NC}: "
read domain
done
echo -e ${YELLOW} Checking IPs | tee -a checklog.log
printf >&2 "\n\n"
# Check rmmdomain IPs
locapiip=$(dig @"$locdns" +short $rmmdomain | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
remapiip=$(dig @8.8.8.8 +short $rmmdomain | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
if [ "$locapiip" = "$remapiip" ]; then
echo -e ${GREEN} Success $rmmdomain is Locally Resolved: "$locapiip" Remotely Resolved: "$remapiip" | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} Locally Resolved: "$locapiip" Remotely Resolved: "$remapiip" | tee -a checklog.log
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} Your Local and Remote IP for $rmmdomain all agents will require non-public DNS to find TRMM server | tee -a checklog.log
printf >&2 "\n\n"
fi
# Check Frontenddomain IPs
locrmmip=$(dig @"$locdns" +short $frontenddomain | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
remrmmip=$(dig @8.8.8.8 +short $frontenddomain | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
if [ "$locrmmip" = "$remrmmip" ]; then
echo -e ${GREEN} Success $frontenddomain is Locally Resolved: "$locrmmip" Remotely Resolved: "$remrmmip" | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} Locally Resolved: "$locrmmip" Remotely Resolved: "$remrmmip" | tee -a checklog.log
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} echo Your Local and Remote IP for $frontenddomain all agents will require non-public DNS to find TRMM server | tee -a checklog.log
printf >&2 "\n\n"
fi
# Check meshdomain IPs
locmeship=$(dig @"$locdns" +short $meshdomain | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
remmeship=$(dig @8.8.8.8 +short $meshdomain | grep -m 1 -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
if [ "$locmeship" = "$remmeship" ]; then
echo -e ${GREEN} Success $meshdomain is Locally Resolved: "$locmeship" Remotely Resolved: "$remmeship" | tee -a checklog.log
printf >&2 "\n\n" | tee -a checklog.log
else
echo -e ${RED} Locally Resolved: "$locmeship" Remotely Resolved: "$remmeship" | tee -a checklog.log
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} Your Local and Remote IP for $meshdomain all agents will require non-public DNS to find TRMM server | tee -a checklog.log
printf >&2 "\n\n" | tee -a checklog.log
fi
echo -e ${YELLOW} Checking Services | tee -a checklog.log
printf >&2 "\n\n"
# Check if services are running
rmmstatus=$(systemctl is-active rmm)
daphnestatus=$(systemctl is-active daphne)
celerystatus=$(systemctl is-active celery)
celerybeatstatus=$(systemctl is-active celerybeat)
nginxstatus=$(systemctl is-active nginx)
natsstatus=$(systemctl is-active nats)
natsapistatus=$(systemctl is-active nats-api)
meshcentralstatus=$(systemctl is-active meshcentral)
mongodstatus=$(systemctl is-active mongod)
postgresqlstatus=$(systemctl is-active postgresql)
redisserverstatus=$(systemctl is-active redis-server)
# RMM Service
if [ $rmmstatus = active ]; then
echo -e ${GREEN} Success RMM Service is Running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'RMM Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# daphne Service
if [ $daphnestatus = active ]; then
echo -e ${GREEN} Success daphne Service is Running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'daphne Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# celery Service
if [ $celerystatus = active ]; then
echo -e ${GREEN} Success celery Service is Running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'celery Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# celerybeat Service
if [ $celerybeatstatus = active ]; then
echo -e ${GREEN} Success celerybeat Service is Running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'celerybeat Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# nginx Service
if [ $nginxstatus = active ]; then
echo -e ${GREEN} Success nginx Service is Running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'nginx Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# nats Service
if [ $natsstatus = active ]; then
echo -e ${GREEN} Success nats Service is running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'nats Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# nats-api Service
if [ $natsapistatus = active ]; then
echo -e ${GREEN} Success nats-api Service is running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'nats-api Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# meshcentral Service
if [ $meshcentralstatus = active ]; then
echo -e ${GREEN} Success meshcentral Service is running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'meshcentral Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# mongod Service
if grep -q mongo "/meshcentral/meshcentral-data/config.json"; then
if [ $mongodstatus = active ]; then
echo -e ${GREEN} Success mongod Service is running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'mongod Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
fi
# postgresql Service
if [ $postgresqlstatus = active ]; then
echo -e ${GREEN} Success postgresql Service is running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'postgresql Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
# redis-server Service
if [ $redisserverstatus = active ]; then
echo -e ${GREEN} Success redis-server Service is running | tee -a checklog.log
printf >&2 "\n\n"
else
printf >&2 "\n\n" | tee -a checklog.log
echo -e ${RED} 'redis-server Service isnt running (Tactical wont work without this)' | tee -a checklog.log
printf >&2 "\n\n"
fi
echo -e ${YELLOW} Checking Open Ports | tee -a checklog.log
printf >&2 "\n\n"
#Get WAN IP
wanip=$(dig @resolver4.opendns.com myip.opendns.com +short)
echo -e ${GREEN} WAN IP is $wanip | tee -a checklog.log
printf >&2 "\n\n"
if ! which nc >/dev/null; then
echo "netcat is not installed, installing now"
sudo apt-get install netcat -y
fi
#Check if HTTPs Port is open
if (nc -zv $wanip 443 2>&1 >/dev/null); then
echo -e ${GREEN} 'HTTPs Port is open' | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} 'HTTPs port is closed (you may want this if running locally only)' | tee -a checklog.log
printf >&2 "\n\n"
fi
echo -e ${YELLOW} Checking For Proxy | tee -a checklog.log
printf >&2 "\n\n"
echo -e ${YELLOW} ......this might take a while!!
printf >&2 "\n\n"
# Detect Proxy via cert
proxyext=$(openssl s_client -showcerts -servername $remapiip -connect $remapiip:443 2>/dev/null | openssl x509 -inform pem -noout -text)
proxyint=$(openssl s_client -showcerts -servername 127.0.0.1 -connect 127.0.0.1:443 2>/dev/null | openssl x509 -inform pem -noout -text)
if [[ $proxyext == $proxyint ]]; then
echo -e ${GREEN} No Proxy detected using Certificate | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} Proxy detected using Certificate | tee -a checklog.log
printf >&2 "\n\n"
fi
# Detect Proxy via IP
if [ $wanip != $remrmmip ]; then
echo -e ${RED} Proxy detected using IP | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${GREEN} No Proxy detected using IP | tee -a checklog.log
printf >&2 "\n\n"
fi
echo -e ${YELLOW} Checking SSL Certificate is up to date | tee -a checklog.log
printf >&2 "\n\n"
#SSL Certificate check
cert=$(sudo certbot certificates)
if [[ "$cert" != *"INVALID"* ]]; then
echo -e ${GREEN} SSL Certificate for $domain is fine | tee -a checklog.log
printf >&2 "\n\n"
else
echo -e ${RED} SSL Certificate has expired or doesnt exist for $domain | tee -a checklog.log
printf >&2 "\n\n"
fi
# Get List of Certbot Certificates
sudo certbot certificates | tee -a checklog.log
echo -e ${YELLOW} Getting summary output of logs | tee -a checklog.log
tail /rmm/api/tacticalrmm/tacticalrmm/private/log/django_debug.log | tee -a checklog.log
printf >&2 "\n\n"
tail /rmm/api/tacticalrmm/tacticalrmm/private/log/error.log | tee -a checklog.log
printf >&2 "\n\n"
printf >&2 "\n\n"
echo -e ${YELLOW}
printf >&2 "You will have a log file called checklog.log in the directory you ran this script from\n\n"
echo -e ${NC}