Linux Nginx service daemon monitoring

Source: Internet
Author: User

Due to Nginx's outstanding performance, more and more web servers use Nginx. Although nginx is great, what if it crashes? We 'd better write a script for monitoring. If nginx fails, the system restarts automatically.
 
Of course, before giving the script, make a few assumptions: The nginx directory is/usr/local/nginx/, and the pid conf is under the corresponding default directory. The instance script is as follows:
 
#! /Bin/bash
 
PidFile =/usr/local/nginx/logs/nginx. pid
NginxBin =/usr/local/nginx/sbin/nginx
ConfFile =/usr/local/nginx/conf/nginx. conf
 
If [! -F $ pidFile]; then
$ NginxBin-c $ confFile
Fi
 
The above script does not work. You need to add it to the system scheduled task. Crontab is required at this time. Here is a tip: The minimum crontab time is minute. Our monitoring script cannot be in minutes. If we run the script every five seconds, what should we do? Assume that the above script is saved as/root/. bin/webmonitor. sh and edit crontab as follows:
 
* *** Sleep 5;/bin/bash/root/. bin/webmonitor. sh>/dev/null
 
Through the above operations, the monitoring script can basically run. Of course, you can continue to expand, how to monitor php and so on
For more information about crontab usage, see previous blog: crontab command summary.


From the pure soul

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.