How to check if your Apache Webserver is still running

March 5th, 2009 Posted in Bash Scripting, Linux

Difficulty Level:


If you have a apache webserver running on a linux machine sometimes it happens that the webserver crashs. This could have many reasons, but still there is the problem your site isn’t reachable. How can we solve this problem?

An easy way to check the apache deamon is in wiriting a small bash script. You can run the script every hour in a cron job.

So what is this script doing?

  1. First we check if the apache deamon is running.
  2. If the apache deamon is running we do nothing.
  3. If the apache deamon isn’t running we start the deamon again.
  4. After the start, we check again if the deamon was successfully started

  1. # look if the apache deamon is running
  2. apacha_alive=`ps -eaf |grep apache2 |grep -v grep |wc -l`
  3. if [ "$apacha_alive" -lt "1" ]; then
  4. # Apache is not running
  5. # Start Apache Deamon
  6. /etc/init.d/apache2 start
  7. # Check if start was successful
  8. apacha_alive=`ps -eaf |grep apache2 |grep -v grep |wc -l`
  9. if [ "$apacha_alive" -lt "1" ]; then
  10. echo "Apache couldn't be started"
  11. else
  12. echo "Apache successfully started"
  13. fi
  14. else
  15. echo "Apache is already running"
  16. fi

You can also download this bash script.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • MisterWong
  • Y!GG
  • Webnews
  • Digg
  • StumbleUpon
  • Reddit

Comments are closed.

My-Guide Interessante Guides: Einb├╝rgerungst..Fabrikverkauf G..Snowboard GuideNewsKurzarbeit