From 85466e0ab0fe379ee09a7030319b67d465ac2a65 Mon Sep 17 00:00:00 2001 From: deajan Date: Mon, 21 Nov 2016 19:18:22 +0100 Subject: [PATCH] Added MAX_WAIT support for MacOS daemon mode --- dev/n_osync.sh | 8 +++++++- dev/ofunctions.sh | 15 ++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dev/n_osync.sh b/dev/n_osync.sh index 5392736..809bb6c 100755 --- a/dev/n_osync.sh +++ b/dev/n_osync.sh @@ -2052,6 +2052,8 @@ function SyncOnChanges { local cmd local retval + local sleepTime + if [ "$LOCAL_OS" == "MacOSX" ]; then if ! type fswatch > /dev/null 2>&1 ; then Logger "No inotifywait command found. Cannot monitor changes." "CRITICAL" @@ -2086,8 +2088,12 @@ function SyncOnChanges { else inotifywait --exclude $OSYNC_DIR $RSYNC_PATTERNS $RSYNC_PARTIAL_EXCLUDE -qq -r -e create -e modify -e delete -e move -e attrib --timeout "$MAX_WAIT" "$INITIATOR_SYNC_DIR" & fi - wait $! + #wait $! + sleepTime=SLEEP_TIME + SLEEP_TIME=1 + WaitForTaskCompletion $! 0 $MAX_WAIT ${FUNCNAME[0]} true 0 true retval=$? + SLEEP_TIME=$sleepTime if [ $retval == 0 ]; then Logger "#### Changes detected, waiting $MIN_WAIT seconds before running next sync." "NOTICE" sleep $MIN_WAIT diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index 87b73a0..511e969 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -1,6 +1,6 @@ #### MINIMAL-FUNCTION-SET BEGIN #### -## FUNC_BUILD=2016112103 +## FUNC_BUILD=2016112104 ## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## To use in a program, define the following variables: @@ -578,9 +578,10 @@ function WaitForTaskCompletion { local callerName="${4}" # Who called this function local counting="${5:-true}" # Count time since function has been launched if true, since script has been launched if false local keepLogging="${6:-0}" # Log a standby message every X seconds. Set to zero to disable logging + local noError="${7:-false}" # When set to true, reaching soft or hard max time does not trigger an error Logger "${FUNCNAME[0]} called by [$callerName]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG - __CheckArguments 6 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG + __CheckArguments 6-7 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG local soft_alert=false # Does a soft alert need to be triggered, if yes, send an alert once local log_ttime=0 # local time instance for comparaison @@ -625,14 +626,16 @@ function WaitForTaskCompletion { fi if [ $exec_time -gt $softMaxTime ]; then - if [ $soft_alert == true ] && [ $softMaxTime -ne 0 ]; then + if [ $soft_alert == true ] && [ $softMaxTime -ne 0 ] && [ $noError != true ]; then Logger "Max soft execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]." "WARN" soft_alert=true SendAlert true fi if [ $exec_time -gt $hardMaxTime ] && [ $hardMaxTime -ne 0 ]; then - Logger "Max hard execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution." "ERROR" + if [ $noError != true ]; then + Logger "Max hard execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution." "ERROR" + fi for pid in "${pidsArray[@]}"; do KillChilds $pid true if [ $? == 0 ]; then @@ -641,7 +644,9 @@ function WaitForTaskCompletion { Logger "Could not stop task with pid [$pid]." "ERROR" fi done - SendAlert true + if [ $noError != true ]; then + SendAlert true + fi fi fi