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.