X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-replicated;h=1e19ef4ac0b14470f5d2c19de616391a34e52d33;hb=3a43c86784c706c1ef6c650bf270365def78f996;hp=ac83a4d805161db874ad3a1bb180b1459d770581;hpb=1b804762104088311ba80f34e174750adebf23a3;p=mirror%2Fuserdir-ldap.git diff --git a/ud-replicated b/ud-replicated old mode 100644 new mode 100755 index ac83a4d..1e19ef4 --- a/ud-replicated +++ b/ud-replicated @@ -63,14 +63,22 @@ FORMAT='%(asctime)s ud-replicated: %(levelname)s %(message)s' SFORMAT='ud-replicated[%(process)s]: %(message)s' logging.basicConfig(format=FORMAT, level=lvl) LOG = logging.getLogger(__name__) -syslog_handler = logging.handlers.SysLogHandler(address = '/dev/log') +logsock = '/dev/log' +if os.path.exists('/var/run/log'): # Kfreebsd randomly different + logsock = '/var/run/log' +syslog_handler = logging.handlers.SysLogHandler(address = logsock) formatter = logging.Formatter(SFORMAT) syslog_handler.setFormatter(formatter) LOG.addHandler(syslog_handler) +last_run = 0 + def do_replicate(message): - last_update = time.time() - LOG.debug("Got message at %s" % last_update) + global last_run + last_update = int(time.time()) + LOG.debug("Got message at %s: %s" % (last_update, message['message'])) + if last_run > message.get('timestamp', 0): + return command = ['/usr/bin/ud-replicate'] if options.dryrun: @@ -84,9 +92,9 @@ def do_replicate(message): LOG.error('%s failed:', ' '.join(command)) else: LOG.debug('%s finished with ret: 0' % ' '.join(command)) - finally: + finally: os.environ['TERM'] = old_term - LOG.debug(message) + last_run = int(time.time()) def main(): conn = Connection(conf=mq_conf)