Httpd Automatic Start If DOWN, Urgent Assistance Required , please help

Posted on 2003-03-08
Medium Priority
Last Modified: 2013-12-15
Dear Sir,

I have enter the following command in my crond as you can see the first line is checking if the httpd is running if its down then then it will restart the HTTPD service . The problem which I am getting is whenever I enter those following line in my cron it never work. Is there any other command or any other way you could help me please.

* * * * * /bin/ps ax | /bin/grep '[/]sbin/httpd'> /dev/null 2> /dev/null
*/1 * * * * /bin/ps ax | /bin/grep '[/]sbin/httpd' || service httpd restart> /dev/null 2> /dev/null


Question by:sohaib69

Accepted Solution

majorwoo earned 2000 total points
ID: 8095638
there are a number of things here, ps -ax can possibly get you:

[root@daboss root]# ps -ax | grep httpd
25290 ?        S      0:00 /usr/sbin/httpd
25295 ?        S      0:00 /usr/sbin/httpd
25296 ?        S      0:00 /usr/sbin/httpd
25297 ?        S      0:00 /usr/sbin/httpd
25298 ?        S      0:00 /usr/sbin/httpd
25299 ?        S      0:00 /usr/sbin/httpd
25300 ?        S      0:00 /usr/sbin/httpd
25301 ?        S      0:00 /usr/sbin/httpd
25302 ?        S      0:00 /usr/sbin/httpd
25318 pts/0    S      0:00 grep httpd

so even if httpd is not running you can get the grep httpd line
you want a script to run that does that for you:


#check of httpd is running
ALIVE=`/bin/ps -e | grep httpd`

#if it is not running restart it
if [ ! "$ALIVE" ]; then
  service httpd restart >/dev/null 2>/dev/null
  #or if you prefer
  #/etc/init.d/httpd restart >/dev/null 2>/dev/null

exit 0

then call that script from your crontab

Expert Comment

ID: 8095847

If you are running redhat.
Try this at command line:
/etc/init.d/httpd status

If this works you'll get som pids and a word running.
I would rather do my grep check on this than on the process itself.

You might also checkout supervise progr to do this for you.

/Hans - Erik Skyttberg

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month4 days, 3 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question