监测linux负载过高时重启php脚本
#!/bin/sh
TOP_SYS_LOAD_NUM=5
SYS_LOAD_NUM=`uptime | awk '{print $(NF-2)}' | sed 's/,//'`
echo $(date +"%y-%m-%d") `uptime`
if [ `echo "$TOP_SYS_LOAD_NUM < $SYS_LOAD_NUM"|bc` -eq 1 ]
then
echo "#0#" $(date +"%y-%m-%d %H:%M:%S") "pkill php-fpm" `ps -ef | grep php-fpm | wc -l`
/etc/init.d/php-fpm stop
sleep 8
pkill php-fpm
sleep 8
for i in 1 2 3
do
if [ `pgrep php-fpm | wc -l` -le 0 ]
then
/etc/init.d/php-fpm start
sleep 30
echo "#1#" $(date +"%y-%m-%d %H:%M:%S") "start php-fpm" `ps -ef | grep php-fpm | wc -l`
fi
done
else
if [ `pgrep php-fpm | wc -l` -le 0 ]
then
/etc/init.d/php-fpm start
sleep 30
echo "#2#" $(date +"%y-%m-%d %H:%M:%S") "start php-fpm" `ps -ef | grep php-fpm | wc -l`
fi
fi
定时执行
*/5 * * * * /root/check-php.sh >>/var/log/check-php.log