[CentOS] Any one have a good example...

Tue Aug 29 19:25:56 UTC 2006
mike.redan at bell.ca <mike.redan at bell.ca>

Something like this works alright:


# Check if process is running already
SCRIPT_NAME=do_stuff
pidfile=/tmp/$SCRIPT_NAME.pid


if [ -f $pidfile ]; then
   runpid=`cat $pidfile`
   if ps -p $runpid; then
      echo "$SCRIPT_NAME is already running ... stopping"
      exit 1
   else
      echo "$SCRIPT_NAME pid found but process dead, cleaning up and
starting ..."
      rm -f $pidfile
   fi
else
   echo "No $SCRIPT_NAME Process Detected ... starting"
fi

echo $$ > $pidfile





-----Original Message-----
From: centos-bounces at centos.org [mailto:centos-bounces at centos.org] On
Behalf Of Morten Torstensen
Sent: August 29, 2006 3:20 PM
To: CentOS mailing list
Subject: Re: [CentOS] Any one have a good example...


Scott Silva wrote:
> ...of a shell script for rsync that won't start again if it is already

> running? I thought of using a lock file, but what if it is killed mid 
> script or bombs?

You write your PID to the lock file, then in startup, you check if the
lock file 
exist and if the PID process is running, then it is still active.

It could be that the process is just hung, so this method will only help
assure 
that you do not start a second copy.

-- 

//Morten Torstensen
//Email: morten at mortent.org
//IM: Cartoon at jabber.no morten.torstensen at gmail.com

And if it turns out that there is a God, I don't believe that he is
evil. The worst that can be said is that he's an underachiever.
_______________________________________________
CentOS mailing list
CentOS at centos.org http://lists.centos.org/mailman/listinfo/centos