Note: This digest from: http://www.111cn.net/sys/linux/63718.htm
Principle: Local access to the Apache service via the server (similar to the user visiting the website), if more than 15s does not return the normal 220-header code information, stating that the Apache service has stopped running, restart the httpd service immediately.
1. Execute VI Edit a new script on the Linux server and copy the script code below, then exit and save
[Email protected]/]# VI/OPT/AUTORSHTTPD
#!/bin/bash
Url= "HTTP://127.0.0.1/"
Curlit ()
{
Curl--connect-timeout--max-time--head--silent "$URL" | grep ' 200 '
}
Doit ()
{
if! Curlit; Then
/ETC/INIT.D/HTTPD Restart >/dev/null
Fi
}
While true; Do
doit >/dev/null
Sleep 10
Done
2. Give script permission to execute
[Email protected]/]# chmod 755/opt/autorshttpd
3. Execute script
[Email protected]/]# SH/OPT/AUTORSHTTPD &
Note: Here the SH command to add a & symbol, is to facilitate our remote SSH operation, if not add & sign, then close the SSH remote interface, this process is ended with, plus & symbol, even if the remote SSH shutdown can let the program run in the background, Don't forget to exit the login with the exit command and then close the SSH remote interface
4, let the script start automatically run
[Email protected]/]# vi/etc/rc.local
Add sh/opt/autorshttpd to the back of the line.
Apache Stateful monitoring Set restart