2

[Linux笔记]Linux守护进程

之前写过一个针对Linux环境下的Nginx守护进程,现在来个增强版的.同学们看着改来用吧.

ipv4=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
#把xxx@163.com改成自己的邮箱
EMAIL_TO=xxx@163.com
#可以把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

Continue Reading