Improved file monitor mode

This commit is contained in:
deajan 2013-11-25 13:20:53 +01:00
parent e3f5b2f85b
commit e18dfd1822
2 changed files with 38 additions and 5 deletions

View File

@ -21,6 +21,7 @@ KNOWN ISSUES
RECENT CHANGES RECENT CHANGES
-------------- --------------
- Improved file monitor mode
- Added possibility to daemonize osync in monitor mode - Added possibility to daemonize osync in monitor mode
- Added monitor mode, which will launch a sync task upon file operations on master replica - Added monitor mode, which will launch a sync task upon file operations on master replica
- Changed conf file default format for ssh uri (old format is still compatible) - Changed conf file default format for ssh uri (old format is still compatible)

View File

@ -3,7 +3,7 @@
###### Osync - Rsync based two way sync engine with fault tolerance ###### Osync - Rsync based two way sync engine with fault tolerance
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr) ###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
OSYNC_VERSION=0.99RC2-qs OSYNC_VERSION=0.99RC2-qs
OSYNC_BUILD=2511201301 OSYNC_BUILD=2511201302
DEBUG=no DEBUG=no
SCRIPT_PID=$$ SCRIPT_PID=$$
@ -774,6 +774,11 @@ function WriteLockFiles
function LockDirectories function LockDirectories
{ {
if [ $nolocks -eq 1 ]
then
return 0
fi
if [ $force_unlock -eq 1 ] if [ $force_unlock -eq 1 ]
then then
WriteLockFiles WriteLockFiles
@ -850,6 +855,11 @@ function LockDirectories
function UnlockDirectories function UnlockDirectories
{ {
if [ $nolocks -eq 1 ]
then
return 0
fi
if [ "$REMOTE_SYNC" == "yes" ] if [ "$REMOTE_SYNC" == "yes" ]
then then
CheckConnectivity3rdPartyHosts CheckConnectivity3rdPartyHosts
@ -1712,7 +1722,13 @@ function SyncOnChanges
while true while true
do do
inotifywait --exclude $OSYNC_DIR $RSYNC_EXCLUDE -qq -r -e create -e modify -e delete -e move -e attrib "$MASTER_SYNC_DIR/" inotifywait --exclude $OSYNC_DIR $RSYNC_EXCLUDE -qq -r -e create -e modify -e delete -e move -e attrib "$MASTER_SYNC_DIR/"
$osync_cmd "$ConfigFile" $opts if [ "$ConfigFile" != "" ]
then
cmd="bash $osync_cmd \"$ConfigFile\" $opts --no-locks"
else
cmd="bash $osync_cmd $opts --no-locks"
fi
eval $cmd
done done
} }
@ -1736,6 +1752,7 @@ soft_stop=0
quick_sync=0 quick_sync=0
sync_on_changes=0 sync_on_changes=0
daemonize=0 daemonize=0
nolocks=0
osync_cmd=$0 osync_cmd=$0
if [ $# -eq 0 ] if [ $# -eq 0 ]
@ -1773,14 +1790,17 @@ do
quick_sync=$(($quick_sync + 1)) quick_sync=$(($quick_sync + 1))
no_maxtime=1 no_maxtime=1
MASTER_SYNC_DIR=${i##*=} MASTER_SYNC_DIR=${i##*=}
opts=$opts" --master=\"$MASTER_SYNC_DIR\""
;; ;;
--slave=*) --slave=*)
quick_sync=$(($quick_sync + 1)) quick_sync=$(($quick_sync + 1))
SLAVE_SYNC_DIR=${i##*=} SLAVE_SYNC_DIR=${i##*=}
opts=$opts" --slave=\"$SLAVE_SYNC_DIR\""
no_maxtime=1 no_maxtime=1
;; ;;
--rsakey=*) --rsakey=*)
SSH_RSA_PRIVATE_KEY=${i##*=} SSH_RSA_PRIVATE_KEY=${i##*=}
opts=$opts" --rsakey=\"$SSH_RSA_PRIVATE_KEY\""
;; ;;
--on-changes) --on-changes)
sync_on_changes=1 sync_on_changes=1
@ -1788,9 +1808,15 @@ do
--daemon) --daemon)
daemonize=1 daemonize=1
;; ;;
--no-locks)
nolocks=1
;;
esac esac
done done
# Remove leading space if there is one
opts="${opts# *}"
CheckEnvironment CheckEnvironment
if [ $? == 0 ] if [ $? == 0 ]
then then
@ -1811,17 +1837,23 @@ then
then then
if [ $daemonize -eq 1 ] if [ $daemonize -eq 1 ]
then then
echo $SCRIPT_PID > $PID_FILE ## echo $SCRIPT_PID > $PID_FILE
silent=1 silent=1
exec > /dev/null 2>&1 exec > /dev/null 2>&1
SyncOnChanges &
exit
else
SyncOnChanges
fi fi
SyncOnChanges &
exit
fi fi
DATE=$(date) DATE=$(date)
Log "-------------------------------------------------------------" Log "-------------------------------------------------------------"
Log "$DRY_WARNING $DATE - Osync v$OSYNC_VERSION script begin." Log "$DRY_WARNING $DATE - Osync v$OSYNC_VERSION script begin."
Log "-------------------------------------------------------------" Log "-------------------------------------------------------------"
if [ $daemonize -eq 1 ]
then
Log "Running as daemon"
fi
Log "Sync task [$SYNC_ID] launched as $LOCAL_USER@$LOCAL_HOST (PID $SCRIPT_PID)" Log "Sync task [$SYNC_ID] launched as $LOCAL_USER@$LOCAL_HOST (PID $SCRIPT_PID)"
GetOperatingSystem GetOperatingSystem
if [ $no_maxtime -eq 1 ] if [ $no_maxtime -eq 1 ]