# Do not use exit and quit traps if osync runs in monitor mode
if[$sync_on_changes==false];then
if[$_SYNC_ON_CHANGES==false];then
trap TrapStop INT HUP TERM QUIT
trap TrapQuit EXIT
else
@ -5385,6 +5435,7 @@ function Usage {
echo"--no-maxtime Disables any soft and hard execution time checks"
echo"--force-unlock Will override any existing active or dead locks on initiator and target replica"
echo"--on-changes Will launch a sync task after a short wait period if there is some file activity on initiator replica. You should try daemon mode instead"
echo"--on-changes-target Will trigger ansync task on initiator if initiator runs daemon mode. You should call this with the osync-target-helper service"
echo"--no-resume Do not try to resume a failed run. By default, execution is resumed once"
echo"--initialize Create file lists without actually synchronizing anything, this will help setup deletion detections before the first run"
@ -5406,14 +5457,17 @@ function Usage {
}
function SyncOnChanges {
__CheckArguments 0$#"$@"#__WITH_PARANOIA_DEBUG
localisTargetHelper="${1:-false}"# Is this service supposed to be run as target helper ?
__CheckArguments 1$#"$@"#__WITH_PARANOIA_DEBUG
local watchDirectory
local cmd
local retval
if["$LOCAL_OS"=="MacOSX"];then
if ! type fswatch > /dev/null 2>&1;then
Logger "No inotifywait command found. Cannot monitor changes." "CRITICAL"
Logger "No fswatch command found. Cannot monitor changes." "CRITICAL"
exit1
fi
else
@ -5423,36 +5477,53 @@ function SyncOnChanges {
fi
fi
if[ ! -d "$INITIATOR_SYNC_DIR"];then
Logger "Initiator directory [$INITIATOR_SYNC_DIR] does not exist. Cannot monitor.""CRITICAL"
exit1
fi
Logger "#### Running $PROGRAM in file monitor mode.""NOTICE"
if[$isTargetHelper==false];then
if[ ! -d "$INITIATOR_SYNC_DIR"];then
Logger "Initiator directory [$INITIATOR_SYNC_DIR] does not exist. Cannot monitor.""CRITICAL"
exit1
fi
Logger "#### Running $PROGRAM in initiator file monitor mode.""NOTICE"
else
if[ ! -d "$TARGET_SYNC_DIR"];then
Logger "Target directory [$TARGET_SYNC_DIR] does not exist. Cannot monitor.""CRITICAL"
exit1
fi
Logger "#### Running $PROGRAM in target helper file monitor mode.""NOTICE"
fi
while true;do
if["$ConfigFile" !=""];then
cmd='bash '$osync_cmd' "'$ConfigFile'" '$opts
if[$isTargetHelper==false];then
if["$ConfigFile" !=""];then
cmd='bash '$osync_cmd' "'$ConfigFile'" '$opts
else
cmd='bash '$osync_cmd' '$opts
fi
Logger "Daemon cmd: $cmd""DEBUG"
eval"$cmd"
retval=$?
if[$retval -ne 0]&&[$retval !=2];then
Logger "$PROGRAM child exited with error.""ERROR"$retval
fi
watchDirectory="$INITIATOR_SYNC_DIR"
else
cmd='bash '$osync_cmd' '$opts
fi
Logger "Daemon cmd: $cmd""DEBUG"
eval"$cmd"
retval=$?
if[$retval -ne 0]&&[$retval !=2];then
Logger "osync child exited with error.""ERROR"$retval
# Mac fswatch doesn't have timeout switch, replacing wait $! with WaitForTaskCompletion without warning nor spinner and increased SLEEP_TIME to avoid cpu hogging. This sims wait $! with timeout
# Mac fswatch doesn't have timeout switch, replacing wait $! with WaitForTaskCompletion without warning nor spinner and increased SLEEP_TIME to avoid cpu hogging. This simulates wait $! with timeout
# Do not use exit and quit traps if osync runs in monitor mode
if[$sync_on_changes==false];then
if[$_SYNC_ON_CHANGES==false];then
trap TrapStop INT HUP TERM QUIT
trap TrapQuit EXIT
else
@ -5163,6 +5210,7 @@ function Usage {
echo"--no-maxtime Disables any soft and hard execution time checks"
echo"--force-unlock Will override any existing active or dead locks on initiator and target replica"
echo"--on-changes Will launch a sync task after a short wait period if there is some file activity on initiator replica. You should try daemon mode instead"
echo"--on-changes-target Will trigger ansync task on initiator if initiator runs daemon mode. You should call this with the osync-target-helper service"
echo"--no-resume Do not try to resume a failed run. By default, execution is resumed once"
echo"--initialize Create file lists without actually synchronizing anything, this will help setup deletion detections before the first run"
@ -5184,13 +5232,16 @@ function Usage {
}
function SyncOnChanges {
localisTargetHelper="${1:-false}"# Is this service supposed to be run as target helper ?
local watchDirectory
local cmd
local retval
if["$LOCAL_OS"=="MacOSX"];then
if ! type fswatch > /dev/null 2>&1;then
Logger "No inotifywait command found. Cannot monitor changes." "CRITICAL"
Logger "No fswatch command found. Cannot monitor changes." "CRITICAL"
exit1
fi
else
@ -5200,36 +5251,53 @@ function SyncOnChanges {
fi
fi
if[ ! -d "$INITIATOR_SYNC_DIR"];then
Logger "Initiator directory [$INITIATOR_SYNC_DIR] does not exist. Cannot monitor.""CRITICAL"
exit1
fi
Logger "#### Running $PROGRAM in file monitor mode.""NOTICE"
if[$isTargetHelper==false];then
if[ ! -d "$INITIATOR_SYNC_DIR"];then
Logger "Initiator directory [$INITIATOR_SYNC_DIR] does not exist. Cannot monitor.""CRITICAL"
exit1
fi
Logger "#### Running $PROGRAM in initiator file monitor mode.""NOTICE"
else
if[ ! -d "$TARGET_SYNC_DIR"];then
Logger "Target directory [$TARGET_SYNC_DIR] does not exist. Cannot monitor.""CRITICAL"
exit1
fi
Logger "#### Running $PROGRAM in target helper file monitor mode.""NOTICE"
fi
while true;do
if["$ConfigFile" !=""];then
cmd='bash '$osync_cmd' "'$ConfigFile'" '$opts
if[$isTargetHelper==false];then
if["$ConfigFile" !=""];then
cmd='bash '$osync_cmd' "'$ConfigFile'" '$opts
else
cmd='bash '$osync_cmd' '$opts
fi
Logger "Daemon cmd: $cmd""DEBUG"
eval"$cmd"
retval=$?
if[$retval -ne 0]&&[$retval !=2];then
Logger "$PROGRAM child exited with error.""ERROR"$retval
fi
watchDirectory="$INITIATOR_SYNC_DIR"
else
cmd='bash '$osync_cmd' '$opts
fi
Logger "Daemon cmd: $cmd""DEBUG"
eval"$cmd"
retval=$?
if[$retval -ne 0]&&[$retval !=2];then
Logger "osync child exited with error.""ERROR"$retval
# Mac fswatch doesn't have timeout switch, replacing wait $! with WaitForTaskCompletion without warning nor spinner and increased SLEEP_TIME to avoid cpu hogging. This sims wait $! with timeout
# Mac fswatch doesn't have timeout switch, replacing wait $! with WaitForTaskCompletion without warning nor spinner and increased SLEEP_TIME to avoid cpu hogging. This simulates wait $! with timeout