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