Linux Next Smart Restart Apache server script sharing _linux

Source: Internet
Author: User

Description: My host for the Centos system, step-by-step instructions are written in the annotation inside, easy to read.

VI apachemonitor.sh #!/bin/bash url= "HTTP://127.0.0.1/" Curlit () {curl–connect-timeout 15–max-time 20–head–silent "$URL" |
grep ' 200′# 15 is the connection timeout, and if the HTTP service that accesses localhost exceeds 15s and still does not respond correctly to the 200-head code, it is judged as inaccessible. Doit () {if! Curlit then # if localhost Apache service does not return 200 headers correctly, an exception occurs. Execute the following command: Sleep top-n 1-b >>/var/log/apachemonitor.log # The top command content is written to date to file for reference/usr/bin/killall-9 apache2 &&am P /usr/bin/killall-9 php5-cgi &&/usr/bin/killall-9 httpd &&/usr/bin/killall-9 http &&/usr/bin /killall-9 Apache &&/usr/bin/killall-9 php-cgi >/dev/null # is compatible, killing a variety of Apache processes. You can modify the sleep 2/etc/init.d/apache2 Start >/dev/null/etc/init.d/httpd start >/dev/null # Compatibility based on the features of your Apache service, and execute two AP
Ache Restart command, can be modified as needed. echo $ (date) "Apache restart" >>/var/log/apachemonitor.log # Write log Sleep 30 # wait 30 seconds after reboot completes, and then try again if! Curlit; Then # If you still cannot access, then: Echo $ (date) failed! Now Reboot computer! ">>/var/log/apachemonitor.log # writes to Apache that is still restarting the failed log Reboot # Reboot the machine. Actually restarting the entire server is a great way to do it. I do not propose.
Everyone according to the need to modify their own, such as text messages, e-mail alarm or something. Fi Sleep 180 fi 300 # 5 minutes after the script is run (prevents the server from restarting because Apache is not starting to cause a miscalculation) while true; Do # main circulation body doit >/dev/null sleep done then execute: chmod +x apachemonitor.sh Add boot entry: vi/etc/rc.d/rc.local my rc.local script
Content is: #!/bin/sh # This script would be executed *after* all the other init scripts.

# You can put your own initialization stuff in-if you don ' t # want to do the full Sys V style init stuff.

 touch/var/lock/subsys/local/root/lampmonitor.sh

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.