from dsa_mq.connection import Connection
from dsa_mq.config import Config
+import json
import logging
import logging.handlers
import optparse
import os
import platform
+import stat
import subprocess
import sys
import time
logging.basicConfig(format=FORMAT, level=lvl)
LOG = logging.getLogger(__name__)
logsock = '/dev/log'
-if os.path.exists('/var/run/log'): # Kfreebsd randomly different
+if os.path.exists('/var/run/log') and stat.S_ISSOCK(os.stat('/var/run/log').st_mode): # Kfreebsd randomly different
logsock = '/var/run/log'
syslog_handler = logging.handlers.SysLogHandler(address = logsock)
formatter = logging.Formatter(SFORMAT)
global last_run
last_update = int(time.time())
timestamp = last_update
+ try:
+ message = json.loads(message)
+ except ValueError:
+ pass
if isinstance(message, dict):
timestamp = message.get('timestamp', last_update)
message = message.get('message', 'update required')
LOG.debug("Got message at %s: %s" % (last_update, message))
- if last_run > timestamp, last_update):
+ if last_run > timestamp:
return
command = ['/usr/bin/ud-replicate']
else:
LOG.debug('%s finished with ret: 0' % ' '.join(command))
finally:
- os.environ['TERM'] = old_term
+ if old_term is not None:
+ os.environ['TERM'] = old_term
last_run = last_update
def main():
sys.exit(0)
if __name__ == '__main__':
- do_replicate(
+ do_replicate(json.dumps(
{'timestamp': time.time(),
- 'message': 'startup complete'})
+ 'message': 'startup complete'}))
main()