From 3467e4f3288e487e543d095f67c0b5c96721a145 Mon Sep 17 00:00:00 2001 From: deajan Date: Wed, 21 May 2014 19:12:19 +0200 Subject: [PATCH] Added init and install scripts --- CHANGELOG.md | 1 + README.md | 30 ++++++------ install.sh | 11 +++++ osync-srv | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++ sync.conf | 6 +-- 5 files changed, 163 insertions(+), 17 deletions(-) create mode 100755 install.sh create mode 100755 osync-srv diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ff7df..1e53208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ UNDER WORK RECENT CHANGES -------------- +- Added a simple init script working for RHEL / CentOS and an install script - Fixed an issue with MacOSX using rsync -E differently than other *nix (Thanks to Pierre Clement) - Multislave asynchronous task support (Thanks to Ulrich Norbisrath) - This breaks compat with elder osync runs. Add the SYNC_ID suffix to elder state files to keep deleted file information. diff --git a/README.md b/README.md index afac12a..30a3b3a 100644 --- a/README.md +++ b/README.md @@ -31,15 +31,15 @@ Basic MacOS X tests have also been done, but a lot of tests are still needed. ## Installation Keep in mind that Osync has been designed to not delete any data, but rather make backups or soft deletes. -Nevertheless, still consider making backups of your data before trying a sync tool. +Nevertheless, you should always consider making backups of your data before trying a new sync tool. -First, grab a fresh copy of osync and make it executable: +You can download the latest stable release of Osync at www.netpower.fr/osync +You may also get the last development snapshot at https://github.com/deajan/osync - $ git clone https://github.com/deajan/osync - $ cd osync - $ chmod +x ./osync.sh +You may copy the osync.sh file to /usr/local/bin if you intend to use it on a regular basis, or just run it from the directory you downloaded it to. +There is a very basic installation script if you plan to use osync as a daemon too. -Osync needs to run with bash shell. Using any other shell will most probably result in lots of errors. +Osync needs to run with bash shell. Using any other shell will most probably result in errors. If bash is not your default shell, invoke it using $ bash osync.sh [options] @@ -48,7 +48,7 @@ If bash is not your default shell, invoke it using Osync can work with in two flavors: Quick sync mode and configuration file mode. While quick sync mode is convenient to do fast sync sceanrios, a configuration file gives much more functionnality. -Please use double quotes if directoires contain spaces. Do not use escaped spaces. +Please use double as directoires delimiters. Do not use escaped characters in directory names. QuickSync example: @@ -58,9 +58,9 @@ QuickSync example: Configuration files example: You'll have to customize the sync.conf file according to your needs. -Osync needs a pair of private / public RSA keys to perform remote SSH connections. +If you intend to sync a remote directory, osync will need a pair of private / public RSA keys to perform remote SSH connections. Also, running sync as superuser requires to configure /etc/sudoers file. -Please read the documentation on author's site. +Please read the documentation about remote sync setups. Once you've customized a sync.conf file, you may run osync with the following test run: $ ./osync.sh /path/to/your.conf --dry @@ -79,16 +79,18 @@ Once you're confident about your fist runs, you may add osync as cron task like */5 * * * * root /usr/local/bin/osync.sh /path/to/your.conf --silent Additionnaly, you may run osync in monitor mode, which means it will perform a sync upon file operations on master replica. -This can be a drawback on functionnality versus scheduled mode because it won't launch a sync task if there are only file modifications on slave replica. -File monitor mode can also be launched in daemon mode. +This can be a drawback on functionnality versus scheduled mode because this mode only launches a sync task if there are file modifications on the master replica, without being able to monitor the slave replica. Slave replica changes are then only synced when master replica changes occur. +File monitor mode can also be launched as a daemon with an init script. Please read the documentation for more info. Note that monitoring changes requires inotifywait command (inotify-tools package for most Linux distributions). -BSD, MacOS X and Windows are not yet supported for this operation mode. +BSD, MacOS X and Windows are not yet supported for this operation mode, unless you find a inotify-tools package on these. $ ./osync.sh /path/to/your.conf --on-changes - $ ./osync.sh /path/to/your.conf --on-changes --daemon +Osync file monitor mode may be run as system service with the osync-srv init script. Any configuration file found in /etc/osync will then create a osync daemon instance. -You may then find osync output in /var/log/osync-*.log (or current directory if /var/log is not writable). + $ service osync-srv start + +You may find osync's logs in /var/log/osync-*.log (or current directory if /var/log is not writable). ## Author diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8b4ece3 --- /dev/null +++ b/install.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +## Osync daemon install script +## Tested on RHEL / CentOS 6 +## Please adapt this to fit your distro needs + +mkdir /etc/osync +cp ./sync.conf /etc/osync +cp ./osync.sh /usr/local/bin +cp ./osync-srv /etc/init.d + diff --git a/osync-srv b/osync-srv new file mode 100755 index 0000000..4309eaf --- /dev/null +++ b/osync-srv @@ -0,0 +1,132 @@ +#!/bin/bash +# +# osync two way directory sync tool +# +# chkconfig: - 90 100 +# description: monitors a local directory and syncs to a local or remote \ +# directory on file changes + +prog=osync +progexec=osync.sh +progpath=/usr/local/bin +confdir=/etc/osync +pidfile=/var/run/$prog +lockfile=/var/lock/subsys/$prog + +if [ ! -f $progpath/$progexec ] && [ ! -f $progexec ] +then + echo "Cannot find $prog executable in $progpath nor in local path." + exit 1 +fi + +if [ ! -w $(dirname $pidfile) ] +then + pidfile=./$prog +fi + +start() { + if [ ! -f $confdir/*.conf ] + then + echo "Cannot find any configuration files in $confdir." + exit 1 + fi + + errno=0 + + for cfgfile in $confdir/*.conf + do + if [ -f $progpath/$progexec ] + then + $progpath/$progexec $cfgfile --on-changes > /dev/null 2>&1 & + elif [ -f ./$progexec ] + then + ./$progexec $cfgfile --on-changes > /dev/null 2>&1 & + else + echo "Cannot find osync executable in $progpath" + exit 1 + fi + + pid=$! + retval=$? + + if [ $? == 0 ] + then + echo $pid > "$pidfile-$(basename $cfgfile)" + echo "$prog successfully started for configuration file $cfgfile" + else + echo "Cannot start $prog for configuration file $cfgfile" + $errno = 1 + fi + done + + exit $errno +} + +stop() { + if [ ! -f $pidfile-* ] + then + echo "No running osync instances found." + exit 1 + fi + + for pfile in $pidfile-* + do + if ps -p$(cat $pfile) > /dev/null 2>&1 + then + kill -TERM $(cat $pfile) + if [ $? == 0 ] + then + rm -f $pfile + echo "$prog instance $(basename $pfile) stopped." + else + echo "Cannot stop $prog instance $(basename $pfile)" + fi + else + rm -f $pfile + echo "$pfile is dead but lockfile exists." + fi + done +} + +status() { + if [ ! -f $pidfile-* ] + then + echo "Cannot find any running osync instance." + exit + fi + + for pfile in $pidfile-* + do + if ps -p$(cat $pfile) > /dev/null 2>&1 + then + echo "$prog instance $(basename $pfile) is running (pid $(cat $pfile))" + else + echo "$pfile is dead but lockfile exists." + fi + done +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + status + ;; + condrestart|try-restart) + status || exit 0 + restart + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + ;; +esac + +exit 0 diff --git a/sync.conf b/sync.conf index 6c95574..84a62bc 100755 --- a/sync.conf +++ b/sync.conf @@ -2,7 +2,7 @@ ###### Osync - Rsync based two way sync engine with fault tolerance ###### (L) 2013-2014 by Orsiris "Ozy" de Jong (www.netpower.fr) -###### Config file rev 0805201402 +###### Config file rev 2105201401 ## ---------- GENERAL OPTIONS @@ -10,8 +10,8 @@ SYNC_ID="sync_test" ## Directories to synchronize. Master must be on the system Osync runs on. Slave can be either a local directory, or a remote one. -MASTER_SYNC_DIR="/home/git/osync/test/dir1" -SLAVE_SYNC_DIR="/home/git/osync/test/dir2" +MASTER_SYNC_DIR="/home/git/osync/dir1" +SLAVE_SYNC_DIR="/home/git/osync/dir2" #SLAVE_SYNC_DIR="ssh://user@host.com:22//path/to/dir2" ## If slave replica is a remote directory, you must specifiy a RSA key (please use full path). Please see documentation for further information. SSH_RSA_PRIVATE_KEY="/home/backupuser/.ssh/id_rsa"