[CentOS-mirror] lock files

Wed Aug 5 22:11:25 UTC 2009
Nick Olsen <Nick at 141networks.com>

Guess I'm just not really getting the whole lock file thing, If its not there SHOULD this script make it? Also, If I make a file called update-centos.lock it complains that the lock file already exists when I run the script but still runs the rsync command.
I'm really not well versed when it comes to linux lock files and scripting. And would really need someone to hold my hand the whole way :s
This is what I make from David's comments, I'm sure I've done it wrong.

#!/bin/sh

### update-centos.sh
#!/bin/bash

### Lock file
if [ -f /tmp/update-centos.lock ]
    then echo "Lock file exists" && exit 1 else
    date >> /tmp/update-centos.lock
fi

### Big long rsync command ###
echo "Starting centos rsync"
screen -A -m -d -S centos rsync -vaH --numeric-ids --delete --delete-after --delay-updates  --progress rsync://linux.mirrors.es.net/centos/ /home/www/centos

### Remove lock file
/bin/rm -rf /tmp/update-centos.lock
### end update-centos.sh

-----Original Message-----
From: centos-mirror-bounces at centos.org [mailto:centos-mirror-bounces at centos.org] On Behalf Of David Richardson
Sent: Wednesday, August 05, 2009 5:59 PM
To: Mailing list for CentOS mirrors.
Subject: Re: [CentOS-mirror] lock files

On Wed, 5 Aug 2009, Nick Olsen wrote:

> I run a private centos mirror. Using rsync from the es.net mirror
> 
> I?m sure you get this all the time, but how do I use lock files with the 
> rsync client to keep multiple from spawning because of cron jobs?
> 
> My mirror also hosts ubuntu and a few others which run at the same time, 
> if this info is needed.
 
> 
> Right now the cron job just SH?s a script containing a screen call with 
> the rsync command in it. And I would like to keep it this way. At least 
> that sh script. What im really looking for is a script that checks for 
> the lockfile if its running. And then if its not SH?s the script. I 
> would have the cron job run  that script, and that script would run my 
> sh script called centos.sh located in /root/


On my mirror, I have a separate script for each project I mirror. My 
update-centos.sh script looks like this:

### update-centos.sh
#!/bin/bash

### Lock file
if [ -f /tmp/update-centos.lock ]
    then echo "Lock file exists" && exit 1
else
    date >> /tmp/update-centos.lock
fi

### Big long rsync command ###

### Remove lock file
/bin/rm -rf /tmp/update-centos.lock
### end update-centos.sh

I also have /etc/rc.local remove the lock files for all my scripts (in 
case I reboot during a run):
# /etc/rc.local
/bin/rm /tmp/update.lock >/dev/null 2>&1

Hope this helps.
DR

-- 
David Richardson <david.richardson at utah.edu>
"There are two kinds of statistics: the
kind you look up and the kind you make up."
-- Archie Goodwin, Death of a Doxy
_______________________________________________
CentOS-mirror mailing list
CentOS-mirror at centos.org
http://lists.centos.org/mailman/listinfo/centos-mirror