WIP: fixing unlocking depending on lock success
This commit is contained in:
parent
c5f6874ad8
commit
7e51ad5497
|
@ -6,7 +6,7 @@ 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.2-dev-parallel
|
PROGRAM_VERSION=1.2-dev-parallel
|
||||||
PROGRAM_BUILD=2016082801
|
PROGRAM_BUILD=2016082802
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
# Function Name Is parallel #__WITH_PARANOIA_DEBUG
|
# Function Name Is parallel #__WITH_PARANOIA_DEBUG
|
||||||
|
@ -128,6 +128,24 @@ function CheckEnvironment {
|
||||||
function CheckCurrentConfig {
|
function CheckCurrentConfig {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
# Check all variables that should contain "yes" or "no"
|
||||||
|
declare -a yes_no_vars=(CREATE_DIRS SUDO_EXEC SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS REMOTE_HOST_PING PRESERVE_PERMISSIONS PRESERVE_OWNER PRESERVE_GROUP PRESERVE_EXECUTABILITY PRESERVE_ACL PRESERVE_XATTR COPY_SYMLINKS KEEP_DIRLINKS PRESERVE_HARDLINKS CHECKSUM RSYNC_COMPRESS CONFLICT_BACKUP CONFLICT_BACKUP_MULTIPLE SOFT_DELETE RESUME_SYNC FORCE_STRANGER_LOCK_RESUME PARTIAL DELTA_COPIES STOP_ON_CMD_ERROR RUN_AFTER_CMD_ON_ERROR)
|
||||||
|
for i in "${yes_no_vars[@]}"; do
|
||||||
|
test="if [ \"\$$i\" != \"yes\" ] && [ \"\$$i\" != \"no\" ]; then Logger \"Bogus $i value defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
|
||||||
|
eval "$test"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check all variables that should contain a numerical value >= 0
|
||||||
|
declare -a num_vars=(MINIMUM_SPACE BANDWIDTH SOFT_MAX_EXEC_TIME HARD_MAX_EXEC_TIME KEEP_LOGGING MIN_WAIT MAX_WAIT CONFLICT_BACKUP_DAYS SOFT_DELETE_DAYS RESUME_TRY MAX_EXEC_TIME_PER_CMD_BEFORE MAX_EXEC_TIME_PER_CMD_AFTER)
|
||||||
|
for i in "${num_vars[@]}"; do
|
||||||
|
test="if [ $(IsNumeric \"\$$i\") -eq 0 ]; then Logger \"Bogus $i value defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
|
||||||
|
eval "$test"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function CheckCurrentConfigAll {
|
||||||
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
if [ "$INSTANCE_ID" == "" ]; then
|
if [ "$INSTANCE_ID" == "" ]; then
|
||||||
Logger "No INSTANCE_ID defined in config file." "CRITICAL"
|
Logger "No INSTANCE_ID defined in config file." "CRITICAL"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -143,20 +161,6 @@ function CheckCurrentConfig {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check all variables that should contain "yes" or "no"
|
|
||||||
declare -a yes_no_vars=(CREATE_DIRS SUDO_EXEC SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS REMOTE_HOST_PING PRESERVE_PERMISSIONS PRESERVE_OWNER PRESERVE_GROUP PRESERVE_EXECUTABILITY PRESERVE_ACL PRESERVE_XATTR COPY_SYMLINKS KEEP_DIRLINKS PRESERVE_HARDLINKS CHECKSUM RSYNC_COMPRESS CONFLICT_BACKUP CONFLICT_BACKUP_MULTIPLE SOFT_DELETE RESUME_SYNC FORCE_STRANGER_LOCK_RESUME PARTIAL DELTA_COPIES STOP_ON_CMD_ERROR RUN_AFTER_CMD_ON_ERROR)
|
|
||||||
for i in "${yes_no_vars[@]}"; do
|
|
||||||
test="if [ \"\$$i\" != \"yes\" ] && [ \"\$$i\" != \"no\" ]; then Logger \"Bogus $i value defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
|
|
||||||
eval "$test"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Check all variables that should contain a numerical value >= 0
|
|
||||||
declare -a num_vars=(MINIMUM_SPACE BANDWIDTH SOFT_MAX_EXEC_TIME HARD_MAX_EXEC_TIME KEEP_LOGGING MIN_WAIT MAX_WAIT CONFLICT_BACKUP_DAYS SOFT_DELETE_DAYS RESUME_TRY MAX_EXEC_TIME_PER_CMD_BEFORE MAX_EXEC_TIME_PER_CMD_AFTER)
|
|
||||||
for i in "${num_vars[@]}"; do
|
|
||||||
test="if [ $(IsNumeric \"\$$i\") -eq 0 ]; then Logger \"Bogus $i value defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
|
|
||||||
eval "$test"
|
|
||||||
done
|
|
||||||
|
|
||||||
#TODO(low): Add runtime variable tests (RSYNC_ARGS etc)
|
#TODO(low): Add runtime variable tests (RSYNC_ARGS etc)
|
||||||
if [ "$REMOTE_OPERATION" == "yes" ] && [ ! -f "$SSH_RSA_PRIVATE_KEY" ]; then
|
if [ "$REMOTE_OPERATION" == "yes" ] && [ ! -f "$SSH_RSA_PRIVATE_KEY" ]; then
|
||||||
Logger "Cannot find rsa private key [$SSH_RSA_PRIVATE_KEY]. Cannot connect to remote system." "CRITICAL"
|
Logger "Cannot find rsa private key [$SSH_RSA_PRIVATE_KEY]. Cannot connect to remote system." "CRITICAL"
|
||||||
|
@ -499,6 +503,7 @@ function _WriteLockFilesRemote {
|
||||||
cmd=$SSH_CMD' "echo '$SCRIPT_PID@$INSTANCE_ID' | '$COMMAND_SUDO' tee \"'$lockfile'\"" > /dev/null 2>&1'
|
cmd=$SSH_CMD' "echo '$SCRIPT_PID@$INSTANCE_ID' | '$COMMAND_SUDO' tee \"'$lockfile'\"" > /dev/null 2>&1'
|
||||||
Logger "cmd: $cmd" "DEBUG"
|
Logger "cmd: $cmd" "DEBUG"
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
eval "mongo"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Could not set lock on remote $replica_type replica." "CRITICAL"
|
Logger "Could not set lock on remote $replica_type replica." "CRITICAL"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -510,23 +515,38 @@ function _WriteLockFilesRemote {
|
||||||
function WriteLockFiles {
|
function WriteLockFiles {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
local pids
|
local initiatorPid
|
||||||
|
local targetPid
|
||||||
|
local pidArray
|
||||||
|
local pid
|
||||||
|
|
||||||
_WriteLockFilesLocal "${INITIATOR[2]}" &
|
_WriteLockFilesLocal "${INITIATOR[2]}" &
|
||||||
pids="$!"
|
initiatorPid="$!"
|
||||||
|
|
||||||
if [ "$REMOTE_OPERATION" != "yes" ]; then
|
if [ "$REMOTE_OPERATION" != "yes" ]; then
|
||||||
_WriteLockFilesLocal "${TARGET[2]}" &
|
_WriteLockFilesLocal "${TARGET[2]}" &
|
||||||
pids="$pids;$!"
|
targetPid="$!"
|
||||||
else
|
else
|
||||||
_WriteLockFilesRemote "${TARGET[2]}" &
|
_WriteLockFilesRemote "${TARGET[2]}" &
|
||||||
pids="$pids;$!"
|
targetPid="$!"
|
||||||
fi
|
fi
|
||||||
WaitForTaskCompletion $pids 720 1800 ${FUNCNAME[0]} true $KEEP_LOGGING
|
|
||||||
|
WaitForTaskCompletion "$initiatorPid;$targetPid" 720 1800 ${FUNCNAME[0]} true $KEEP_LOGGING
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
IFS=';' read -r -a pidArray <<< "$WAIT_FOR_TASK_COMPLETION"
|
||||||
|
for pid in "${pidArray[@]}"; do
|
||||||
|
pid=${pid%:*}
|
||||||
|
if [ $pid == $initiatorPid ]; then
|
||||||
|
INITIATOR_LOCK_FILE_EXISTS=false
|
||||||
|
elif [ $pid == $targetPid ]; then
|
||||||
|
TARGET_LOCK_FILE_EXISTS=false
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
Logger "Cancelling task." "CRITICAL"
|
Logger "Cancelling task." "CRITICAL"
|
||||||
|
local
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
LOCK_FILES_EXIST=1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _UnlockReplicasLocal {
|
function _UnlockReplicasLocal {
|
||||||
|
@ -568,13 +588,17 @@ function UnlockReplicas {
|
||||||
|
|
||||||
local pids
|
local pids
|
||||||
|
|
||||||
if [ $_NOLOCKS -eq 1 ] || [ $LOCK_FILES_EXIST -eq 0 ]; then
|
if [ $_NOLOCKS -eq 1 ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $INITIATOR_LOCK_FILE_EXISTS == true ]; then
|
||||||
_UnlockReplicasLocal "${INITIATOR[2]}" &
|
_UnlockReplicasLocal "${INITIATOR[2]}" &
|
||||||
pids="$!"
|
pids="$!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#WIP check if WaitForTaskCompletion can handle emppty pids like ";pid"
|
||||||
|
if [ $TARGET_LOCK_FILE_EXISTS == true ]; then
|
||||||
if [ "$REMOTE_OPERATION" != "yes" ]; then
|
if [ "$REMOTE_OPERATION" != "yes" ]; then
|
||||||
_UnlockReplicasLocal "${TARGET[2]}" &
|
_UnlockReplicasLocal "${TARGET[2]}" &
|
||||||
pids="$pids;$!"
|
pids="$pids;$!"
|
||||||
|
@ -582,7 +606,11 @@ function UnlockReplicas {
|
||||||
_UnlockReplicasRemote "${TARGET[2]}" &
|
_UnlockReplicasRemote "${TARGET[2]}" &
|
||||||
pids="$pids;$!"
|
pids="$pids;$!"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$pids" != "" ]; then
|
||||||
WaitForTaskCompletion $pids 720 1800 ${FUNCNAME[0]} true $KEEP_LOGGING
|
WaitForTaskCompletion $pids 720 1800 ${FUNCNAME[0]} true $KEEP_LOGGING
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
###### Sync core functions
|
###### Sync core functions
|
||||||
|
@ -1817,7 +1845,10 @@ if [ "$CONFLICT_PREVALANCE" == "" ]; then
|
||||||
CONFLICT_PREVALANCE=initiator
|
CONFLICT_PREVALANCE=initiator
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LOCK_FILES_EXIST=0
|
# Always assume lock files exist and must be unlocked, unless WriteLockFiles says otherwise
|
||||||
|
INITIATOR_LOCK_FILE_EXISTS=true
|
||||||
|
TARGET_LOCK_FILE_EXISTS=true
|
||||||
|
|
||||||
FORCE_UNLOCK=0
|
FORCE_UNLOCK=0
|
||||||
no_maxtime=0
|
no_maxtime=0
|
||||||
opts=""
|
opts=""
|
||||||
|
@ -1975,6 +2006,7 @@ opts="${opts# *}"
|
||||||
if [ $_QUICK_SYNC -lt 2 ]; then
|
if [ $_QUICK_SYNC -lt 2 ]; then
|
||||||
CheckCurrentConfig
|
CheckCurrentConfig
|
||||||
fi
|
fi
|
||||||
|
CheckCurrentConfigAll
|
||||||
|
|
||||||
DATE=$(date)
|
DATE=$(date)
|
||||||
Logger "-------------------------------------------------------------" "NOTICE"
|
Logger "-------------------------------------------------------------" "NOTICE"
|
||||||
|
|
Loading…
Reference in New Issue