Linux How to..

Linux How to ,Share Knowledge

TAG : Shell Scripts Check Service httpd and auto restart service httpd when it down.

#create shell scripts file
vi /root/
input line below :

/usr/bin/wget –tries=1 –timeout=30 -O /dev/null http://localhost/check_httpd.txt

if [ $? -ne 0 ]; then
/etc/init.d/httpd restart
datetime=`date “+%Y%m%d %H:%M:%S”`
echo ‘restarting httpd’ `ps aux` | mail -s “`hostname` restarting httpd `who | awk ‘{print $6}’`”
datetime=`date “+%Y%m%d %H:%M:%S”`
echo $datetime “failure”>>/var/log/httpd/check.log
datetime=`date “+%Y%m%d %H:%M:%S”`
echo $datetime “Normal” >> /var/log/httpd/check.log

:wq!  save and quit

#Create page for check  on DocumentRoot  Example DocumentRoot = /var/www/html/
touch /var/www/html/check_httpd.txt

#Auto Check with crontab check every time 5 minutes
crontab -e
input line below :
*/5 * * * *  /bin/sh /root/ 1> /dev/null 2> /tmp/checkhttpd

:wq! save and quit


Comments are closed.