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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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@xxxxxxxxxx [mailto:centos-bounces@xxxxxxxxxx] 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@xxxxxxxxxxx
//IM: Cartoon@xxxxxxxxx morten.torstensen@xxxxxxxxx

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@xxxxxxxxxx http://lists.centos.org/mailman/listinfo/centos
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux