diff --git a/debian/sylkserver.init b/debian/sylkserver.init index f545398..dd847d4 100644 --- a/debian/sylkserver.init +++ b/debian/sylkserver.init @@ -1,75 +1,75 @@ #!/bin/sh # ### BEGIN INIT INFO # Provides: sylkserver # Required-Start: $syslog $network $local_fs $remote_fs $time # Required-Stop: $syslog $network $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start the SylkServer # Description: Start the SylkServer ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin INSTALL_DIR="/usr/bin" RUNTIME_DIR="/var/run/sylkserver" DEFAULTS="/etc/default/sylkserver" SERVER="$INSTALL_DIR/sylk-server" -PID="$RUNTIME_DIR/server.pid" +PID="$RUNTIME_DIR/sylk-server.pid" OPTIONS="" NAME="sylk-server" DESC="SylkServer" test -f $SERVER || exit 0 . /lib/lsb/init-functions # Load startup options if available if [ -f $DEFAULTS ]; then . $DEFAULTS || true fi if [ "$RUN_SYLKSERVER" != "yes" ]; then echo "SylkServer not yet configured. Edit /etc/default/sylkserver first." exit 0 fi if [ "$DUMP_CORE" = "yes" ]; then ulimit -c unlimited fi start() { log_daemon_msg "Starting $DESC: $NAME " start-stop-daemon --start --quiet --pidfile $PID \ --exec $SERVER -- $OPTIONS || log_progress_msg "already running" } stop () { log_daemon_msg "Stopping $DESC: $NAME " start-stop-daemon --stop --quiet --oknodo --retry=TERM/15/KILL/5 --pidfile $PID } case "$1" in start) start log_end_msg 0 ;; stop) stop log_end_msg 0 ;; restart|force-reload) stop start log_end_msg 0 ;; *) echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0 diff --git a/sylk-server b/sylk-server index 0dc5d28..257a4ff 100755 --- a/sylk-server +++ b/sylk-server @@ -1,109 +1,100 @@ #!/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 if __name__ == '__main__': name = 'sylk-server' fullname = 'SylkServer' - runtime_directory = '/var/run/sylkserver' system_config_directory = '/etc/sylkserver' - default_pid = os.path.join(runtime_directory, 'server.pid') - default_config = sylk.configuration_filename if os.path.isfile(sylk.configuration_filename) else os.path.join(system_config_directory, sylk.configuration_filename) + default_runtime_directory = '/var/run/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('--pid', dest='pid_file', - help='pid file (%r)' % default_pid, metavar='File') - parser.add_option('--config-file', dest='config_file', default=default_config, - help='path to configuration file to read (%r)' % default_config, - metavar='File') + 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 (%r)' % default_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() - path, configuration_filename = os.path.split(options.config_file) - if path: - system_config_directory = path - + if options.config_directory is not None: + process.local_config_directory = options.config_directory process.system_config_directory = system_config_directory - sylk.configuration_filename = process.config_file(options.config_file) - pid_file = options.pid_file or default_pid - # when run in foreground, do not require root access because of /var/run/sylkserver - if not options.fork: - process._runtime_directory = None - else: + if options.fork: + pid_file = '{}.pid'.format(name) try: - process.runtime_directory = runtime_directory + 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.server import SylkServer, ServerConfig log.info('Starting {name} {sylk.__version__}, using SIP SIMPLE SDK {sipsimple.__version__}'.format(name=fullname, sylk=sylk, sipsimple=sipsimple)) config_file = ServerConfig.__cfgtype__(ServerConfig.__cfgfile__) if config_file.files: log.info('Reading configuration from {}'.format(', '.join(config_file.files))) else: log.info('Not reading any configuration files (using internal defaults)') 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) 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/__init__.py b/sylk/__init__.py index 9ad252c..a5f68ea 100644 --- a/sylk/__init__.py +++ b/sylk/__init__.py @@ -1,4 +1,2 @@ __version__ = '4.1.0' - -configuration_filename = 'config.ini' diff --git a/sylk/configuration/__init__.py b/sylk/configuration/__init__.py index 6b4ccf6..a305de8 100644 --- a/sylk/configuration/__init__.py +++ b/sylk/configuration/__init__.py @@ -1,89 +1,86 @@ from application.configuration import ConfigSection, ConfigSetting from application.configuration.datatypes import NetworkRangeList, StringList from application.system import host from sipsimple.configuration.datatypes import NonNegativeInteger, SampleRate -from sylk import configuration_filename from sylk.configuration.datatypes import AudioCodecs, IPAddress, Path, Port, PortRange, SIPProxyAddress, SRTPEncryption, LogLevel from sylk.resources import Resources, VarResources from sylk.tls import Certificate, PrivateKey class ServerConfig(ConfigSection): - __cfgfile__ = configuration_filename + __cfgfile__ = 'config.ini' __section__ = 'Server' ca_file = ConfigSetting(type=Path, value=Path(Resources.get('tls/ca.crt'))) certificate = ConfigSetting(type=Path, value=Path(Resources.get('tls/default.crt'))) verify_server = False enable_bonjour = False default_application = 'conference' application_map = ConfigSetting(type=StringList, value=['echo:echo']) disabled_applications = ConfigSetting(type=StringList, value='') extra_applications_dir = ConfigSetting(type=Path, value=None) trace_dir = ConfigSetting(type=Path, value=Path(VarResources.get('log/sylkserver'))) trace_dns = False trace_sip = False trace_msrp = False trace_core = False trace_notifications = False log_level = ConfigSetting(type=LogLevel, value=LogLevel('info')) spool_dir = ConfigSetting(type=Path, value=Path(VarResources.get('spool/sylkserver'))) class SIPConfig(ConfigSection): - __cfgfile__ = configuration_filename + __cfgfile__ = 'config.ini' __section__ = 'SIP' local_ip = ConfigSetting(type=IPAddress, value=IPAddress(host.default_ip)) local_udp_port = ConfigSetting(type=Port, value=5060) local_tcp_port = ConfigSetting(type=Port, value=5060) local_tls_port = ConfigSetting(type=Port, value=5061) advertised_ip = ConfigSetting(type=IPAddress, value=None) outbound_proxy = ConfigSetting(type=SIPProxyAddress, value=None) trusted_peers = ConfigSetting(type=NetworkRangeList, value=NetworkRangeList('any')) enable_ice = False class MSRPConfig(ConfigSection): - __cfgfile__ = configuration_filename + __cfgfile__ = 'config.ini' __section__ = 'MSRP' use_tls = True class RTPConfig(ConfigSection): - __cfgfile__ = configuration_filename + __cfgfile__ = 'config.ini' __section__ = 'RTP' audio_codecs = ConfigSetting(type=AudioCodecs, value=['opus', 'G722', 'speex', 'PCMA', 'PCMU']) port_range = ConfigSetting(type=PortRange, value=PortRange('50000:50500')) srtp_encryption = ConfigSetting(type=SRTPEncryption, value='opportunistic') timeout = ConfigSetting(type=NonNegativeInteger, value=30) sample_rate = ConfigSetting(type=SampleRate, value=48000) class WebServerConfig(ConfigSection): - __cfgfile__ = configuration_filename + __cfgfile__ = 'config.ini' __section__ = 'WebServer' local_ip = ConfigSetting(type=IPAddress, value=IPAddress(host.default_ip)) local_port = ConfigSetting(type=Port, value=10888) hostname = '' certificate = ConfigSetting(type=Path, value=None) certificate_chain = ConfigSetting(type=Path, value=None) class ThorNodeConfig(ConfigSection): - __cfgfile__ = configuration_filename + __cfgfile__ = 'config.ini' __section__ = 'ThorNetwork' enabled = False domain = "sipthor.net" multiply = 1000 certificate = ConfigSetting(type=Certificate, value=None) private_key = ConfigSetting(type=PrivateKey, value=None) ca = ConfigSetting(type=Certificate, value=None) - -