自动监控apache服务状态并重启的shell脚本


#!/bin/sh
curdate=`date +"%Y-%m-%d %H:%M:%S"`
#echo $curdate" exit " >> /home/opp/mon.log 2>&1 &
#exit

#statistik forum.php
num=`ps -ef|grep "/opp/apache/bin/httpd"|grep -v grep|wc -l`
#statistik www.123456.com/index.php
num2=`ps -ef|grep "/opt/lampp/bin/httpd" | grep -v grep |wc -l`
#echo $num;
#echo $curdate;
#num3=`netstat -anopt | grep 8080 | wc -l`
#echo $num3
if [ ${num} -lt 1 ] ;then
echo $curdate >> /home/opp/mon.log 2>&1 &
/opp/apache/bin/httpd -k start >> /home/opp/mon.log 2>&1 &
else
echo "apache/httpd is running "$curdate >> /home/opp/mon.log 2>&1 &
fi

if [ ${num} -gt 700 ] ;then
echo $curdate"this timestamp is index full" >> /home/opp/mon.log 2>&1 &
/opp/apache/bin/httpd -k stop
sleep 3
/opp/apache/bin/httpd -k start >> /home/opp/mon.log 2>&1 &
else
echo "apache/httpd is running "$curdate >> /home/opp/mon.log 2>&1 &
fi

if [ ${num2} -lt 2 ] ;then
echo $curdate >> /home/opp/mon.log 2>&1 &
killall -9 /opt/lampp/bin/httpd
/opt/lampp/lampp start >> /home/opp/mon.log 2>&1 &
else
echo "opt/httpd is running "$curdate >> /home/opp/mon.log 2>&1 &
fi

if [ ${num2} -gt 450 ] ;then
echo $curdate" this timestamp is for the forum's conection full" >> /home/opp/mon.log 2>&1 &
killall -9 /opt/lampp/bin/httpd
sleep 3
/opt/lampp/lampp start >> /home/opp/mon.log 2 >&1 &
else
echo "opt/httpd is running "$curdate >> /home/opp/mon.log 2>&1 &
fi
目的:
1.监控apache服务器的状态
2.当发现apache down机就自动重启apache服务

3.重启apache不成功,杀死该进程。并重新启动

4.记录日志

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com