|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
## FUNC_BUILD=2016071902-h
|
|
|
|
|
## FUNC_BUILD=2016071902-i
|
|
|
|
|
## 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
|
|
|
|
@ -15,6 +15,9 @@ KEEP_LOGGING=1801
|
|
|
|
|
## Correct output of sort command (language agnostic sorting)
|
|
|
|
|
export LC_ALL=C
|
|
|
|
|
|
|
|
|
|
## Default umask for file creation
|
|
|
|
|
umask 0077
|
|
|
|
|
|
|
|
|
|
# Standard alert mail body
|
|
|
|
|
MAIL_ALERT_MSG="Execution of $PROGRAM instance $INSTANCE_ID on $(date) has warnings/errors."
|
|
|
|
|
|
|
|
|
@ -175,33 +178,52 @@ function QuickLogger {
|
|
|
|
|
|
|
|
|
|
# Portable child (and grandchild) kill function tester under Linux, BSD and MacOS X
|
|
|
|
|
function KillChilds {
|
|
|
|
|
local pid="${1}"
|
|
|
|
|
local self="${2:-false}"
|
|
|
|
|
|
|
|
|
|
if children="$(pgrep -P "$pid")"; then
|
|
|
|
|
for child in $children; do
|
|
|
|
|
Logger "Launching KillChilds \"$child\" true" "DEBUG" #__WITH_PARANOIA_DEBUG
|
|
|
|
|
KillChilds "$child" true
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Try to kill nicely, if not, wait 15 seconds to let Trap actions happen before killing
|
|
|
|
|
if ( [ "$self" == true ] && eval $PROCESS_TEST_CMD > /dev/null 2>&1); then
|
|
|
|
|
Logger "Sending SIGTERM to process [$pid]." "DEBUG"
|
|
|
|
|
kill -s SIGTERM "$pid"
|
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
|
sleep 15
|
|
|
|
|
Logger "Sending SIGTERM to process [$pid] failed." "DEBUG"
|
|
|
|
|
kill -9 "$pid"
|
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
|
Logger "Sending SIGKILL to process [$pid] failed." "DEBUG"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
local pid="${1}" # Parent pid to kill childs
|
|
|
|
|
local self="${2:-false}" # Should parent be killed too ?
|
|
|
|
|
|
|
|
|
|
# Paranoid checks, we can safely assume that $pid shouldn't be 0 nor 1
|
|
|
|
|
if [ $(IsNumeric "$pid") -eq 0 ] || [ "$pid" == "" ] || [ "$pid" == "0" ] || [ "$pid" == "1" ]; then
|
|
|
|
|
Logger "Bogus pid given [$pid]." "CRITICAL"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if kill -0 "$pid" > /dev/null 2>&1; then
|
|
|
|
|
# Warning: pgrep is not native on cygwin, have this checked in CheckEnvironment
|
|
|
|
|
if children="$(pgrep -P "$pid")"; then
|
|
|
|
|
if [[ "$pid" == *"$children"* ]]; then
|
|
|
|
|
Logger "Bogus pgrep implementation." "CRITICAL"
|
|
|
|
|
children="${children/$pid/}"
|
|
|
|
|
fi
|
|
|
|
|
for child in $children; do
|
|
|
|
|
Logger "Launching KillChilds \"$child\" true" "DEBUG" #__WITH_PARANOIA_DEBUG
|
|
|
|
|
KillChilds "$child" true
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Try to kill nicely, if not, wait 15 seconds to let Trap actions happen before killing
|
|
|
|
|
if [ "$self" == true ]; then
|
|
|
|
|
# We need to check for pid again because it may have disappeared after recursive function call
|
|
|
|
|
if kill -0 "$pid" > /dev/null 2>&1; then
|
|
|
|
|
kill -s TERM "$pid"
|
|
|
|
|
Logger "Sent SIGTERM to process [$pid]." "DEBUG"
|
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
|
sleep 15
|
|
|
|
|
Logger "Sending SIGTERM to process [$pid] failed." "DEBUG"
|
|
|
|
|
kill -9 "$pid"
|
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
|
Logger "Sending SIGKILL to process [$pid] failed." "DEBUG"
|
|
|
|
|
return 1
|
|
|
|
|
fi # Simplify the return 0 logic here
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
|
|
|
|
@ -1207,9 +1229,9 @@ function PostInit {
|
|
|
|
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
|
|
|
|
|
|
|
|
|
# Define remote commands
|
|
|
|
|
SSH_CMD="$(type -p ssh) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT"
|
|
|
|
|
SCP_CMD="$(type -p scp) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY -P $REMOTE_PORT"
|
|
|
|
|
RSYNC_SSH_CMD="$(type -p ssh) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS -p $REMOTE_PORT"
|
|
|
|
|
SSH_CMD="$(type -p ssh) $SSH_COMP -q -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT"
|
|
|
|
|
SCP_CMD="$(type -p scp) $SSH_COMP -q -i $SSH_RSA_PRIVATE_KEY -P $REMOTE_PORT"
|
|
|
|
|
RSYNC_SSH_CMD="$(type -p ssh) $SSH_COMP -q -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS -p $REMOTE_PORT"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function InitLocalOSSettings {
|
|
|
|
|