pax_global_header00006660000000000000000000000064112626201360014511gustar00rootroot0000000000000052 comment=6ede5cecbaca6672f5ae2a1addd64578a54b2d6c inosync-0.2.1/000077500000000000000000000000001126262013600131735ustar00rootroot00000000000000inosync-0.2.1/LICENSE000066400000000000000000000026051126262013600142030ustar00rootroot00000000000000Copyright (c) 2007-2008 Benedikt Böhm All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. inosync-0.2.1/README.rst000066400000000000000000000062121126262013600146630ustar00rootroot00000000000000======= inosync ======= :Author: `Benedikt Böhm `_ :Version: 0.2.1 :Web: http://bb.xnull.de/projects/inosync/ :Source: http://git.xnull.de/gitweb/?p=inosync.git (also on `github `_) :Download: http://bb.xnull.de/projects/inosync/dist/ Rationale ========= System administrators have relied on cron+rsync for years to constantly synchronize files and directories to remote machines. However, this technique has a huge disadvantage for content distribution with near real-time requirements, e.g. podcasts and blogging. It is not feasible to let authors wait for their content to get synchronized every x hours with regard to the enormous pace of articles and podcasts nowadays. The inosync daemon leverages the inotify service available in recent linux kernels to monitor and synchronize changes within directories to remote nodes. Usage ===== :: inosync [OPTIONS] -c FILE load configuration from FILE -d daemonize (fork to background) -p do not actually call rsync -v print debugging information --version show program's version number and exit -h, --help show this help message and exit Configuration ============= Configuration files are simple python scripts, merely declaring necessary variables. Below is an example configuration to synchronize ``/var/www`` except ``/var/www/localhost`` to 3 remote locations: :: # directory that should be watched for changes wpath = "/var/www/" # exclude list for rsync rexcludes = [ "/localhost", ] # common remote path rpath = "/var/www/" # remote locations in rsync syntax rnodes = [ "a.mirror.com:" + rpath, "b.mirror.com:" + rpath, "c.mirror.com:" + rpath, ] # limit remote sync speed (in KB/s, 0 = no limit) #rspeed = 0 # event mask (only sync on these events) #emask = [ # "IN_CLOSE_WRITE", # "IN_CREATE", # "IN_DELETE", # "IN_MOVED_FROM", # "IN_MOVED_TO", #] # event delay in seconds (this prevents huge # amounts of syncs, but dicreases the # realtime side of things) #edelay = 10 # rsync binary path #rsync = "/usr/bin/rsync" Bugs ==== There are no known bugs currently, however, due to the design of inosync, there are several shortcomings: - inosync cannot parse rsync excludes and therefore calls rsync on changes in excluded directories as well. (`of course rsync still excludes these directories`) - It is easily possible to flood the daemon with huge amounts of change events, potentially resulting in enormous bandwidth and connection usage. Requirements ============ To use this script you need the following software installed on your system: - linux-2.6.13 or later - Python-2.4 or later - pyinotify-0.7.0 or later Related Software ================ inosync is similar to `lsyncd `_, but uses a lot less (nasty) magic to parse rsync excludes and shared www directories. Additionally inosync has no limitation on filename size and number of active watchpoints. A comparision to other approaches like DRBD, incron and FUSE can be found at lsyncds project page, mentioned above. inosync-0.2.1/inosync.py000077500000000000000000000131151126262013600152330ustar00rootroot00000000000000#!/usr/bin/python # vim: set fileencoding=utf-8 ts=2 sw=2 expandtab : import os,sys from optparse import OptionParser,make_option from time import sleep from syslog import * from pyinotify import * __author__ = "Benedikt Böhm" __copyright__ = "Copyright (c) 2007-2008 Benedikt Böhm " __version__ = 0,2,1 OPTION_LIST = [ make_option( "-c", dest = "config", default = "/etc/inosync/default.py", metavar = "FILE", help = "load configuration from FILE"), make_option( "-d", dest = "daemonize", action = "store_true", default = False, help = "daemonize %prog"), make_option( "-p", dest = "pretend", action = "store_true", default = False, help = "do not actually call rsync"), make_option( "-v", dest = "verbose", action = "store_true", default = False, help = "print debugging information"), ] ALL_EVENTS = [ "IN_ACCESS", "IN_ATTRIB", "IN_CLOSE_WRITE", "IN_CLOSE_NOWRITE", "IN_CREATE", "IN_DELETE", "IN_DELETE_SELF", "IN_MODIFY", "IN_MOVED_FROM", "IN_MOVED_TO", "IN_OPEN" ] DEFAULT_EVENTS = [ "IN_CLOSE_WRITE", "IN_CREATE", "IN_DELETE", "IN_MOVED_FROM", "IN_MOVED_TO" ] class RsyncEvent(ProcessEvent): pretend = None dirty = True def __init__(self, pretend=False): self.pretend = pretend def sync(self): if not self.dirty: return args = [config.rsync, "-ltrp", "--delete"] args.append("--bwlimit=%s" % config.rspeed) if config.logfile: args.append("--log-file=%s" % config.logfile) if "excludes" in dir(config): for exclude in config.excludes: args.append("--exclude=%s" % exclude) args.append(config.wpath) args.append("%s") cmd = " ".join(args) for node in config.rnodes: if self.pretend: syslog("would execute `%s'" % (cmd % node)) else: syslog(LOG_DEBUG, "executing %s" % (cmd % node)) proc = os.popen(cmd % node) for line in proc: syslog(LOG_DEBUG, "[rsync] %s" % line.strip()) self.dirty = False def process_default(self, event): syslog(LOG_DEBUG, "caught %s on %s" % \ (event.event_name, os.path.join(event.path, event.name))) if not event.event_name in config.emask: syslog(LOG_DEBUG, "ignoring %s on %s" % \ (event.event_name, os.path.join(event.path, event.name))) return self.dirty = True def daemonize(): try: pid = os.fork() except OSError, e: raise Exception, "%s [%d]" % (e.strerror, e.errno) if (pid == 0): os.setsid() try: pid = os.fork() except OSError, e: raise Exception, "%s [%d]" % (e.strerror, e.errno) if (pid == 0): os.chdir('/') os.umask(0) else: os._exit(0) else: os._exit(0) os.open("/dev/null", os.O_RDWR) os.dup2(0, 1) os.dup2(0, 2) return 0 def load_config(filename): if not os.path.isfile(filename): raise RuntimeError, "configuration file does not exist: %s" % filename configdir = os.path.dirname(filename) configfile = os.path.basename(filename) if configfile.endswith(".py"): configfile = configfile[0:-3] sys.path.append(configdir) exec("import %s as __config__" % configfile) sys.path.remove(configdir) global config config = __config__ if not "wpath" in dir(config): raise RuntimeError, "no watch path given" if not os.path.isdir(config.wpath): raise RuntimeError, "watch path does not exist: %s" % config.wpath if not os.path.isabs(config.wpath): config.wpath = os.path.abspath(config.wpath) if not "rnodes" in dir(config) or len(config.rnodes) < 1: raise RuntimeError, "no remote nodes given" if not "rspeed" in dir(config) or config.rspeed < 0: config.rspeed = 0 if not "emask" in dir(config): config.emask = DEFAULT_EVENTS for event in config.emask: if not event in ALL_EVENTS: raise RuntimeError, "invalid inotify event: %s" % event if not "edelay" in dir(config): config.edelay = 10 if config.edelay < 1: raise RuntimeError, "event delay needs to be greater than 1" if not "logfile" in dir(config): config.logfile = None if not "rsync" in dir(config): config.rsync = "/usr/bin/rsync" if not os.path.isabs(config.rsync): raise RuntimeError, "rsync path needs to be absolute" if not os.path.isfile(config.rsync): raise RuntimeError, "rsync binary does not exist: %s" % config.rsync def main(): version = ".".join(map(str, __version__)) parser = OptionParser(option_list=OPTION_LIST,version="%prog " + version) (options, args) = parser.parse_args() if len(args) > 0: parser.error("too many arguments") logopt = LOG_PID|LOG_CONS if not options.daemonize: logopt |= LOG_PERROR openlog("inosync", logopt, LOG_DAEMON) if options.verbose: setlogmask(LOG_UPTO(LOG_DEBUG)) else: setlogmask(LOG_UPTO(LOG_INFO)) load_config(options.config) if options.daemonize: daemonize() wm = WatchManager() ev = RsyncEvent(options.pretend) notifier = Notifier(wm, ev) wds = wm.add_watch(config.wpath, EventsCodes.ALL_EVENTS, rec = True, auto_add = True) syslog(LOG_DEBUG, "starting initial synchronization on %s" % config.wpath) ev.sync() syslog(LOG_DEBUG, "initial synchronization on %s done" % config.wpath) syslog("resuming normal operations on %s" % config.wpath) while True: try: notifier.process_events() if notifier.check_events(0): notifier.read_events() ev.sync() sleep(config.edelay) except KeyboardInterrupt: notifier.stop() break sys.exit(0) if __name__ == "__main__": main() inosync-0.2.1/mkrelease.sh000077500000000000000000000011351126262013600155020ustar00rootroot00000000000000#!/bin/bash source /etc/init.d/functions.sh PROJECT=$(sed -n '2{p;q;}' README.rst|tr '[A-Z]' '[a-z]') VERSION=$(sed 's/^:Version: \(.*\)/\1/;t;d' README.rst) HTDOCS=~/public_html/projects/${PROJECT} DISTTAR=${HTDOCS}/dist/${PROJECT}-${VERSION}.tar.bz2 mkdir -p ${HTDOCS}/dist ebegin "Generating project page" ~/work/rst2html.py ~/public_html/template.html < README.rst > ${HTDOCS}/index.html eend $? if [[ -e ${DISTTAR} ]]; then echo "!!! ${DISTTAR} exists." else ebegin "Creating release tarball" git archive --format=tar --prefix=${PROJECT}-${VERSION}/ HEAD | \ bzip2 > ${DISTTAR} eend $? fi inosync-0.2.1/sample_config.py000066400000000000000000000013241126262013600163530ustar00rootroot00000000000000# directory that should be watched for changes wpath = "/var/www/" # exclude list for rsync rexcludes = [ "/localhost", ] # common remote path rpath = "/var/www/" # remote locations in rsync syntax rnodes = [ "a.mirror.com:" + rpath, "b.mirror.com:" + rpath, "c.mirror.com:" + rpath, ] # limit remote sync speed (in KB/s, 0 = no limit) #rspeed = 0 # event mask (only sync on these events) #emask = [ # "IN_CLOSE_WRITE", # "IN_CREATE", # "IN_DELETE", # "IN_MOVED_FROM", # "IN_MOVED_TO", #] # event delay in seconds (prevents huge amounts of syncs, but dicreases the # realtime side of things) #edelay = 10 # rsync log file for updates #logfile = /var/log/inosync.log # rsync binary path #rsync = "/usr/bin/rsync"