Перевірялка Апача на живучість

#!/bin/bash

PATH=/bin:/usr/bin
THEDIR=/tmp/apache-watchdog
EMAIL=blablabla@gmail.com
mkdir -p $THEDIR

if ( wget --timeout=30 -q -P $THEDIR http://localhost/robots.txt )
then
# we are up
touch ~/.apache-was-up
else
# down! but if it was down already, don't keep spamming
if [[ -f ~/.apache-was-up ]]
then
# write a nice e-mail
echo -n "apache crashed at " > $THEDIR/mail
date >> $THEDIR/mail
echo >> $THEDIR/mail
echo "Access log:" >> $THEDIR/mail
tail -n 30 /var/log/httpd/access_log >> $THEDIR/mail
echo >> $THEDIR/mail
echo "Error log:" >> $THEDIR/mail
tail -n 30 /var/log/httpd/access_log >> $THEDIR/mail
echo >> $THEDIR/mail
# kick apache
echo "Now kicking apache..." >> $THEDIR/mail
/etc/rc.d/init.d/httpd stop >> $THEDIR/mail 2>&1
killall -9 httpd >> $THEDIR/mail 2>&1
/etc/rc.d/init.d/httpd start >> $THEDIR/mail 2>&1
# send the mail
echo >> $THEDIR/mail
echo "Good luck troubleshooting!" >> $THEDIR/mail
mail -s "apache-watchdog: apache crashed" $EMAIL < $THEDIR/mail
rm ~/.apache-was-up
fi
fi
rm -rf $THEDIR


(c) десь нагуглено і допиляно під федору

Немає коментарів: