Apache Stateful monitoring Set restart

Source: Internet
Author: User

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

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.