run only one instance of this script at a time
authorWolfram Schneider <wosch@indexdata.dk>
Fri, 23 Apr 2010 12:57:43 +0000 (12:57 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Fri, 23 Apr 2010 12:57:43 +0000 (12:57 +0000)
implemented by a simple self-written lockfile. Do not use lockfile(1)
due a bug in debian packages, for details see:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=565613

bin/irspy-update.sh

index 90d5259..a29d167 100755 (executable)
@@ -8,6 +8,16 @@
 home=/usr/local/src/git
 cd $home/irspy/bin || exit 2
 logdir=../tmp
+lockfile=../tmp/irspy-update.lock
+
+if [ -f $lockfile ]; then
+    pid=`cat $lockfile`
+    if kill -0 $pid 2>/dev/null; then
+       echo "This script is already running with pid: $pid"
+       exit 1
+    fi
+fi
+echo $$ > $lockfile || exit 2
 
 for i in 0 1 2 3 4 5 6
 do
@@ -16,3 +26,5 @@ do
    gzip -f $logfile
 done
 
+rm -f $lockfile
+