Rebuilt targets

This commit is contained in:
deajan 2016-08-08 15:49:48 +02:00
parent 93a5dbcf78
commit 81c9ddf202
2 changed files with 444 additions and 388 deletions

View File

@ -13,7 +13,7 @@ IS_STABLE=yes
#### MINIMAL-FUNCTION-SET BEGIN ####
## FUNC_BUILD=2016080702
## FUNC_BUILD=2016080805
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
#TODO: set _LOGGER_PREFIX in other apps, specially for osync daemon mode
@ -576,13 +576,19 @@ function Spinner {
esac
}
# Array to string converter, see http://stackoverflow.com/questions/1527049/bash-join-elements-of-an-array
# usage: joinString separaratorChar Array
function joinString {
local IFS="$1"; shift; echo "$*";
}
function WaitForTaskCompletion {
local pids="${1}" # pids to wait for, separated by semi-colon
local soft_max_time="${2}" # If program with pid $pid takes longer than $soft_max_time seconds, will log a warning, unless $soft_max_time equals 0.
local hard_max_time="${3}" # If program with pid $pid takes longer than $hard_max_time seconds, will stop execution, unless $hard_max_time equals 0.
local caller_name="${4}" # Who called this function
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
Logger "${FUNCNAME[0]} called by [$caller_name]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG
__CheckArguments 6 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
@ -626,25 +632,27 @@ function WaitForTaskCompletion {
if [ $((($exec_time + 1) % $KEEP_LOGGING)) -eq 0 ]; then
if [ $log_ttime -ne $exec_time ]; then
log_ttime=$exec_time
Logger "Current tasks still running with pids [${pidsArray[@]}]." "NOTICE"
Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
fi
fi
if [ $exec_time -gt $soft_max_time ]; then
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
Logger "Max soft execution time exceeded for task [$caller_name] with pids [${pidsArray[@]}]." "WARN"
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
soft_alert=1
SendAlert
fi
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 [${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
if [ $? == 0 ]; then
Logger "Task stopped successfully" "NOTICE"
Logger "Task stopped successfully." "NOTICE"
else
errrorcount=$((errorcount+1))
Logger "Could not stop task." "ERROR"
fi
SendAlert
errrorcount=$((errorcount+1))
fi
fi
@ -954,7 +962,7 @@ function CheckConnectivityRemoteHost {
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_OPERATION" != "no" ]; then
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
WaitForTaskCompletion $! 180 180 ${FUNCNAME[0]} false true
WaitForTaskCompletion $! 10 180 ${FUNCNAME[0]} false true
if [ $? != 0 ]; then
Logger "Cannot ping $REMOTE_HOST" "ERROR"
return 1
@ -966,6 +974,9 @@ function CheckConnectivityRemoteHost {
function CheckConnectivity3rdPartyHosts {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local remote_3rd_party_success
local pids
if [ "$_PARANOIA_DEBUG" != "yes" ]; then # Do not loose time in paranoia debug
if [ "$REMOTE_3RD_PARTY_HOSTS" != "" ]; then
@ -975,17 +986,26 @@ function CheckConnectivity3rdPartyHosts {
for i in $REMOTE_3RD_PARTY_HOSTS
do
eval "$PING_CMD $i > /dev/null 2>&1" &
WaitForTaskCompletion $! 360 360 ${FUNCNAME[0]} false true
if [ "$pids" == "" ]; then
pids="$!"
else
pids="$pids;$!"
fi
done
WaitForTaskCompletion $pids 10 360 ${FUNCNAME[0]} false true
if [ $? != 0 ]; then
Logger "Cannot ping 3rd party host $i" "NOTICE"
else
remote_3rd_party_success=1
fi
done
IFS=$OLD_IFS
if [ $remote_3rd_party_success -ne 1 ]; then
Logger "No remote 3rd party host responded to ping. No internet ?" "ERROR"
return 1
else
return 0
fi
fi
fi
@ -1037,7 +1057,7 @@ function RsyncPatternsAdd {
local pattern="${2}"
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local rest=
local rest
# Disable globbing so wildcards from exclusions do not get expanded
set -f
@ -1081,20 +1101,28 @@ function RsyncPatterns {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
if [ "$RSYNC_PATTERN_FIRST" == "exclude" ]; then
if [ "$RSYNC_EXCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "exclude" "$RSYNC_EXCLUDE_PATTERN"
fi
if [ "$RSYNC_EXCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "exclude" "$RSYNC_EXCLUDE_FROM"
fi
if [ "$RSYNC_INCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "$RSYNC_INCLUDE_PATTERN" "include"
fi
if [ "$RSYNC_INCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "include" "$RSYNC_INCLUDE_FROM"
fi
elif [ "$RSYNC_PATTERN_FIRST" == "include" ]; then
if [ "$RSYNC_INCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "include" "$RSYNC_INCLUDE_PATTERN"
fi
if [ "$RSYNC_INCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "include" "$RSYNC_INCLUDE_FROM"
fi
if [ "$RSYNC_EXCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "exclude" "$RSYNC_EXCLUDE_PATTERN"
fi
if [ "$RSYNC_EXCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "exclude" "$RSYNC_EXCLUDE_FROM"
fi

View File

@ -13,7 +13,7 @@ IS_STABLE=yes
#### MINIMAL-FUNCTION-SET BEGIN ####
## FUNC_BUILD=2016080702
## FUNC_BUILD=2016080805
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
#TODO: set _LOGGER_PREFIX in other apps, specially for osync daemon mode
@ -559,13 +559,19 @@ function Spinner {
esac
}
# Array to string converter, see http://stackoverflow.com/questions/1527049/bash-join-elements-of-an-array
# usage: joinString separaratorChar Array
function joinString {
local IFS="$1"; shift; echo "$*";
}
function WaitForTaskCompletion {
local pids="${1}" # pids to wait for, separated by semi-colon
local soft_max_time="${2}" # If program with pid $pid takes longer than $soft_max_time seconds, will log a warning, unless $soft_max_time equals 0.
local hard_max_time="${3}" # If program with pid $pid takes longer than $hard_max_time seconds, will stop execution, unless $hard_max_time equals 0.
local caller_name="${4}" # Who called this function
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 soft_alert=0 # Does a soft alert need to be triggered, if yes, send an alert once
@ -607,25 +613,27 @@ function WaitForTaskCompletion {
if [ $((($exec_time + 1) % $KEEP_LOGGING)) -eq 0 ]; then
if [ $log_ttime -ne $exec_time ]; then
log_ttime=$exec_time
Logger "Current tasks still running with pids [${pidsArray[@]}]." "NOTICE"
Logger "Current tasks still running with pids [$(joinString , ${pidsArray[@]})]." "NOTICE"
fi
fi
if [ $exec_time -gt $soft_max_time ]; then
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
Logger "Max soft execution time exceeded for task [$caller_name] with pids [${pidsArray[@]}]." "WARN"
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
soft_alert=1
SendAlert
fi
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 [${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
if [ $? == 0 ]; then
Logger "Task stopped successfully" "NOTICE"
Logger "Task stopped successfully." "NOTICE"
else
errrorcount=$((errorcount+1))
Logger "Could not stop task." "ERROR"
fi
SendAlert
errrorcount=$((errorcount+1))
fi
fi
@ -926,7 +934,7 @@ function CheckConnectivityRemoteHost {
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_OPERATION" != "no" ]; then
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
WaitForTaskCompletion $! 180 180 ${FUNCNAME[0]} false true
WaitForTaskCompletion $! 10 180 ${FUNCNAME[0]} false true
if [ $? != 0 ]; then
Logger "Cannot ping $REMOTE_HOST" "ERROR"
return 1
@ -937,6 +945,9 @@ function CheckConnectivityRemoteHost {
function CheckConnectivity3rdPartyHosts {
local remote_3rd_party_success
local pids
if [ "$_PARANOIA_DEBUG" != "yes" ]; then # Do not loose time in paranoia debug
if [ "$REMOTE_3RD_PARTY_HOSTS" != "" ]; then
@ -946,17 +957,26 @@ function CheckConnectivity3rdPartyHosts {
for i in $REMOTE_3RD_PARTY_HOSTS
do
eval "$PING_CMD $i > /dev/null 2>&1" &
WaitForTaskCompletion $! 360 360 ${FUNCNAME[0]} false true
if [ "$pids" == "" ]; then
pids="$!"
else
pids="$pids;$!"
fi
done
WaitForTaskCompletion $pids 10 360 ${FUNCNAME[0]} false true
if [ $? != 0 ]; then
Logger "Cannot ping 3rd party host $i" "NOTICE"
else
remote_3rd_party_success=1
fi
done
IFS=$OLD_IFS
if [ $remote_3rd_party_success -ne 1 ]; then
Logger "No remote 3rd party host responded to ping. No internet ?" "ERROR"
return 1
else
return 0
fi
fi
fi
@ -969,7 +989,7 @@ function RsyncPatternsAdd {
local pattern_type="${1}" # exclude or include
local pattern="${2}"
local rest=
local rest
# Disable globbing so wildcards from exclusions do not get expanded
set -f
@ -1011,20 +1031,28 @@ function RsyncPatternsFromAdd {
function RsyncPatterns {
if [ "$RSYNC_PATTERN_FIRST" == "exclude" ]; then
if [ "$RSYNC_EXCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "exclude" "$RSYNC_EXCLUDE_PATTERN"
fi
if [ "$RSYNC_EXCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "exclude" "$RSYNC_EXCLUDE_FROM"
fi
if [ "$RSYNC_INCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "$RSYNC_INCLUDE_PATTERN" "include"
fi
if [ "$RSYNC_INCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "include" "$RSYNC_INCLUDE_FROM"
fi
elif [ "$RSYNC_PATTERN_FIRST" == "include" ]; then
if [ "$RSYNC_INCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "include" "$RSYNC_INCLUDE_PATTERN"
fi
if [ "$RSYNC_INCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "include" "$RSYNC_INCLUDE_FROM"
fi
if [ "$RSYNC_EXCLUDE_PATTERN" != "" ]; then
RsyncPatternsAdd "exclude" "$RSYNC_EXCLUDE_PATTERN"
fi
if [ "$RSYNC_EXCLUDE_FROM" != "" ]; then
RsyncPatternsFromAdd "exclude" "$RSYNC_EXCLUDE_FROM"
fi