LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-05-2004, 10:09 PM   #1
brentos
Member
 
Registered: Nov 2003
Distribution: Fedora Core3, RHEL3,4
Posts: 92

Rep: Reputation: 15
Restart apache on crash


I have a copy of apache2 running under a user on RHE to serve up images for a website. The site has been experiancing heavy load lately and the apache2 occationally crashes, but if no one is around to notice it, it might stay out for a while or over night depending on when it crashes.

Is there a way to monitor apache and have it restart if it crashes? Sort of what cpanel does for its version of apache?

Thank for anything you guys can suggest.
 
Old 06-06-2004, 02:21 AM   #2
SBing
Member
 
Registered: Mar 2004
Posts: 519

Rep: Reputation: 35
You could add a script to cron.daemon to run every (15?) minutes (the time interval is up to you)
which runs 'ps aux | grep httpd' - if it can't find httpd then it 'apachectl start' :)

Good luck

Steve
 
Old 06-06-2004, 08:37 AM   #3
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
do u have any ideas why it crashes? u may take a look at the server logs to find out. apache does not tend to crash without reason as far as i know.
 
Old 06-06-2004, 11:30 AM   #4
brentos
Member
 
Registered: Nov 2003
Distribution: Fedora Core3, RHEL3,4
Posts: 92

Original Poster
Rep: Reputation: 15
Yes it crashed because it gets maxed out on its connections for a extended period of time. We are running at around 12 million page loads a day and 1200 Gigs of bandwidth a month on that server and the apache2 is hosting the images.

The only question I have is can i get the grep to check the user name as well? Cause there is two copies of apache a 1.3 that comes with cpanel and a 2 to host layouts and images since the cpanel couldn't handle it all. So I just want to check the one running as a specific user not nobody.

Thanks for the help.
 
Old 06-06-2004, 01:11 PM   #5
SBing
Member
 
Registered: Mar 2004
Posts: 519

Rep: Reputation: 35
sure,

ps aux | grep httpd | grep -v nobody | grep -v grep

grep -v is an inverse grep,

the first grep -v ignores httpd running by nobody
the second grep -v ignores grep

or you could grep for the specific user

ps aux | grep -httpd | grep <user>

Steve
 
Old 06-06-2004, 02:22 PM   #6
brentos
Member
 
Registered: Nov 2003
Distribution: Fedora Core3, RHEL3,4
Posts: 92

Original Poster
Rep: Reputation: 15
So just to make sure I did this right I put

if ps aux | grep -httpd | grep <user>
then
everything ok exit script
else
restart the server
fi

So that should be all i need right?
 
Old 06-07-2004, 02:29 AM   #7
SBing
Member
 
Registered: Mar 2004
Posts: 519

Rep: Reputation: 35
Essentially yes, in pseudo:

Code:
IF ps aux | grep -httpd | grep <user> = ""                 #I.E. doesn't equal anything
THEN
     restart server
ELSE
     do nothing
END IF
Maybe you can post your final script for others to use :)

Steve
 
Old 06-07-2004, 10:54 AM   #8
brentos
Member
 
Registered: Nov 2003
Distribution: Fedora Core3, RHEL3,4
Posts: 92

Original Poster
Rep: Reputation: 15
Here is my final script, I used a different version of the ps command just cause it required one less grep command so I figured less commands is better and I did the if backwards cause I could never get the = "" to work for some odd reason, I tried like 20 ways but hey this works. The only thing is when you run it manually you get a long list from the ps but hey this runs in a cron so I don't care I never see it. I also got it to send me an email when it happens so that I can sort of check up on the server, if its crashing to much its not that good. The restartMsg.txt just contains a sort little restart message.


#!/bin/bash
#script checks and restarts apache if required

if ps U layout | grep httpd
then
echo "Layouts server up and running"
exit 0
else
#restart server
echo "Layouts server down, restarting server"
cat restartMsg.txt | mail -s "Layouts failed on host.domain.com" root
/home/layout/bin/apachectl restart
echo "Layouts server restarted"
fi


Hope someone else might find the script useful, I know its small and easy to write but you never know.
Thanks Steve for the help
 
Old 06-07-2004, 02:41 PM   #9
SBing
Member
 
Registered: Mar 2004
Posts: 519

Rep: Reputation: 35
No problem, just glad you got it all sorted :)

Shame apache crashes though, still, heavy loads cause these sort of things to happen :(

Steve

Edit:

Quote:
Originally posted by brentos
The only thing is when you run it manually you get a long list from the ps...
I know it's not a problem since you're running it through cron, but for anyone else, try this instead:

if ps U layout | grep httpd > /dev/null

It'll suppress the output from ps :)

Last edited by SBing; 06-07-2004 at 02:46 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't trace frequent apache crash/automagic restart error I_AM Linux - General 1 04-09-2005 08:13 AM
how do i apache restart? einstien Linux - General 3 03-30-2005 01:22 PM
amuleweb - restart after crash? jess1975 Linux - Software 0 03-16-2005 05:45 AM
Apache can't restart Serbulent Linux - Enterprise 2 03-16-2005 02:29 AM
How do I restart Apache? 360 Linux - Networking 2 08-25-2001 06:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration