-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_check.sh
executable file
·218 lines (148 loc) · 5.32 KB
/
health_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
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
#!/bin/sh
###########################################################################################################
#
# Script Name: health_check.sh
#
# Description: This script queries if the following services are running: Syncthing, Folding@Home, Firewall
#
###########################################################################################################
# Clear screen for consumption
clear
# Variables
email=$(cat /home/git/scripts/email.txt)
# Confirm user is running as root
if [ `whoami` != 'root' ]
then
echo "You must be root to run this script. This script will now exit."
exit
fi
# Clear screen for consumption
clear
# Prompt that health check script is running
echo ""
echo "################################"
echo "# #"
echo "# Starting System Health Check #"
echo "# #"
echo "################################"
# Prompt user that script is checking Syncthing service status
echo ""
echo ""
echo "Checking Syncthing service status..."
# Check if Syncthing service is running
syncthing_status=$(systemctl status syncthing@syncthing | grep Active)
syncthing_status_logic=$(systemctl status syncthing@syncthing | grep running | wc -l)
echo ""
echo "Syncthing status:" $syncthing_status
echo ""
if [ "$syncthing_status_logic" == "1" ]
then
echo "SUCCESS: Syncthing is running"
continue
echo ""
else
echo "WARNING: Syncthing is not in a running state"
echo ""
echo "WARNING: Syncthing is not in a running state" | mailx -s "WARNING: Syncthing is not in a running state" "$email"
echo "Sending Syncthing status alert to "$email"..."
echo ""
fi
# Prompt user that script is checking Folding@Home service status
echo ""
echo "------------------------------------------------------------"
echo ""
echo "Checking Folding@Home service status..."
# Check if Folding@Home service is running
fah_status=$(systemctl status fahclient | grep -i running)
fah_status_logic=$(systemctl status fahclient | grep -i 'running' | wc -l)
echo ""
echo "Folding@Home Status:" $fah_status
echo ""
if [ "$fah_status_logic" == "1" ]; then
echo "SUCCESS: fahclient is running"
continue
echo ""
else
echo "WARNING: Folding@Home is not in a running state"
echo ""
cat "WARNING: Folding@Home is not in a running state" | mailx -s "WARNING: Folding@Home is not in a running state" "$email"
echo "Sending Folding@Home status alert to "$email"..."
echo ""
fi
# Start Folding@Home Service if it is not in a running state
if [ "$fah_status_logic" != "1" ]; then
systemctl start fahclient
echo "Folding@Home service has been started."
fi
# Start KF2 logic
#echo | tee -a "$log"
#echo "------------------------------------------------------------" | tee -a "$log"
#echo | tee -a "$log"
#echo "Checking KF2 server process and web status..." | tee -a "$log"
#echo | tee -a "$log"
#kf_process_status=$(ps -ef | grep -i kf | wc -l)
#if [ "$kf_process_status" == 3 ]; then
# echo "SUCCESS: KF2 process is in a running state" | tee -a "$log"
# continue
# echo | tee -a "$log"
#else
# echo "WARNING: KF2 process in not in a running state" | tee -a "$log"
# echo | tee -a "$log"
# cat "$log" | mailx -s "WARNING: KF2 process is not in a running state" "$email"
# echo "Sending KF2 process status alert to "$email"..." | tee -a "$log"
# echo | tee -a "$log"
#fi
#kf_web_status=$(curl -Is http:https://192.168.1.3:8080/ServerAdmin/current/info | grep -i "Content-Type: text/html" | awk '{print $1}')
#if [ "$kf_web_status" == Content-Type: ]; then
# echo "SUCCESS: KF2 web test successfull" | tee -a "$log"
# continue
# echo | tee -a "$log"
#else
# echo "WARNING: KF2 web test failed" | tee -a "$log"
# cat "$log" | mailx -s "WARNING: KF2 web test failed" "$email"
# echo | tee -a "$log"
# echo "Sending KF2 web status alert to "$email"..." | tee -a "$log"
# echo | tee -a "$log"
#fi
echo ""
echo "------------------------------------------------------------"
echo ""
echo "Checking Firewall service status..."
# Check if Firewall service is running
firewall_status=$(systemctl status firewalld | grep Active)
firewall_status_logic=$(systemctl status firewalld | grep running | wc -l)
echo ""
echo "Firewall status:" $firewall_status
echo ""
if [ "$firewall_status_logic" == "1" ]; then
echo "SUCCESS: Firewall is running"
continue
echo ""
echo ""
else
echo "WARNING: Firewall is not in a running state"
echo ""
echo "WARNING: Firewall is not in a running state" | mailx -s "WARNING: Firewall is not in a running state" "$email"
echo "Sending Firewall status alert to $"email"..."
echo ""
echo ""
fi
# Prompt user that script is checking cpu temp
echo "------------------------------------------------------------"
echo ""
echo "Checking CPU temp..."
echo ""
# Check CPU temp
cpu_temp=$(sensors | grep Package | awk '{print $4}' | cut -c 2-3)
if [ $cpu_temp -lt 80 ]; then
echo "SUCCESS: CPU temp within operating threshold"
echo ""
echo ""
else
echo "WARNING: CPU Temp over 80 degrees"
echo ""
cat "WARNING: CPU Temp over 80 degrees" | mailx -s "WARNING: CPU temp is above 85 degrees" "$email"
echo "Sending CPU temp alert to "$email"..."
echo ""
echo ""
fi