diff --git a/debian/control b/debian/control index ac8fd67..f07eac4 100644 --- a/debian/control +++ b/debian/control @@ -1,47 +1,47 @@ Source: sylkserver Section: net Priority: optional Maintainer: Dan Pascu Uploaders: Adrian Georgescu Build-Depends: debhelper (>= 11), dh-python, python-all (>= 2.7), rename Standards-Version: 3.9.8 Package: sylkserver Architecture: all Depends: ${python:Depends}, ${misc:Depends}, lsb-base, - python-application (>= 2.5.0), + python-application (>= 2.8.0), python-autobahn, python-eventlib, python-klein, python-lxml, python-sipsimple (>= 3.0.0), python-twisted, python-typing Suggests: libavahi-compat-libdnssd1, python-wokkel, sylkserver-webrtc-gateway Recommends: sylkserver-sounds Description: Extensible real-time-communications application server SylkServer is a SIP applications server that provides applications like echo, playback and conference, as well as act as a gateway between SIP and IRC, XMPP and WEBRTC. Package: sylkserver-sounds Architecture: all Depends: ${misc:Depends} Description: Extensible real-time-communications application server sounds SylkServer is a SIP applications server that provides applications like echo, playback and conference, as well as act as a gateway between SIP and IRC, XMPP and WEBRTC. . This package contains sounds used by SylkServer. Package: sylkserver-webrtc-gateway Architecture: all Depends: ${misc:Depends}, sylkserver, janus Description: Extensible real-time-communications application server WebRTC gateway SylkServer is a SIP applications server that provides applications like echo, playback and conference, as well as act as a gateway between SIP and IRC, XMPP and WEBRTC. . This is a meta-package containing the dependencies required to run the WebRTC gateway application. diff --git a/sylk-server b/sylk-server index 0832938..f07e968 100644 --- a/sylk-server +++ b/sylk-server @@ -1,113 +1,114 @@ #!/usr/bin/env python import os import signal import sys from application import log from application.process import process, ProcessError from optparse import OptionParser import sipsimple import sylk # noinspection PyUnusedLocal def stop_server(signum, frame): sylk_server = SylkServer() sylk_server.stop() # noinspection PyUnusedLocal def toggle_debugging(signum, frame): if log.level.current != log.level.DEBUG: log.level.current = log.level.DEBUG log.info('Switched logging level to DEBUG') else: log.info('Switched logging level to {}'.format(ServerConfig.log_level)) log.level.current = ServerConfig.log_level # noinspection PyUnusedLocal def dump_observers(signum, frame): from application.notification import NotificationCenter from pprint import pprint notification_center = NotificationCenter() pprint(notification_center.observers) if __name__ == '__main__': name = 'sylk-server' fullname = 'SylkServer' - system_config_directory = '/etc/sylkserver' - default_runtime_directory = '/var/run/sylkserver' + + process.configuration.subdirectory = 'sylkserver' + process.runtime.subdirectory = 'sylkserver' parser = OptionParser(version='%%prog %s' % sylk.__version__) parser.add_option('--no-fork', action='store_false', dest='fork', default=1, help='run the process in the foreground (for debugging)') parser.add_option('--config-dir', dest='config_directory', default=None, help='the configuration directory', metavar='Path') - parser.add_option('--runtime-dir', dest='runtime_directory', default=default_runtime_directory, - help='the runtime directory (%s)' % default_runtime_directory, metavar='Path') + parser.add_option('--runtime-dir', dest='runtime_directory', default=None, + help='the runtime directory ({})'.format(process.runtime.directory), metavar='Path') parser.add_option('--enable-bonjour', action='store_true', dest='enable_bonjour', default=False, help='enable Bonjour services') parser.add_option('--debug-memory', action='store_true', dest='debug_memory', default=False, help='enable memory debugging (only works with --no-fork)') options, args = parser.parse_args() if options.config_directory is not None: - process.local_config_directory = options.config_directory - process.system_config_directory = system_config_directory + process.configuration.local_directory = options.config_directory + if options.runtime_directory is not None: + process.runtime.directory = options.runtime_directory if options.fork: sys.argv[0] = os.path.realpath(sys.argv[0]) # on fork the current directory changes to / resulting in the wrong resources directory if started with a relative path pid_file = '{}.pid'.format(name) try: - process.runtime_directory = options.runtime_directory process.daemonize(pid_file) except ProcessError as e: log.fatal('Failed to start {name}: {exception!s}'.format(name=fullname, exception=e)) sys.exit(1) log.start_syslog(name) from sylk.resources import Resources from sylk.server import SylkServer, ServerConfig log.info('Starting {name} {sylk.__version__}, using SIP SIMPLE SDK {sipsimple.__version__}'.format(name=fullname, sylk=sylk, sipsimple=sipsimple)) configuration = ServerConfig.__cfgtype__(ServerConfig.__cfgfile__) if configuration.files: log.info('Reading configuration from {}'.format(', '.join(configuration.files))) else: log.info('Not reading any configuration files (using internal defaults)') log.info('Using resources from {}'.format(Resources.directory)) if not options.fork and options.debug_memory: import atexit from application.debug.memory import memory_dump atexit.register(memory_dump) process.signals.add_handler(signal.SIGTERM, stop_server) process.signals.add_handler(signal.SIGINT, stop_server) process.signals.add_handler(signal.SIGUSR1, toggle_debugging) process.signals.add_handler(signal.SIGUSR2, dump_observers) server = SylkServer() try: server.run(options) except Exception as e: log.fatal('Failed to start {name}: {exception!s}'.format(name=fullname, exception=e)) log.exception() sys.exit(1) # the run() method returns after the server is stopped if server.state == 'stopped': log.info('{name} stopped'.format(name=fullname)) sys.exit(int(server.failed)) else: log.info('Forcefully exiting {name}...'.format(name=fullname)) # noinspection PyProtectedMember os._exit(1) diff --git a/sylk/tls.py b/sylk/tls.py index bbaefae..066c6dd 100644 --- a/sylk/tls.py +++ b/sylk/tls.py @@ -1,49 +1,49 @@ from application import log from application.process import process from gnutls.crypto import X509Certificate, X509PrivateKey __all__ = 'Certificate', 'PrivateKey' def file_content(file): - path = process.config_file(file) + path = process.configuration.file(file) if path is None: raise Exception("File '%s' does not exist" % file) try: f = open(path, 'rt') except Exception: raise Exception("File '%s' could not be open" % file) try: return f.read() finally: f.close() class Certificate(object): """Configuration data type. Used to create a gnutls.crypto.X509Certificate object from a file given in the configuration file.""" def __new__(cls, value): if isinstance(value, basestring): try: return X509Certificate(file_content(value)) except Exception as e: log.warn("Certificate file '%s' could not be loaded: %s" % (value, str(e))) return None else: raise TypeError('value should be a string') class PrivateKey(object): """Configuration data type. Used to create a gnutls.crypto.X509PrivateKey object from a file given in the configuration file.""" def __new__(cls, value): if isinstance(value, basestring): try: return X509PrivateKey(file_content(value)) except Exception as e: log.warn("Private key file '%s' could not be loaded: %s" % (value, str(e))) return None else: raise TypeError('value should be a string')