aa=`pgrep -f nginx | wc -l` if [ "$aa" = 0 ] then /usr/local/nginx/sbin/nginx /usr/local/php/sbin/php-fpm start else echo "the program is running" fi 把以上腳本寫成一個.sh文件,然后用Crontab設置自動執行,發現Nginx不在進程中,自動啟動Nginx和PHP-FPM,否則輸出The Program is Running.
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 --phpfensi.com mail命令需要mailx這個程序,用下面這條命令安裝,代碼如下:
yum -y install mailx
跟上個版本一樣把以上腳本寫成一個.sh文件,然后用Crontab設置自動執行,這個版本是增強了郵件通知功能,發現Nginx不在進程中,自動啟動Nginx和PHP-FPM并通過郵件通知管理檢查,否則輸出The Program is Running.