154f871dec4299c79113834fd45f17a4521ad8c6
jcasper
  Wed Nov 23 22:07:55 2022 -0800
Replacing lockfile in fetchCramReference with flock, to remove the procmail
dependency.  Also updating the browserbox version to match the current server version.  refs #17547, #14717

diff --git src/browserbox/root/fetchCramReference.sh src/browserbox/root/fetchCramReference.sh
index d9ea2d2..ed36df3 100755
--- src/browserbox/root/fetchCramReference.sh
+++ src/browserbox/root/fetchCramReference.sh
@@ -43,36 +43,32 @@
     exit 255
 fi
 
 if [ ! -d "$DESTDIR" ]
 then
     echo "Error: $DESTDIR is missing or not a directory"
     exit 255
 fi
 
 if [ ! -d "$ERRORDIR" ]
 then
     echo "Error: $ERRORDIR is missing or not a directory"
     exit 255
 fi
 
-if lockfile -! -r 0 "${PENDING}/fetch.lock" >& /dev/null
-then
-    # echo "${PENDING}/fetch.lock already exists.  Exiting."
-    exit 0
-fi
-
+(
+flock -n 9 || exit 0
 
 # set up cleanup in the event of Ctrl-C
 trap '{rm -f "${PENDING}/*.out"; rm -f ${PENDING}/fetch.lock; exit 1; }' INT
 
 
 # Re-add files that previously failed, if they failed long enough ago.
 # Retry after 1 hour; give up after $MAXTRIES attempts
 find ${ERRORDIR} -type f -mmin +60 -printf "%f\0" |
  xargs -0 -n 1 -I % sh -c \
 '
     if [ -e "${PENDING}/%.try${MAXTRIES}" ]
     then
         rm -f "${PENDING}/%.try${MAXTRIES}" "${ERRORDIR}/%"
     else
         cp $(find "${PENDING}" -maxdepth 1 -type f -name "%.try*" -print -quit) "${PENDING}/%" || true
@@ -82,31 +78,34 @@
 
 
 # Fetch files in parallel; up to 5 at a time.  If xargs does not support -P 5
 # in your Unix, delete that option to do serial fetch.
 
 ls "$PENDING" | (egrep -v 'fetch.lock|.out|.try' || true) |
 xargs -I % -n 1 -P 5 sh -c \
 '
     if WGETOUT=$(wget -nv -i "${PENDING}/%" -O "${PENDING}/%.out" 2>&1)
     then
         # Download successful
         mv "${PENDING}/%.out" "${DESTDIR}/%" &&
         rm -f "${PENDING}/%" "${PENDING}/%.try*" ||
         echo "Internal server error: Please contact system administrator" > ${ERRORDIR}/%
     else
-        # Download failed - increment try count
+        # Download failed, record wget error message
         echo "$WGETOUT" | tr "\n" "\t" > "${ERRORDIR}/%"
+    fi
+    # On error, increment try count
+    if [ -e "${ERRORDIR}/%" ]
+    then
         OLDTRY=$(find "${PENDING}" -maxdepth 1 -type f -name "%.try*" -print -quit)
         if [[ "${OLDTRY}" == "" ]]
         then
             mv "${PENDING}/%" "${PENDING}/%.try1"
         else
             NEWTRY=$(echo "${OLDTRY}" | perl -pe "s/try(\d+)$/\"try\".(\$1+1)/e" )
             mv "${OLDTRY}" "${NEWTRY}"
             rm -f "${PENDING}/%"
         fi
         rm -f "${PENDING}/%.out"
     fi
 '
-
-rm -f "${PENDING}/fetch.lock"
+) 9>${PENDING}/fetch.lock