From 0e6d107a5087de52bb891cd35617f2a149bdd06f Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 26 Apr 2018 15:51:35 +0200 Subject: [PATCH] Fix in the algorithms-updater the check for a already running instance. --- .../templates/algorithms-updater.j2 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/smartgears/dataminer_app/templates/algorithms-updater.j2 b/smartgears/dataminer_app/templates/algorithms-updater.j2 index 1cd861ea..a96714e9 100644 --- a/smartgears/dataminer_app/templates/algorithms-updater.j2 +++ b/smartgears/dataminer_app/templates/algorithms-updater.j2 @@ -23,7 +23,6 @@ SVN_UPDATE_STATUS= UPDATER_PROCESS_MAX_RUNTIME=21600 OLDPROC= OLDPROC_RUNNING= -RUNNING_JOB_RETVAL= trap "logger 'algorithms-updater: trap intercepted, exiting.' ; cleanup 1" SIGHUP SIGINT SIGTERM @@ -46,23 +45,22 @@ create_log_dir() { set +o pipefail set +e OLDPROC=$( cat "$LOCK_FILE" ) - OLDPROC_RUNNING=$( ps auwwx | grep -v grep | grep $OLDPROC | awk '{ print $2 }' ) - RUNNING_JOB_RETVAL=$? + OLDPROC_RUNNING=$( ps auwwx | grep -v grep | awk '{ print $2 }' | grep "$OLDPROC" ) if [ ! -z "$OLDPROC_RUNNING" ] ; then logger "algorithms_updater: pid of the already running process: $OLDPROC_RUNNING" - OLDPROC_RUNNING_TIME=$( ps -o etimes= -p ${OLDPROC_RUNNING} ) - if [ $OLDPROC_RUNNING_TIME -gt $UPDATER_PROCESS_MAX_RUNTIME ] ; then + OLDPROC_RUNNING_TIME=$( ps -o etimes= -p "${OLDPROC_RUNNING}" ) + if [ "$OLDPROC_RUNNING_TIME" -gt $UPDATER_PROCESS_MAX_RUNTIME ] ; then logger "algorithms_updater: process $OLDPROC_RUNNING was running for $OLDPROC_RUNNING_TIME seconds. Got stuck, killing it" - kill -9 $OLDPROC_RUNNING - rm -f $LOCK_FILE + kill -9 "$OLDPROC_RUNNING" + rm -f "$LOCK_FILE" else logger "algorithms_updater: another process is running, exiting." - rm -fr $OUT_DIR + rm -fr "$OUT_DIR" exit 0 fi else logger "algorithms_updater: lock file exist but the process not. Continuing." - rm -f $LOCK_FILE + rm -f "$LOCK_FILE" fi else logger 'algorithms-updater: no other jobs running, proceeding.'