Automatic restart of Apache in case of failure

Source: Internet
Author: User
Tags apache error log mail code

Recently don't know why blogs are always somehow hanging off,
Restarting Apache is good, and I'm too lazy to study exactly where it went wrong.
Just need to manually ssh up to restart Apache every time, a bit of trouble.
And sometimes it hangs in the night, and one night the blog is inaccessible.


Finally unbearable, wrote a script to do this thing, the code is as follows:

#!/bin/shif (wget--timeout=5 -Q--spider http://leonax.net/)  " OK " else/etc/init.d/"httpd restarted"fi

The principle is simple, is to try to visit the blog (the third line),
If there is any problem, restart Apache (line seventh).
The wget parameter –spider means just a visit and does not download the content.
If you like, you can also add an e-mail code to the Else
The Apache error log sent directly to the mail, convenient analysis, but I do not bother to do.

Then save the code as check_apache.sh and add it to the crontab:

*/5 * * * */var/www/check_apache.sh

Where */5 says to run check_apache.sh every 5 minutes.
Note that you should use sudo when opening crontab, because it requires sudo permissions to restart Apache.

Reprinted from: http://leonax.net/c/product/software/apache/

Automatic restart of Apache in case of failure

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.