diff --git a/debian/control b/debian/control index 2b5486e..f1b471c 100644 --- a/debian/control +++ b/debian/control @@ -1,16 +1,16 @@ Source: msrprelay Section: net Priority: optional Maintainer: Dan Pascu Uploaders: Adrian Georgescu Build-Depends: debhelper (>= 9), python(>= 2.7) Standards-Version: 3.9.8 Package: msrprelay Architecture: all -Depends: ${python:Depends}, ${misc:Depends}, lsb-base, python-application (>= 2.8.0), python-gnutls (>= 3.0.0), python-twisted-core (>= 2.5.0), python-twisted-names, python-sqlobject (>= 0.10.2) +Depends: ${python:Depends}, ${misc:Depends}, lsb-base, python-application (>= 2.8.0), python-gnutls (>= 3.0.0), python-twisted-core (>= 2.5.0), python-twisted-names, python-sqlobject (>= 0.10.2), python-systemd Description: MSRP Relay, a RFC 4976 compatible IM/File transfer relay This software implements an MSRP relay, which is an extension to the MSRP protocol (RFC 4975). Its main role is to help NAT traversal of Interactive Messaging and file transfer sessions for SIP/MSRP endpoints located behind NAT. diff --git a/msrprelay b/msrprelay index ea491c7..13d3cac 100644 --- a/msrprelay +++ b/msrprelay @@ -1,77 +1,82 @@ #!/usr/bin/env python """MSRP Relay""" if __name__ == '__main__': import msrp import sys import signal from application import log from application.process import process, ProcessError from argparse import ArgumentParser name = 'msrprelay' fullname = 'MSRP Relay' description = 'An open source MSRP Relay' process.configuration.user_directory = None process.configuration.subdirectory = name # process.runtime.subdirectory = name parser = ArgumentParser(usage='%(prog)s [options]') parser.add_argument('--version', action='version', version='%(prog)s {}'.format(msrp.__version__)) + parser.add_argument('--systemd', action='store_true', help='run as a systemd simple service and log to journal') parser.add_argument('--no-fork', action='store_false', dest='fork', help='run in the foreground and log to terminal') parser.add_argument('--config-dir', dest='config_directory', default=None, help='the configuration directory', metavar='PATH') parser.add_argument('--runtime-dir', dest='runtime_directory', default=None, help='the runtime directory ({})'.format(process.runtime.directory), metavar='PATH') parser.add_argument('--debug', action='store_true', help='enable verbose logging') parser.add_argument('--debug-memory', action='store_true', help='enable memory debugging') options = parser.parse_args() log.Formatter.prefix_format = '{record.levelname:<8s} ' if options.config_directory is not None: process.configuration.local_directory = options.config_directory if options.runtime_directory is not None: process.runtime.directory = options.runtime_directory - if options.fork: + if options.systemd: + from systemd.journal import JournalHandler + log.set_handler(JournalHandler(SYSLOG_IDENTIFIER=name)) + log.capture_output() + elif options.fork: try: pid_file = '{}.pid'.format(name) process.daemonize(pid_file) except ProcessError, e: log.critical('Cannot start %s: %s' % (fullname, e)) sys.exit(1) log.use_syslog(name) log.info('Starting %s %s' % (fullname, msrp.__version__)) from msrp.relay import Relay, RelayConfig log.level.current = log.level.DEBUG if options.debug else RelayConfig.log_level if options.debug_memory: from application.debug.memory import memory_dump try: relay = Relay() except Exception, e: log.critical('Failed to create %s: %s' % (fullname, e)) if e.__class__ is not RuntimeError: log.exception() sys.exit(1) process.signals.add_handler(signal.SIGHUP, lambda signum, frame: relay.reload()) try: relay.run() except Exception, e: log.critical('Failed to run %s: %s' % (fullname, e)) if e.__class__ is not RuntimeError: log.exception() sys.exit(1) if options.debug_memory: memory_dump()