mirror of
https://github.com/deajan/obackup.git
synced 2024-12-26 15:33:41 +01:00
Updated ofunctions
This commit is contained in:
parent
8cef797979
commit
a6f52125b0
@ -1,6 +1,6 @@
|
|||||||
#### MINIMAL-FUNCTION-SET BEGIN ####
|
#### MINIMAL-FUNCTION-SET BEGIN ####
|
||||||
|
|
||||||
## FUNC_BUILD=2016082901
|
## FUNC_BUILD=2016083003
|
||||||
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## 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:
|
## To use in a program, define the following variables:
|
||||||
@ -34,7 +34,7 @@ ERROR_ALERT=false
|
|||||||
WARN_ALERT=false
|
WARN_ALERT=false
|
||||||
|
|
||||||
# Log from current run
|
# Log from current run
|
||||||
CURRENT_LOG=
|
CURRENT_LOG=""
|
||||||
|
|
||||||
## allow function call checks #__WITH_PARANOIA_DEBUG
|
## allow function call checks #__WITH_PARANOIA_DEBUG
|
||||||
if [ "$_PARANOIA_DEBUG" == "yes" ];then #__WITH_PARANOIA_DEBUG
|
if [ "$_PARANOIA_DEBUG" == "yes" ];then #__WITH_PARANOIA_DEBUG
|
||||||
@ -142,8 +142,10 @@ function Logger {
|
|||||||
elif [ "$level" == "NOTICE" ]; then
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
_Logger "$prefix$value"
|
_Logger "$prefix$value"
|
||||||
return
|
return
|
||||||
elif [ "$level" == "VERBOSE" ] && [ $_VERBOSE == true ]; then
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
|
if [ $_VERBOSE == true ]; then
|
||||||
_Logger "$prefix$value"
|
_Logger "$prefix$value"
|
||||||
|
fi
|
||||||
return
|
return
|
||||||
elif [ "$level" == "DEBUG" ]; then
|
elif [ "$level" == "DEBUG" ]; then
|
||||||
if [ "$_DEBUG" == "yes" ]; then
|
if [ "$_DEBUG" == "yes" ]; then
|
||||||
@ -156,7 +158,7 @@ function Logger {
|
|||||||
return #__WITH_PARANOIA_DEBUG
|
return #__WITH_PARANOIA_DEBUG
|
||||||
fi #__WITH_PARANOIA_DEBUG
|
fi #__WITH_PARANOIA_DEBUG
|
||||||
else
|
else
|
||||||
_Logger "\e[41mLogger function called without proper loglevel.\e[0m"
|
_Logger "\e[41mLogger function called without proper loglevel [$level].\e[0m"
|
||||||
_Logger "$prefix$value"
|
_Logger "$prefix$value"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -611,7 +613,7 @@ function WaitForTaskCompletion {
|
|||||||
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 6 $# ${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=false # 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
|
||||||
|
|
||||||
local seconds_begin=$SECONDS # Seconds since the beginning of the script
|
local seconds_begin=$SECONDS # Seconds since the beginning of the script
|
||||||
@ -627,6 +629,8 @@ function WaitForTaskCompletion {
|
|||||||
local pidsArray # Array of currently running pids
|
local pidsArray # Array of currently running pids
|
||||||
local newPidsArray # New array of currently running pids
|
local newPidsArray # New array of currently running pids
|
||||||
|
|
||||||
|
local hasPids=false # Are any valable pids given to function ? #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
IFS=';' read -a pidsArray <<< "$pids"
|
IFS=';' read -a pidsArray <<< "$pids"
|
||||||
pidCount=${#pidsArray[@]}
|
pidCount=${#pidsArray[@]}
|
||||||
|
|
||||||
@ -652,9 +656,9 @@ function WaitForTaskCompletion {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $exec_time -gt $soft_max_time ]; then
|
if [ $exec_time -gt $soft_max_time ]; then
|
||||||
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
if [ $soft_alert == true ] && [ $soft_max_time -ne 0 ]; then
|
||||||
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
|
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
|
||||||
soft_alert=1
|
soft_alert=true
|
||||||
SendAlert true
|
SendAlert true
|
||||||
|
|
||||||
fi
|
fi
|
||||||
@ -674,6 +678,7 @@ function WaitForTaskCompletion {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for pid in "${pidsArray[@]}"; do
|
for pid in "${pidsArray[@]}"; do
|
||||||
|
if [ $(IsNumeric $pid) -eq 1 ]; then
|
||||||
if kill -0 $pid > /dev/null 2>&1; then
|
if kill -0 $pid > /dev/null 2>&1; then
|
||||||
# Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :)
|
# Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :)
|
||||||
#TODO(high): have this tested on *BSD, Mac & Win
|
#TODO(high): have this tested on *BSD, Mac & Win
|
||||||
@ -695,8 +700,14 @@ function WaitForTaskCompletion {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
hasPids=true ##__WITH_PARANOIA_DEBUG
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ $hasPids == false ]; then ##__WITH_PARANOIA_DEBUG
|
||||||
|
Logger "No valable pids given." "ERROR" ##__WITH_PARANOIA_DEBUG
|
||||||
|
fi ##__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
pidsArray=("${newPidsArray[@]}")
|
pidsArray=("${newPidsArray[@]}")
|
||||||
# Trivial wait time for bash to not eat up all CPU
|
# Trivial wait time for bash to not eat up all CPU
|
||||||
sleep $SLEEP_TIME
|
sleep $SLEEP_TIME
|
||||||
@ -729,6 +740,8 @@ function ParallelExec {
|
|||||||
local pidState
|
local pidState
|
||||||
local commandsArrayPid
|
local commandsArrayPid
|
||||||
|
|
||||||
|
local hasPids=false # Are any valable pids given to function ? #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
IFS=';' read -r -a commandsArray <<< "$commandsArg"
|
IFS=';' read -r -a commandsArray <<< "$commandsArg"
|
||||||
|
|
||||||
Logger "Runnning ${#commandsArray[@]} commands in $numberOfProcesses simultaneous processes." "DEBUG"
|
Logger "Runnning ${#commandsArray[@]} commands in $numberOfProcesses simultaneous processes." "DEBUG"
|
||||||
@ -747,6 +760,7 @@ function ParallelExec {
|
|||||||
|
|
||||||
newPidsArray=()
|
newPidsArray=()
|
||||||
for pid in "${pidsArray[@]}"; do
|
for pid in "${pidsArray[@]}"; do
|
||||||
|
if [ $(IsNumeric $pid) -eq 1 ]; then
|
||||||
# Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :)
|
# Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :)
|
||||||
if kill -0 $pid > /dev/null 2>&1; then
|
if kill -0 $pid > /dev/null 2>&1; then
|
||||||
pidState=$(ps -p$pid -o state= 2 > /dev/null)
|
pidState=$(ps -p$pid -o state= 2 > /dev/null)
|
||||||
@ -762,7 +776,13 @@ function ParallelExec {
|
|||||||
retvalAll=$((retvalAll+1))
|
retvalAll=$((retvalAll+1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
hasPids=true ##__WITH_PARANOIA_DEBUG
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ $hasPids == false ]; then ##__WITH_PARANOIA_DEBUG
|
||||||
|
Logger "No valable pids given." "ERROR" ##__WITH_PARANOIA_DEBUG
|
||||||
|
fi ##__WITH_PARANOIA_DEBUG
|
||||||
pidsArray=("${newPidsArray[@]}")
|
pidsArray=("${newPidsArray[@]}")
|
||||||
|
|
||||||
# Trivial wait time for bash to not eat up all CPU
|
# Trivial wait time for bash to not eat up all CPU
|
||||||
|
Loading…
Reference in New Issue
Block a user