Created
June 3, 2013 14:10
-
-
Save mfr/5698407 to your computer and use it in GitHub Desktop.
Script that checks whether lighttpd is still up, and if not:
- e-mail the last bit of log files
- kick some life back into it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script that checks whether lighttpd is still up, and if not: | |
# - e-mail the last bit of log files | |
# - kick some life back into it | |
# -- Thomas, 20050606 | |
PATH=/bin:/usr/bin | |
THEDIR=/tmp/lighttpd-watchdog | |
EMAIL= | |
PATH= | |
mkdir -p $THEDIR | |
if ( wget --timeout=5 --dns-timeout=5 --connect-timeout=5 --read-timeout=5 -q -P $THEDIR $PATH ) | |
then | |
# we are up | |
touch ~/.lighttpd-was-up | |
echo "$(date) - UP" | |
else | |
echo "$(date) - DOWN" | |
# write a nice e-mail | |
echo -n "Subject: Lighttpd crashed at " > $THEDIR/mail | |
date >> $THEDIR/mail | |
echo >> $THEDIR/mail | |
echo >> $THEDIR/mail | |
ps aux >> $THEDIR/mail | |
# kick lighttpd | |
echo "Now kicking lighttpd..." >> $THEDIR/mail | |
/etc/init.d/lighttpd stop >> $THEDIR/mail 2>&1 | |
killall -9 lighttpd >> $THEDIR/mail 2>&1 | |
/etc/init.d/lighttpd start >> $THEDIR/mail 2>&1 | |
# send the mail | |
echo >> $THEDIR/mail | |
lsof -n >> $THEDIR/mail 2>&1 | |
echo >> $THEDIR/mail | |
echo "Good luck!" >> $THEDIR/mail | |
/usr/sbin/ssmtp $EMAIL < $THEDIR/mail | |
rm ~/.lighttpd-was-up | |
fi | |
rm -rf $THEDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment