之前写过一个针对Linux环境下的Nginx守护进程,现在来个增强版的.同学们看着改来用吧.
ipv4=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
#把[email protected]改成自己的邮箱
[email protected]
#可以把nginx改为其他要守护的进程名字
nd=`pgrep -f nginx | wc -l`
if [ "$nd" = 0 ]
then
echo -e "Server IP is : $ipv4 " | mail -s "The nginx program is Dead" $EMAIL_TO
/usr/local/nginx/sbin/nginx #当被守护进程不存在后,自动启动的进程。可修改
/usr/local/php/sbin/php-fpm start #当被守护进程不存在后,自动启动的进程。可修改
else
echo "the program is running"
fi