bash script to monitor apache httpd service and automatically restart/kill if it hangs or not responsive

Hi Guys,

My Apache Web-server was playing up a little bit so until I found the cause of it my priority was to keep it up and running so I wrote a bash script to keep an eye on httpd crashes

Lets check it out

First up is to pick a script name and named it as httpdmon.sh and it is stored in my /home/jas/ directory

CronJob

Next I would just set a cron job so that it runs every minute and restart/start the service if required.

 Basic Script

Above script is good and as you can see that I am using curl to shoot a request to my local website and if the request times out i.e. after 5 seconds then an attempt to restart the service is made

Now thats Ok but I would also like to be notified about it and also would like to force kill httpd process if for some reason it hangs

A little bit more added to above script

As you can see that above will send me a message, you can replace mail command with sendmail etc its up to you.

Running that solved few of my issues until I figured out what is causing httpd to crash. If I found something interesting I will be sharing it with you guys.

Please note: I am not a Linux Advanced user but just knows enough to do some basic to intermediate things. If you have something to add to would like to improve above script please leave your comments as it would help others.

Cheers,

VN:F [1.9.22_1171]
Rating: 5.0/5 (2 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
bash script to monitor apache httpd service and automatically restart/kill if it hangs or not responsive, 5.0 out of 5 based on 2 ratings

Comments

  1. if we dont have the website in server.
    wanted to check the httpd service is running or not, if that is not running need to restart httpd service, dont have ping option too., ping also disabled.

Leave a Reply