def __init__(self): self.accounting = [ __import__("mediaproxy.interfaces.accounting.%s" % mod.lower(), globals(), locals(), [""]).Accounting() for mod in set(DispatcherConfig.accounting) ] self.cred = X509Credentials(cert_name='dispatcher') self.tls_context = TLSContext(self.cred) self.relay_factory = RelayFactory(self) dispatcher_addr, dispatcher_port = DispatcherConfig.listen self.relay_listener = reactor.listenTLS(dispatcher_port, self.relay_factory, self.tls_context, interface=dispatcher_addr) self.opensips_factory = OpenSIPSControlFactory(self) socket_path = process.runtime_file(DispatcherConfig.socket_path) unlink(socket_path) self.opensips_listener = reactor.listenUNIX(socket_path, self.opensips_factory) self.opensips_management = opensips.ManagementInterface() self.management_factory = ManagementControlFactory(self) management_addr, management_port = DispatcherConfig.listen_management if DispatcherConfig.management_use_tls: self.management_listener = reactor.listenTLS( management_port, self.management_factory, self.tls_context, interface=management_addr) else: self.management_listener = reactor.listenTCP( management_port, self.management_factory, interface=management_addr)
def _create_connections_as_needed(self): while self.workers < self.max and len(self.waiters) > len(self.connections): socket_name = "opensips_%s%02d.sock" % (self.id, self.workers+1) socket_path = process.runtime_file(socket_name) unlink(socket_path) try: conn = UNIXSocketConnection(socket_path) except CannotListenError, why: log.error("cannot create an OpenSIPS UNIX socket connection: %s" % str(why)) break self.connections.append(conn) self.workers += 1
def __init__(self, dispatcher): self.dispatcher = dispatcher self.relays = {} self.shutting_down = False state_file = process.runtime_file("dispatcher_state") try: self.sessions = pickle.load(open(state_file)) except: self.sessions = {} self.cleanup_timers = {} else: self.cleanup_timers = dict((ip, reactor.callLater(DispatcherConfig.cleanup_dead_relays_after, self._do_cleanup, ip)) for ip in set(session.relay_ip for session in self.sessions.itervalues())) unlink(state_file) self.expired_cleaner = RecurrentCall(600, self._remove_expired_sessions)
def _create_connections_as_needed(self): while self.workers < self.max and len(self.waiters) > len( self.connections): socket_name = "opensips_%s%02d.sock" % (self.id, self.workers + 1) socket_path = process.runtime_file(socket_name) unlink(socket_path) try: conn = UNIXSocketConnection(socket_path) except CannotListenError, why: log.error( "cannot create an OpenSIPS UNIX socket connection: %s" % str(why)) break self.connections.append(conn) self.workers += 1
def __init__(self): self.accounting = [__import__("mediaproxy.interfaces.accounting.%s" % mod.lower(), globals(), locals(), [""]).Accounting() for mod in set(DispatcherConfig.accounting)] self.cred = X509Credentials(cert_name='dispatcher') self.relay_factory = RelayFactory(self) dispatcher_addr, dispatcher_port = DispatcherConfig.listen self.relay_listener = reactor.listenTLS(dispatcher_port, self.relay_factory, self.cred, interface=dispatcher_addr) self.opensips_factory = OpenSIPSControlFactory(self) socket_path = process.runtime_file(DispatcherConfig.socket_path) unlink(socket_path) self.opensips_listener = reactor.listenUNIX(socket_path, self.opensips_factory) self.opensips_management = opensips.ManagementInterface() self.management_factory = ManagementControlFactory(self) management_addr, management_port = DispatcherConfig.listen_management if DispatcherConfig.management_use_tls: self.management_listener = reactor.listenTLS(management_port, self.management_factory, self.cred, interface=management_addr) else: self.management_listener = reactor.listenTCP(management_port, self.management_factory, interface=management_addr)
def __init__(self, dispatcher): self.dispatcher = dispatcher self.relays = {} self.shutting_down = False state_file = process.runtime_file("dispatcher_state") try: self.sessions = pickle.load(open(state_file)) except: self.sessions = {} self.cleanup_timers = {} else: self.cleanup_timers = dict( (ip, reactor.callLater(DispatcherConfig.cleanup_dead_relays_after, self._do_cleanup, ip)) for ip in set(session.relay_ip for session in self.sessions.itervalues())) unlink(state_file) self.expired_cleaner = RecurrentCall(600, self._remove_expired_sessions)
name = 'process-example' # Set the process runtime directory. This is where the pid file and other # process runtime related files will be created. The default is /var/run # but in this example we use /tmp because we need a place where we have # write access even without running as root. process.runtime_directory = '/tmp' # These log lines will go to stdout. log.msg("Starting %s. Check syslog to see what's going on next." % name) log.msg("Use `watch -n .1 ls /tmp' to see how the pid file is created and deleted.") # Set the process to run in the background and create a pid file. # If daemonize is called without arguments or pidfile is None no pid file # will be created. pidfile = process.runtime_file('%s.pid' % name) try: process.daemonize(pidfile) except ProcessError, e: log.fatal(str(e)) sys.exit(1) # process was succesfully put in the background. Redirect logging to syslog log.start_syslog(name) # This log line will go to syslog log.msg('application started (running in the background)') # Add a signal handler for SIGUSR1 process.signals.add_handler(signal.SIGUSR1, signal_handler) # Add another signal handler for SIGUSR1. Mutliple handlers can be added
# Set the process runtime directory. This is where the pid file and other # process runtime related files will be created. The default is /var/run # but in this example we use /tmp because we need a place where we have # write access even without running as root. process.runtime_directory = '/tmp' # These log lines will go to stdout. log.msg("Starting %s. Check syslog to see what's going on next." % name) log.msg( "Use `watch -n .1 ls /tmp' to see how the pid file is created and deleted." ) # Set the process to run in the background and create a pid file. # If daemonize is called without arguments or pidfile is None no pid file # will be created. pidfile = process.runtime_file('%s.pid' % name) try: process.daemonize(pidfile) except ProcessError, e: log.fatal(str(e)) sys.exit(1) # process was successfully put in the background. Redirect logging to syslog log.start_syslog(name) # This log line will go to syslog log.msg('application started (running in the background)') # Add a signal handler for SIGUSR1 process.signals.add_handler(signal.SIGUSR1, signal_handler) # Add another signal handler for SIGUSR1. Multiple handlers can be added
def _save_state(self, result): pickle.dump(self.sessions, open(process.runtime_file("dispatcher_state"), "w"))
name = "process-example" # Set the process runtime directory. This is where the pid file and other # process runtime related files will be created. The default is /var/run # but in this example we use /tmp because we need a place where we have # write access even without running as root. process.runtime_directory = "/tmp" # These log lines will go to stdout. log.msg("Starting %s. Check syslog to see what's going on next." % name) log.msg("Use `watch -n .1 ls /tmp' to see how the pid file is created and deleted.") # Set the process to run in the background and create a pid file. # If daemonize is called without arguments or pidfile is None no pid file # will be created. pidfile = process.runtime_file("%s.pid" % name) try: process.daemonize(pidfile) except ProcessError, e: log.fatal(str(e)) sys.exit(1) # process was successfully put in the background. Redirect logging to syslog log.start_syslog(name) # This log line will go to syslog log.msg("application started (running in the background)") # Add a signal handler for SIGUSR1 process.signals.add_handler(signal.SIGUSR1, signal_handler) # Add another signal handler for SIGUSR1. Multiple handlers can be added