Rebuilt targets

v1.1-maint
deajan 7 years ago
parent 063eca84e4
commit 60c6657ba8

@ -3,11 +3,11 @@
PROGRAM="osync" # Rsync based two way sync engine with fault tolerance PROGRAM="osync" # Rsync based two way sync engine with fault tolerance
AUTHOR="(C) 2013-2016 by Orsiris de Jong" AUTHOR="(C) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION=1.1.5 PROGRAM_VERSION=1.1.6-beta
PROGRAM_BUILD=2016111701 PROGRAM_BUILD=2016113001
IS_STABLE=yes IS_STABLE=yes
## FUNC_BUILD=2016071902-g ## 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 ## 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
@ -24,6 +24,9 @@ KEEP_LOGGING=1801
## Correct output of sort command (language agnostic sorting) ## Correct output of sort command (language agnostic sorting)
export LC_ALL=C export LC_ALL=C
## Default umask for file creation
umask 0077
# Standard alert mail body # Standard alert mail body
MAIL_ALERT_MSG="Execution of $PROGRAM instance $INSTANCE_ID on $(date) has warnings/errors." MAIL_ALERT_MSG="Execution of $PROGRAM instance $INSTANCE_ID on $(date) has warnings/errors."
@ -47,14 +50,16 @@ fi #__WITH_PARANOIA_DEBUG
## allow debugging from command line with _DEBUG=yes ## allow debugging from command line with _DEBUG=yes
if [ ! "$_DEBUG" == "yes" ]; then if [ ! "$_DEBUG" == "yes" ]; then
_DEBUG=no _DEBUG=no
SLEEP_TIME=.1
_VERBOSE=0 _VERBOSE=0
else else
SLEEP_TIME=1
trap 'TrapError ${LINENO} $?' ERR trap 'TrapError ${LINENO} $?' ERR
_VERBOSE=1 _VERBOSE=1
fi fi
if [ "$SLEEP_TIME" == "" ]; then
SLEEP_TIME=.1
fi
SCRIPT_PID=$$ SCRIPT_PID=$$
LOCAL_USER=$(whoami) LOCAL_USER=$(whoami)
@ -182,33 +187,52 @@ function QuickLogger {
# Portable child (and grandchild) kill function tester under Linux, BSD and MacOS X # Portable child (and grandchild) kill function tester under Linux, BSD and MacOS X
function KillChilds { function KillChilds {
local pid="${1}" local pid="${1}" # Parent pid to kill childs
local self="${2:-false}" local self="${2:-false}" # Should parent be killed too ?
if children="$(pgrep -P "$pid")"; then # Paranoid checks, we can safely assume that $pid shouldn't be 0 nor 1
for child in $children; do if [ $(IsNumeric "$pid") -eq 0 ] || [ "$pid" == "" ] || [ "$pid" == "0" ] || [ "$pid" == "1" ]; then
Logger "Launching KillChilds \"$child\" true" "DEBUG" #__WITH_PARANOIA_DEBUG Logger "Bogus pid given [$pid]." "CRITICAL"
KillChilds "$child" true return 1
done fi
fi
if kill -0 "$pid" > /dev/null 2>&1; then
# Try to kill nicely, if not, wait 15 seconds to let Trap actions happen before killing # Warning: pgrep is not native on cygwin, have this checked in CheckEnvironment
if ( [ "$self" == true ] && eval $PROCESS_TEST_CMD > /dev/null 2>&1); then if children="$(pgrep -P "$pid")"; then
Logger "Sending SIGTERM to process [$pid]." "DEBUG" if [[ "$pid" == *"$children"* ]]; then
kill -s SIGTERM "$pid" Logger "Bogus pgrep implementation." "CRITICAL"
if [ $? != 0 ]; then children="${children/$pid/}"
sleep 15 fi
Logger "Sending SIGTERM to process [$pid] failed." "DEBUG" for child in $children; do
kill -9 "$pid" Logger "Launching KillChilds \"$child\" true" "DEBUG" #__WITH_PARANOIA_DEBUG
if [ $? != 0 ]; then KillChilds "$child" true
Logger "Sending SIGKILL to process [$pid] failed." "DEBUG" done
return 1 fi
fi fi
fi
return 0 # Try to kill nicely, if not, wait 15 seconds to let Trap actions happen before killing
else if [ "$self" == true ]; then
return 0 # We need to check for pid again because it may have disappeared after recursive function call
fi 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 # osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
@ -773,10 +797,10 @@ function WaitForTaskCompletion {
KillChilds $pid KillChilds $pid
if [ $? == 0 ]; then if [ $? == 0 ]; then
Logger "Task stopped successfully" "NOTICE" Logger "Task stopped successfully" "NOTICE"
return 0
else else
return 1 Logger "Could not stop task" "ERROR"
fi fi
return 1
fi fi
fi fi
sleep $SLEEP_TIME sleep $SLEEP_TIME
@ -823,10 +847,16 @@ function WaitForCompletion {
KillChilds $pid KillChilds $pid
if [ $? == 0 ]; then if [ $? == 0 ]; then
Logger "Task stopped successfully" "NOTICE" Logger "Task stopped successfully" "NOTICE"
return 0
else else
return 1 Logger "Could not stop task" "ERROR"
fi fi
return 1
#if [ $? == 0 ]; then
# Logger "Task stopped successfully" "NOTICE"
# return 0
#else
# return 1
#fi
fi fi
fi fi
sleep $SLEEP_TIME sleep $SLEEP_TIME
@ -1208,9 +1238,9 @@ function PostInit {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
# Define remote commands # Define remote commands
SSH_CMD="$(type -p ssh) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS $REMOTE_USER@$REMOTE_HOST -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 -i $SSH_RSA_PRIVATE_KEY -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 -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS -p $REMOTE_PORT" RSYNC_SSH_CMD="$(type -p ssh) $SSH_COMP -q -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS -p $REMOTE_PORT"
} }
function InitLocalOSSettings { function InitLocalOSSettings {
@ -1289,7 +1319,7 @@ function TrapStop {
} }
function TrapQuit { function TrapQuit {
local exitcode= local exitcode
# Get ERROR / WARN alert flags from subprocesses that call Logger # Get ERROR / WARN alert flags from subprocesses that call Logger
if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID" ]; then if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID" ]; then
@ -2913,7 +2943,6 @@ do
;; ;;
--initiator=*) --initiator=*)
_QUICK_SYNC=$(($_QUICK_SYNC + 1)) _QUICK_SYNC=$(($_QUICK_SYNC + 1))
no_maxtime=1
INITIATOR_SYNC_DIR=${i##*=} INITIATOR_SYNC_DIR=${i##*=}
opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\"" opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\""
;; ;;
@ -2921,7 +2950,6 @@ do
_QUICK_SYNC=$(($_QUICK_SYNC + 1)) _QUICK_SYNC=$(($_QUICK_SYNC + 1))
TARGET_SYNC_DIR=${i##*=} TARGET_SYNC_DIR=${i##*=}
opts=$opts" --target=\"$TARGET_SYNC_DIR\"" opts=$opts" --target=\"$TARGET_SYNC_DIR\""
no_maxtime=1
;; ;;
--rsakey=*) --rsakey=*)
SSH_RSA_PRIVATE_KEY=${i##*=} SSH_RSA_PRIVATE_KEY=${i##*=}
@ -3033,7 +3061,7 @@ opts="${opts# *}"
GetRemoteOS GetRemoteOS
InitRemoteOSSettings InitRemoteOSSettings
if [ $no_maxtime -eq 1 ]; then if [ $no_maxtime -eq 1 ] ; then
SOFT_MAX_EXEC_TIME=0 SOFT_MAX_EXEC_TIME=0
HARD_MAX_EXEC_TIME=0 HARD_MAX_EXEC_TIME=0
fi fi

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
PROGRAM=osync PROGRAM=osync
PROGRAM_VERSION=1.1.5 PROGRAM_VERSION=1.1.6-beta
PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh" PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2016082902 SCRIPT_BUILD=2016082902

@ -3,11 +3,11 @@
PROGRAM="osync" # Rsync based two way sync engine with fault tolerance PROGRAM="osync" # Rsync based two way sync engine with fault tolerance
AUTHOR="(C) 2013-2016 by Orsiris de Jong" AUTHOR="(C) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION=1.1.5 PROGRAM_VERSION=1.1.6-beta
PROGRAM_BUILD=2016111701 PROGRAM_BUILD=2016113001
IS_STABLE=yes IS_STABLE=yes
## FUNC_BUILD=2016071902-g ## 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 ## 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
@ -24,6 +24,9 @@ KEEP_LOGGING=1801
## Correct output of sort command (language agnostic sorting) ## Correct output of sort command (language agnostic sorting)
export LC_ALL=C export LC_ALL=C
## Default umask for file creation
umask 0077
# Standard alert mail body # Standard alert mail body
MAIL_ALERT_MSG="Execution of $PROGRAM instance $INSTANCE_ID on $(date) has warnings/errors." MAIL_ALERT_MSG="Execution of $PROGRAM instance $INSTANCE_ID on $(date) has warnings/errors."
@ -43,14 +46,16 @@ WARN_ALERT=0
## allow debugging from command line with _DEBUG=yes ## allow debugging from command line with _DEBUG=yes
if [ ! "$_DEBUG" == "yes" ]; then if [ ! "$_DEBUG" == "yes" ]; then
_DEBUG=no _DEBUG=no
SLEEP_TIME=.1
_VERBOSE=0 _VERBOSE=0
else else
SLEEP_TIME=1
trap 'TrapError ${LINENO} $?' ERR trap 'TrapError ${LINENO} $?' ERR
_VERBOSE=1 _VERBOSE=1
fi fi
if [ "$SLEEP_TIME" == "" ]; then
SLEEP_TIME=.1
fi
SCRIPT_PID=$$ SCRIPT_PID=$$
LOCAL_USER=$(whoami) LOCAL_USER=$(whoami)
@ -172,32 +177,51 @@ function QuickLogger {
# Portable child (and grandchild) kill function tester under Linux, BSD and MacOS X # Portable child (and grandchild) kill function tester under Linux, BSD and MacOS X
function KillChilds { function KillChilds {
local pid="${1}" local pid="${1}" # Parent pid to kill childs
local self="${2:-false}" local self="${2:-false}" # Should parent be killed too ?
if children="$(pgrep -P "$pid")"; then # Paranoid checks, we can safely assume that $pid shouldn't be 0 nor 1
for child in $children; do if [ $(IsNumeric "$pid") -eq 0 ] || [ "$pid" == "" ] || [ "$pid" == "0" ] || [ "$pid" == "1" ]; then
KillChilds "$child" true Logger "Bogus pid given [$pid]." "CRITICAL"
done return 1
fi fi
# Try to kill nicely, if not, wait 15 seconds to let Trap actions happen before killing if kill -0 "$pid" > /dev/null 2>&1; then
if ( [ "$self" == true ] && eval $PROCESS_TEST_CMD > /dev/null 2>&1); then # Warning: pgrep is not native on cygwin, have this checked in CheckEnvironment
Logger "Sending SIGTERM to process [$pid]." "DEBUG" if children="$(pgrep -P "$pid")"; then
kill -s SIGTERM "$pid" if [[ "$pid" == *"$children"* ]]; then
if [ $? != 0 ]; then Logger "Bogus pgrep implementation." "CRITICAL"
sleep 15 children="${children/$pid/}"
Logger "Sending SIGTERM to process [$pid] failed." "DEBUG" fi
kill -9 "$pid" for child in $children; do
if [ $? != 0 ]; then KillChilds "$child" true
Logger "Sending SIGKILL to process [$pid] failed." "DEBUG" done
return 1 fi
fi fi
fi
return 0 # Try to kill nicely, if not, wait 15 seconds to let Trap actions happen before killing
else if [ "$self" == true ]; then
return 0 # We need to check for pid again because it may have disappeared after recursive function call
fi 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 # osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
@ -754,10 +778,10 @@ function WaitForTaskCompletion {
KillChilds $pid KillChilds $pid
if [ $? == 0 ]; then if [ $? == 0 ]; then
Logger "Task stopped successfully" "NOTICE" Logger "Task stopped successfully" "NOTICE"
return 0
else else
return 1 Logger "Could not stop task" "ERROR"
fi fi
return 1
fi fi
fi fi
sleep $SLEEP_TIME sleep $SLEEP_TIME
@ -801,10 +825,16 @@ function WaitForCompletion {
KillChilds $pid KillChilds $pid
if [ $? == 0 ]; then if [ $? == 0 ]; then
Logger "Task stopped successfully" "NOTICE" Logger "Task stopped successfully" "NOTICE"
return 0
else else
return 1 Logger "Could not stop task" "ERROR"
fi fi
return 1
#if [ $? == 0 ]; then
# Logger "Task stopped successfully" "NOTICE"
# return 0
#else
# return 1
#fi
fi fi
fi fi
sleep $SLEEP_TIME sleep $SLEEP_TIME
@ -1136,9 +1166,9 @@ function PreInit {
function PostInit { function PostInit {
# Define remote commands # Define remote commands
SSH_CMD="$(type -p ssh) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS $REMOTE_USER@$REMOTE_HOST -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 -i $SSH_RSA_PRIVATE_KEY -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 -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS -p $REMOTE_PORT" RSYNC_SSH_CMD="$(type -p ssh) $SSH_COMP -q -i $SSH_RSA_PRIVATE_KEY $SSH_OPTS -p $REMOTE_PORT"
} }
function InitLocalOSSettings { function InitLocalOSSettings {
@ -1215,7 +1245,7 @@ function TrapStop {
} }
function TrapQuit { function TrapQuit {
local exitcode= local exitcode
# Get ERROR / WARN alert flags from subprocesses that call Logger # Get ERROR / WARN alert flags from subprocesses that call Logger
if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID" ]; then if [ -f "$RUN_DIR/$PROGRAM.Logger.warn.$SCRIPT_PID" ]; then
@ -2802,7 +2832,6 @@ do
;; ;;
--initiator=*) --initiator=*)
_QUICK_SYNC=$(($_QUICK_SYNC + 1)) _QUICK_SYNC=$(($_QUICK_SYNC + 1))
no_maxtime=1
INITIATOR_SYNC_DIR=${i##*=} INITIATOR_SYNC_DIR=${i##*=}
opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\"" opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\""
;; ;;
@ -2810,7 +2839,6 @@ do
_QUICK_SYNC=$(($_QUICK_SYNC + 1)) _QUICK_SYNC=$(($_QUICK_SYNC + 1))
TARGET_SYNC_DIR=${i##*=} TARGET_SYNC_DIR=${i##*=}
opts=$opts" --target=\"$TARGET_SYNC_DIR\"" opts=$opts" --target=\"$TARGET_SYNC_DIR\""
no_maxtime=1
;; ;;
--rsakey=*) --rsakey=*)
SSH_RSA_PRIVATE_KEY=${i##*=} SSH_RSA_PRIVATE_KEY=${i##*=}
@ -2922,7 +2950,7 @@ opts="${opts# *}"
GetRemoteOS GetRemoteOS
InitRemoteOSSettings InitRemoteOSSettings
if [ $no_maxtime -eq 1 ]; then if [ $no_maxtime -eq 1 ] ; then
SOFT_MAX_EXEC_TIME=0 SOFT_MAX_EXEC_TIME=0
HARD_MAX_EXEC_TIME=0 HARD_MAX_EXEC_TIME=0
fi fi

Loading…
Cancel
Save