Changeset 14376

Show
Ignore:
Timestamp:
01/11/08 14:40:16 (11 months ago)
Author:
rambo
Message:

forward port r14375

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.core/support/midcom_services_cron.sh

    r13590 r14376  
    1717# like "lynx -auth=username:password" for HTTP basic-auth 
    1818LYNX="lynx"  
     19STAT="stat -c %Z" # how to get file timestamp 
     20DATE="date +%s" # how to get system timestamp 
     21LIFETIME=3600 # Max pidfile age in seconds before it's considered stale 
    1922 
    20 if [ "$1" == "" ]; then 
     23if [ "$1" == "" ] 
     24then 
    2125    URL_SUFFIX="" 
    2226    PIDFILE="/var/run/midcom_services_cron_everymin.pid" 
     
    2832fi   
    2933 
    30 # TODO: figure out a locking mechanism that ensures only one instance 
    31 # is running at a time, without missing any valid runs 
     34function check_pidfile 
     35
     36    if [ -f $1 ] 
     37    then 
     38        MODIFIED=`$STAT $1` 
     39        NOW=`$DATE` 
     40        AGE=`expr $NOW - $MODIFIED` 
     41        #echo "MODIFIED=$MODIFIED NOW=$NOW AGE=$AGE LIFETIME=$LIFETIME" 
     42        if [ "$AGE" -lt "$LIFETIME" ] 
     43        then 
     44            return 1 
     45        fi 
     46        echo "Lock $1 is stale, removing" 
     47        # PONDER: Should we kill the process ??, the line below should do the trick 
     48        # kill -9 `cat $1` 
     49        rm -f $1 
     50        return 0 
     51    fi 
     52    return 0 
     53
    3254 
    3355# Make sure we only have one copy of the type running at a given time 
    34 test -f $PIDFILE && exit 1 
     56check_pidfile $PIDFILE 
     57PIDSTAT=$? 
     58if [  "$PIDSTAT" != "0" ] 
     59then 
     60    exit 1 
     61fi 
    3562echo $$ > $PIDFILE 
    36 # Wait until everymin script has completed if it's running 
    37 if [ "$PIDFILE2" != "" ]; then 
    38     if [ -f $PIDFILE2 ]; then 
    39         while [ -f $PIDFILE2 ]; do 
    40             sleep 10 
    41         done 
    42     fi 
     63# Wait untill everymin script has completed if it's running 
     64if [ "$PIDFILE2" != "" ] 
     65then 
     66    check_pidfile $PIDFILE2 
     67    PIDSTAT2=$? 
     68    while [  "$PIDSTAT2" != "0" ] 
     69    do 
     70        sleep 10 
     71        check_pidfile $PIDFILE2 
     72        PIDSTAT2=$? 
     73    done 
    4374fi 
    4475 
    45 for SITE in $SITES; do 
    46     if [ `expr match "$SITE" 'https*'` -eq 0 ]; then 
     76for SITE in $SITES 
     77do 
     78    if [ `expr match "$SITE" 'https*'` -eq 0 ] 
     79    then 
    4780        URL="http://$SITE/midcom-exec-midcom/cron.php$URL_SUFFIX" 
    4881    else