It depends how you start it, but generally speaking most daemons will
have a pid file in /var/run/ (this is system dependant) - so if, for
example, the file, /var/run/apache.pid exists, you can assume that the
daemon is either running or has been killed ungracefully (eg, kill -9).

If you're feeling real paranoid, you can check that this pid exists and
is the apache process

APACHEPID="/var/run/apache.pid"

if [ -f $APACHEPID ]
then
        echo Apache did not stop
        exit 1
else
        echo Apache stopped, proceeding
        proceed
fi


On Mon, 2006-01-09 at 22:48 +1100, Ben Donohue wrote:
> Hi Mike,
> I do the following on a ppp script to check if the process is running or 
> not. It will start the process if it has stopped.
> Maybe you can modify it for your needs...
> ps ax|fgrep pppd|fgrep -v fgrep > /dev/null || /usr/sbin/pppd
> 
> Ben
> 
> 
> Michael Lake wrote:
> 
> > Hi all
> >
> > I have a bash script that shuts down apache so that users can't 
> > updates a database,
> > I do a backup of the database, then startup apache again. Roughly this 
> > is what I have:
> >
> > sudo apache-perlctl stop >> $LOGFILE 2> $ERRORFILE
> > sleep 5
> >
> > The sleep is to give apache enough time to shutdown but I would prefer 
> > to actually test if apache has shutdown and exit with an error or call 
> > an error function if it does not shutdown for some reason. Or it might 
> > just take 6 seconds to shutdown.
> > So far I have tried things like this:
> >
> > ----------------------------------------------
> > #!/bin/bash
> >
> > function report_error {
> >     echo "Error apache didn't stop"
> >     exit 1
> > }
> >
> > function proceed {
> >     echo "Apache stopped OK"
> >     exit 0
> > }
> >
> > # The line below produces 'apache-perl' if apache-perl is running and 
> > '' if it's not.
> > string=`ps -C apache-perl -o comm | uniq | grep -v COMMAND`
> >
> > if [ $string == 'apache-perl' ];
> > then
> >     # apache is still running
> >     report_error
> > else
> >     # apache has stopped
> >     proceed
> > fi
> > ----------------------------------------------
> >
> > I feel the way to get the $string is messy and may not be very portable.
> >
> > Also the script will eventually need to be able to test for either the 
> > first apache-perl or the second one.
> > At present the above script cannot descriminate between the two.
> > i.e. # www-data 28319 28312  0 13:02 pts/3    00:00:00 
> > /usr/sbin/apache-perl
> > # root     28584     1  6 13:03 pts/3    00:00:00 
> > /usr/sbin/apache-perl -f /etc/apache-perl/httpd2.conf
> >
> > What do folks use to determine if a process is running?
> >
> > Mike
> 

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to