-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckNginx.sh
executable file
·70 lines (57 loc) · 1.51 KB
/
checkNginx.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
#!/bin/bash
#
#------------------------------
#
# Import settings
#
# Git branch
. ./settings.sh
# WriteLog() function
. ./timestampLogger.sh
#
#------------------------------
#
# Constants
#
BUILD_HOME=$BIN_HOME
LONG_DATE=$(date "+%Y-%m-%d_%H-%M-%S")
CHECK_LOG_FILE=${BUILD_HOME}/checkNginx-${LONG_DATE}.log
tryCount=2
#
#------------------------------
#
# Check the state of Nginx Server
#
WriteLog "Start Nginx Server check" "${CHECK_LOG_FILE}"
if [ -f /etc/nginx/nginx.conf ]
then
# Magic spell
sudo setenforce Permissive
while [[ $tryCount -ne 0 ]]
do
WriteLog "Try count: $tryCount" "${CHECK_LOG_FILE}"
nginxstate=$( ps aux | grep '[n]ginx' )
if [[ -z $nginxstate ]]
then
WriteLog "Stoped! Start it!" "${CHECK_LOG_FILE}"
sudo nginx &
sleep 5
tryCount=$(( $tryCount-1 ))
continue
else
WriteLog "It is OK!" "${CHECK_LOG_FILE}"
break
fi
done
if [[ $tryCount -eq 0 ]]
then
WriteLog "Nginx won't start! Give up and send Email to Agyi!" "${CHECK_LOG_FILE}"
# send email to Agyi
echo "Nginx won't start!" | mailx -s "Problem with Nginx" -u $USER ${ADMIN_EMAIL_ADDRESS}
fi
else
WriteLog "Nginx not installed in this sysytem! Send Email to Agyi!" "${CHECK_LOG_FILE}"
# send email to Agyi
echo "Nginx not installed in this sysytem!" | mailx -s "Problem with Nginx" -u $USER ${ADMIN_EMAIL_ADDRESS}
fi
WriteLog "End." "${CHECK_LOG_FILE}"