Nginx Daemon (auto start nginx) in Linux system

Source: Internet
Author: User
Tags fpm

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.