[Dehs-devel] r94 - trunk
atomo64-guest at alioth.debian.org
atomo64-guest at alioth.debian.org
Wed Jan 23 20:01:12 UTC 2008
Author: atomo64-guest
Date: 2008-01-23 20:01:12 +0000 (Wed, 23 Jan 2008)
New Revision: 94
Modified:
trunk/dehs.sh
Log:
Disabled kill -O check since it will always exit with non zero if someone else owns the process
Fixed the ps -p $PID | grep check
Make it wait up to $maxattempts (30) with a sleep of 600 seconds each when an other instance is running
Modified: trunk/dehs.sh
===================================================================
--- trunk/dehs.sh 2008-01-04 22:52:31 UTC (rev 93)
+++ trunk/dehs.sh 2008-01-23 20:01:12 UTC (rev 94)
@@ -6,19 +6,32 @@
export BASEDIR=/org/home/groups/dehs
export WORKDIR=$BASEDIR/dehs_prj/dehs
LOCK=$BASEDIR/run.lock
-BNAME="`basename $0`"
+BNAME=$(basename "$0")
-if [ -e $LOCK ]; then
- PID="`cat $LOCK`"
- if [ ! -n "$PID" ] || ! $(kill -0 "$PID" 2> /dev/null) || ! "`ps -p "$PID" | grep "$BNAME" &>/dev/null`"; then
- echo "Removing stale lock file"
- rm $LOCK
- else
- # lock file is okay, dehs.sh running
- exit 1
- fi
-fi
+attempts=0
+maxattempts=30
+while true; do
+ if [ -e $LOCK ]; then
+ PID=$(cat $LOCK)
+ if [ ! -n "$PID" ] || ! ps -p "$PID" | grep "$BNAME" &>/dev/null; then
+ echo "Removing stale lock file"
+ rm $LOCK
+ else
+ if [ $attempts -eq $maxattempts ]; then
+ echo "Max number of attempts ($maxattempts) to run reached, surrending to a forever running instance" >&2
+ exit 1
+ fi
+ # lock file is okay, dehs.sh running
+ # let's wait ten minutes and try again
+ sleep $((10 * 60)) || exit 1
+ attempts=$(($attempts + 1))
+ fi
+ else
+ break
+ fi
+done
+
echo $$ > $LOCK
run_type="-update_all"
More information about the Dehs-devel
mailing list