Recently VPS Nginx don't know why, will turn off for no reason. It may be that the hen was killed by the high load. But to keep the site online, you've written a daemon:
The code is as follows |
Copy Code |
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 |
Write the above script as an. sh file. Then use the Crontab setting to automate, discovering that Nginx is not in the process and automatically starts Nginx and PHP-FPM. Otherwise the output is Running.
Above is a Linux environment for the Nginx Daemon, now to an enhanced version of. Students look at the change to use it.
The code is as follows |
Copy Code |
ipv4= ' ifconfig-a|grep inet|grep-v 127.0.0.1|grep-v Inet6|awk ' {print $} ' |tr-d ' addr: ' #把xxx @163.com changed into his own mailbox. Email_to=xxx@163.com #可以把nginx改为其他要守护的进程名字 Nd= ' Pgrep-f Nginx | Wc-l ' If ["$nd" = 0] Then Echo-e "Server IP is: $IPV 4" | Mail-s "The Nginx is Dead" $EMAIL _to /usr/local/nginx/sbin/nginx #当被守护进程不存在后, the process that starts automatically. Can be modified /USR/LOCAL/PHP/SBIN/PHP-FPM start #当被守护进程不存在后, the process that starts automatically. Can be modified Else echo "The program is running" Fi
|
The Mail command needs to MAILX this program and install it with the following command.
The code is as follows |
Copy Code |
Yum-y Install MAILX |
Like the previous version, the above script is written as an. sh file. Then use the Crontab setting to automate, this version enhances the mail notification function, discovers that Nginx is not in the process, starts Nginx and PHP-FPM automatically and notifies the management check by mail. Otherwise the output is Running.
This will also have an e-mail sent to you oh, haha is not more intelligent ah, than the Windows system is to be smart a lot of OH.