Updated waitfortaskcompletion kill functionality

This commit is contained in:
deajan 2016-08-16 20:39:13 +02:00
parent 4e95245374
commit c822c6e3eb
1 changed files with 17 additions and 14 deletions

View File

@ -1,6 +1,6 @@
#### MINIMAL-FUNCTION-SET BEGIN #### #### MINIMAL-FUNCTION-SET BEGIN ####
## FUNC_BUILD=2016081501 ## FUNC_BUILD=2016081602
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
@ -576,9 +576,10 @@ function WaitForTaskCompletion {
local caller_name="${4}" # Who called this function local caller_name="${4}" # Who called this function
local exit_on_error="${5:-false}" # Should the function exit on subprocess errors local exit_on_error="${5:-false}" # Should the function exit on subprocess errors
local counting="${6:-true}" # Count time since function launch if true, script launch if false local counting="${6:-true}" # Count time since function launch if true, script launch if false
local keep_logging="${7:-0}" # Log a standby message every X seconds. Set to zero to disable logging
Logger "${FUNCNAME[0]} called by [$caller_name]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG Logger "${FUNCNAME[0]} called by [$caller_name]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG
__CheckArguments 6 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 7 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local soft_alert=0 # Does a soft alert need to be triggered, if yes, send an alert once local soft_alert=0 # Does a soft alert need to be triggered, if yes, send an alert once
local log_ttime=0 # local time instance for comparaison local log_ttime=0 # local time instance for comparaison
@ -597,8 +598,6 @@ function WaitForTaskCompletion {
WAIT_FOR_TASK_COMPLETION="" WAIT_FOR_TASK_COMPLETION=""
#TODO: need to find a way to properly handle processes in unterruptible sleep state
while [ ${#pidsArray[@]} -gt 0 ]; do while [ ${#pidsArray[@]} -gt 0 ]; do
newPidsArray=() newPidsArray=()
for pid in "${pidsArray[@]}"; do for pid in "${pidsArray[@]}"; do
@ -631,10 +630,12 @@ function WaitForTaskCompletion {
exec_time=$SECONDS exec_time=$SECONDS
fi fi
if [ $((($exec_time + 1) % $KEEP_LOGGING)) -eq 0 ]; then if [ $keep_logging -ne 0 ]; then
if [ $log_ttime -ne $exec_time ]; then if [ $((($exec_time + 1) % $keep_logging)) -eq 0 ]; then
log_ttime=$exec_time if [ $log_ttime -ne $exec_time ]; then # Fix when sleep time lower than 1s
Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE" log_ttime=$exec_time
Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
fi
fi fi
fi fi
@ -647,12 +648,14 @@ function WaitForTaskCompletion {
fi fi
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
Logger "Max hard execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution." "ERROR" Logger "Max hard execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution." "ERROR"
KillChilds $pid for pid in "${pidsArray[@]}"; do
if [ $? == 0 ]; then KillChilds $pid
Logger "Task stopped successfully." "NOTICE" if [ $? == 0 ]; then
else Logger "Task with pid [$pid] stopped successfully." "NOTICE"
Logger "Could not stop task." "ERROR" else
fi Logger "Could not stop task with pid [$pid]." "ERROR"
fi
done
SendAlert SendAlert
errrorcount=$((errorcount+1)) errrorcount=$((errorcount+1))
fi fi