-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_railo
executable file
·100 lines (82 loc) · 2.53 KB
/
check_railo
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
#!/bin/bash
# Requests a testpage using a timeout, and restarts Railo (or Adobe ColdFusion server,
# or something else) if the page doesn't respond. Also logs http status code if not "200 OK".
#
# USAGE: check_railo [testpage url]
#
# - Run as root
# - Special dependencies: curl
#
# Cron example (every three minutes during working hours):
# */3 7-18 * * * root /usr/local/sbin/check_webserver http://localhost/testpage.cfm
#
# A suitable testpage is a cfm template that runs a simple database query on each datasource.
#
#### CONF SECTION ####
#
# Seconds to wait for testpage to answer
TIMEOUT="7"
#
# Restart railo only after RESTART_INTERVAL minutes after last restart. Prevents restart loop.
RESTART_INTERVAL="60"
#
# Logfile
LOGFILE="/var/log/check_railo.log"
#
# Command to run. Could also be "service coldfusion restart" or something else.
RESTART_COMMAND="/opt/coldfusion2016/cfusion/bin/coldfusion restart"
#
# Command for sendin email. Syntax as mailutils /usr/bin/mail, e.g. MAIL_COMMAND [subject] [to]
# Comment out for no mails
MAIL_COMMAND="/usr/local/sbin/telegrambot.py"
#
# Mail recipient
#ERROR_MAIL="$(cat /etc/scriptmail.txt)"
ERROR_MAIL="telegram"
#
#### END OF CONF SECTION ####
if [ $# -ne 1 ]
then
echo "USAGE: check_railo [testpage url]"
exit
fi
TESTPAGE=$1
killtimeout=$(($TIMEOUT+1)) # Kill command one second after timeout
timefile="/tmp/check_railo_timefile" # File for storing RESTART_INTERVAL
if [ ! -f "$timefile" ];
then
# If missing (first run), create timefile and make it 12 hours old
/usr/bin/touch $timefile -d '-12 hour'
fi
timefile_age=$(( (`date +%s` - `stat -L --format %Y $timefile`)/60 )) # Get file age in minutes
# Run the test and save the result.
RESULT=$(/usr/bin/timeout -k $killtimeout $TIMEOUT /usr/bin/curl -s -o /dev/null -I -w "%{http_code}" ${TESTPAGE})
if [ "$RESULT" == "" ];
then
ERRORSTATUS="TIMEOUT"
if [ "$timefile_age" -gt "$RESTART_INTERVAL" ];
then
ERRORSTATUS="TIMEOUT: INIT RESTART"
/usr/bin/touch $timefile
# Restart server
$RESTART_COMMAND
else
# Don't restart until timefile is old enough
ERRORSTATUS="TIMEOUT: LAST RESTART TOO RECENT ($timefile_age min)"
fi
elif [ "$RESULT" != 200 ];
then
# Responds in time but returns http error: save error for logging.
ERRORSTATUS=$RESULT
fi
if [ "$ERRORSTATUS" ];
then
if [ "$MAIL_COMMAND" ];
then
# Send mail
$MAIL_COMMAND "(check_railo) ERROR: $ERRORSTATUS" "$ERROR_MAIL"
ERRORSTATUS="$ERRORSTATUS, mail sent to $ERROR_MAIL"
fi
# Log errorstatus
echo "$(/bin/date "+%Y-%m-%d %H:%M:%S") ERROR: $ERRORSTATUS" >> $LOGFILE
fi