Linux Apache automatic Monitoring script

Source: Internet
Author: User

1 Install Curl First

Yum Install Curl

2 Writing the Shell

VI restart_apache.sh

Write a bit of content

#!/bin/bash
Url= "HTTP://127.0.0.1/"
Curlit ()
{
Curl--connect-timeout--max-time--head--silent "$URL" | grep ' 200 '
}

Doit ()
{
if! Curlit; Then
Sleep 20
Top-n 1-b >>/var/log/restart_log/apache.log
/ETC/INIT.D/HTTPD stop
Sleep 2
/ETC/INIT.D/HTTPD Start >/dev/null
echo $ (date) "Apache Restart" >>/var/log/restart_log/re_apache.log
Sleep 30
if! Curlit; Then
echo $ (date) "failed! Now Reboot computer! ">>/var/log/restart_log/rebot_apache.log
Reboot
Fi
Sleep 180
Fi
}

Sleep 300
While true; Do
doit >/dev/null
Sleep 10
Done

3 adding restart_apache.sh to Scheduled Tasks

Crontab-e

Write the following content

*/1 * * * */home/restart_apache.sh//one-minute execution

Crontab-l to see if the join was successful

4 chmod +x restart_apache.sh means you can perform

5 test put Apache off and test it for a while to see if Apache started automatically.

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.