In the actual production environment using a more than a multi-web environment is generally Apache, in order to ensure that Apache normal operation, will certainly be the Apache process monitoring, but generally the efficiency is not very good, In order to ensure that the business in the production environment is functioning properly or that a failure can be handled quickly, it is possible to determine whether a httpd TCP connection is available in the check system, and a script to check Apache is written
#!/bin/bash#apache_deamon.shlog=/data/backup/apache_status/logs# event record httpd_num= ' Netstat-ntpa |grep:80 |wc-l ' apache_bin=/usr/local/apache/binif [!-e "$log"];then mkdir-p "$log" fiif [$httpd _num-eq 0];then $apache _bi N/apachectl restart|tee-a $log/' date + '%y%m%d-%h:%m '. Log >/dev/null 2>&1 &fi
And then add the timer to the crontab to check once a minute.
*/1 * * * */usr/local/scripts/apache_deamon.sh
Of course, this script can also be used to check some services that require TCP or UDP connections.
This article from "Technical essay" blog, declined reprint!
Process check script under Apache environment