More ExecTasks fixes

This commit is contained in:
deajan 2018-01-03 17:40:29 +01:00
parent ebf8b106d5
commit 328a07e406
1 changed files with 9 additions and 9 deletions

View File

@ -3,7 +3,7 @@
#### OFUNCTIONS MINI SUBSET #### #### OFUNCTIONS MINI SUBSET ####
_OFUNCTIONS_VERSION=2.2.0-dev _OFUNCTIONS_VERSION=2.2.0-dev
_OFUNCTIONS_BUILD=2018010302 _OFUNCTIONS_BUILD=2018010303
#### _OFUNCTIONS_BOOTSTRAP SUBSET #### #### _OFUNCTIONS_BOOTSTRAP SUBSET ####
_OFUNCTIONS_BOOTSTRAP=true _OFUNCTIONS_BOOTSTRAP=true
#### _OFUNCTIONS_BOOTSTRAP SUBSET END #### #### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
@ -740,6 +740,8 @@ function ParallelExec {
# conditions="[ -d /var ];[ -d /etc ];[ -d /home];[ -d /usr]" # conditions="[ -d /var ];[ -d /etc ];[ -d /home];[ -d /usr]"
# ExecTasks "some_identifier" 0 0 300 900 1 1800 true true false false 4 "$commands" "$conditions" 3 # ExecTasks "some_identifier" 0 0 300 900 1 1800 true true false false 4 "$commands" "$conditions" 3
# ParallelExecMode also creates output for commands in "$RUN_DIR/$PROGRAM.ExecTasks.$id.$SCRIPT_PID.$TSTAMP"
## ofunctions.sh subfunction requirements: ## ofunctions.sh subfunction requirements:
## Spinner ## Spinner
## Logger ## Logger
@ -767,8 +769,6 @@ function ExecTasks {
local i local i
local callerName="${FUNCNAME[1]}"
Logger "${FUNCNAME[0]} called in $execTasksMode mode by [${FUNCNAME[0]} < ${FUNCNAME[1]} < ${FUNCNAME[2]} < ${FUNCNAME[3]} < ${FUNCNAME[4]} ...]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG Logger "${FUNCNAME[0]} called in $execTasksMode mode by [${FUNCNAME[0]} < ${FUNCNAME[1]} < ${FUNCNAME[2]} < ${FUNCNAME[3]} < ${FUNCNAME[4]} ...]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG
__CheckArguments 13-15 $# "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 13-15 $# "$@" #__WITH_PARANOIA_DEBUG
@ -953,7 +953,7 @@ function ExecTasks {
if [ $exec_time -gt $softMaxTime ]; then if [ $exec_time -gt $softMaxTime ]; then
if [ "$softAlert" != true ] && [ $softMaxTime -ne 0 ] && [ $noTimeErrorLog != true ]; then if [ "$softAlert" != true ] && [ $softMaxTime -ne 0 ] && [ $noTimeErrorLog != true ]; then
Logger "Max soft execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]." "WARN" Logger "Max soft execution time exceeded for task [$id] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
softAlert=true softAlert=true
SendAlert true SendAlert true
fi fi
@ -961,7 +961,7 @@ function ExecTasks {
if [ $exec_time -gt $hardMaxTime ] && [ $hardMaxTime -ne 0 ]; then if [ $exec_time -gt $hardMaxTime ] && [ $hardMaxTime -ne 0 ]; then
if [ $noTimeErrorLog != true ]; then if [ $noTimeErrorLog != true ]; then
Logger "Max hard execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution." "ERROR" Logger "Max hard execution time exceeded for task [$id] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution." "ERROR"
fi fi
for pid in "${pidsArray[@]}"; do for pid in "${pidsArray[@]}"; do
KillChilds $pid true KillChilds $pid true
@ -1030,7 +1030,7 @@ function ExecTasks {
if [ $executeCommand == true ]; then if [ $executeCommand == true ]; then
Logger "Running command [$currentCommand]." "DEBUG" Logger "Running command [$currentCommand]." "DEBUG"
eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$callerName.$SCRIPT_PID.$TSTAMP" 2>&1 & eval "$currentCommand" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$id.$SCRIPT_PID.$TSTAMP" 2>&1 &
pid=$! pid=$!
pidsArray+=($pid) pidsArray+=($pid)
commandsArrayPid[$pid]="$currentCommand" commandsArrayPid[$pid]="$currentCommand"
@ -1057,7 +1057,7 @@ function ExecTasks {
wait $pid wait $pid
retval=$? retval=$?
if [ $retval -ne 0 ]; then if [ $retval -ne 0 ]; then
Logger "${FUNCNAME[0]} called by [$callerName] finished monitoring [$pid] [$currentCommad] with exitcode [$retval]." "DEBUG" Logger "${FUNCNAME[0]} called by [$id] finished monitoring [$pid] [$currentCommad] with exitcode [$retval]." "DEBUG"
errorcount=$((errorcount+1)) errorcount=$((errorcount+1))
# Welcome to variable variable bash hell # Welcome to variable variable bash hell
if [ "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_$id\")" == "" ]; then if [ "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_$id\")" == "" ]; then
@ -1066,7 +1066,7 @@ function ExecTasks {
eval "WAIT_FOR_TASK_COMPLETION_$id=\";$pid:$retval\"" eval "WAIT_FOR_TASK_COMPLETION_$id=\";$pid:$retval\""
fi fi
else else
Logger "${FUNCNAME[0]} called by [$callerName] finished monitoring [$pid] [$currentCommand] with exitcode [$retval]." "DEBUG" Logger "${FUNCNAME[0]} called by [$id] finished monitoring [$pid] [$currentCommand] with exitcode [$retval]." "DEBUG"
fi fi
fi fi
hasPids=true ##__WITH_PARANOIA_DEBUG hasPids=true ##__WITH_PARANOIA_DEBUG
@ -1086,7 +1086,7 @@ function ExecTasks {
fi ##__WITH_PARANOIA_DEBUG fi ##__WITH_PARANOIA_DEBUG
done done
Logger "${FUNCNAME[0]} ended for [$callerName] using [$mainItemCount] subprocesses with [$errorcount] errors." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG Logger "${FUNCNAME[0]} ended for [$id] using [$mainItemCount] subprocesses with [$errorcount] errors." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG
# Return exit code if only one process was monitored, else return number of errors # Return exit code if only one process was monitored, else return number of errors
# As we cannot return multiple values, a global variable WAIT_FOR_TASK_COMPLETION contains all pids with their return value # As we cannot return multiple values, a global variable WAIT_FOR_TASK_COMPLETION contains all pids with their return value