[CentOS-mirror] I see all your new mirrors ...

Thu Jul 14 23:36:32 UTC 2011
Kealey, Martin, VF-NZ <Martin.Kealey at vodafone.com>

Perhaps that example code would clearer if written:


(

   if ! flock -w 1 200 ; then

           echo >&2 "Another process is still running..."

           exit

   fi

   RunLocked

) 200> ${lockdir}/mirror.centos.lock

Or


exec 200> ${lockdir}/mirror.centos.lock

if ! flock -w 1 200 ; then

   echo >&2 "Another process is still running..."

   exit

fi

RunLocked

Or for a more succinct version:


( flock -w 1 200 && RunLocked ) 200> ${lockdir}/mirror.centos.lock

(Point is: referencing "$?" is almost never needed, and usually obfuscatory.)

From: centos-mirror-bounces at centos.org [mailto:centos-mirror-bounces at centos.org] On Behalf Of João Carlos Mendes Luís
Sent: 13 July 2011 03:29
To: Mailing list for CentOS mirrors.
Subject: Re: [CentOS-mirror] I see all your new mirrors ...

Using "touch" and "test -e" as a lock test is not safe.  If the shell dies for any reason, the lock file will get stale.

If you sync station is linux, a safer option is to use the flock(1) program:


NAME
       flock - Manage locks from shell scripts

SYNOPSIS
       flock [-sxon] [-w timeout] lockfile [-c] command...

       flock [-sxon] [-w timeout] lockdir [-c] command...

       flock [-sxun] [-w timeout] fd


Here is the lock part of my mirror script:

RunLocked()
{
   ....
}

(
  flock -w 1 200
  if [ "$?" -ne 0 ] ; then
    echo "Error, lock is already taken..."
    exit
  else
    RunLocked
  fi
) 200> ${lockdir}/mirror.centos.lock




                                       Jonny



--

João Carlos Mendes Luís - Computer & Networking Engineer

jonny at jonny.eng.br<mailto:jonny at jonny.eng.br>

On 07/12/2011 11:56 AM, Adam wrote:
admin wrote:


Yes It would be great . I'm still rsync centos repo.
Could you provide me bash script to rsync with file locking ?

Attached is a bash locking rsync script.  This script is pretty informative and intelligent.  It verifies that the time stamp of the server you are syncing form is newer then yours before it syncs.  Hence it shouldn't ever delete files you have already downloaded if you hit an old mirror.

Adam






_______________________________________________

CentOS-mirror mailing list

CentOS-mirror at centos.org<mailto:CentOS-mirror at centos.org>

http://lists.centos.org/mailman/listinfo/centos-mirror

-----------------------------------------------------------------------------------------------
Have you seen our website?.... http://www.vodafone.co.nz

Manage Your Account, check your Vodafone Mail and send web2TXT online: http://www.vodafone.co.nz/myvodafone

CAUTION: This correspondence is confidential and intended for the named recipient(s) only.
If you are not the named recipient and receive this correspondence in error, you must not copy,
distribute or take any action in reliance on it and you should delete it from your system and
notify the sender immediately.  Thank you.

Unless otherwise stated, any views or opinions expressed are solely those of the author and do
not represent those of Vodafone New Zealand Limited.

Vodafone New Zealand Limited
20 Viaduct Harbour Avenue, Private Bag 92161, Auckland 1142
Telephone + 64 9 355 2000
Facsimile + 64 9 355 2001
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.centos.org/pipermail/centos-mirror/attachments/20110715/3f19f230/attachment-0006.html>