diff --git a/call-control b/call-control old mode 100644 new mode 100755 index 0194fc0..b02d285 --- a/call-control +++ b/call-control @@ -1,118 +1,116 @@ #!/usr/bin/env python """Implementation of a call controller for OpenSIPS.""" def send_command(command, **kwargs): import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect('%s/socket' % process.runtime_directory) sock.sendall('%s\r\n' % command + '\r\n'.join(['%s: %s' % (key, value) for key, value in kwargs.items()]) + '\r\n\r\n') response = '' while True: data = sock.recv(4096) response += data if not data or data.endswith('\r\n\r\n'): break sock.close() for line in response.splitlines(): if line: print line if __name__ == '__main__': import sys from optparse import OptionParser from application.process import process, ProcessError from application import log import callcontrol name = 'call-control' fullname = 'SIP call-control' description = 'Implementation of call-control for SIP' config_directory = '/etc/callcontrol' runtime_directory = '/var/run/callcontrol' default_pid = "%s/%s.pid" % (runtime_directory, name) parser = OptionParser(version="%%prog %s" % callcontrol.__version__) parser.add_option("--no-fork", action="store_false", dest="fork", default=True, help="run the process in the foreground") parser.add_option("--pid", dest="pid_file", default='/var/run/callcontrol/call-control.pid', help="pid file (/var/run/callcontrol/call-control.pid)", metavar="FILE") parser.add_option("--debug", dest="debug", default=None, help="get information about a currently running call-control daemon", metavar="COMMAND") parser.add_option("--terminate", dest="terminate", default=None, help="terminate an on-going session", metavar="CALLID") (options, args) = parser.parse_args() - pid_file = options.pid_file - process.system_config_directory = config_directory try: process.runtime_directory = runtime_directory except ProcessError, e: log.fatal(str(e)) sys.exit(1) if options.debug is not None and options.terminate is not None: log.error('cannot run with both --debug and --terminate options in the same time') sys.exit(1) if options.debug is not None: if options.debug == '': log.error('must specify debug command') sys.exit(1) try: send_command('debug', show=options.debug, **dict([arg.split('=',1) for arg in args if arg.find('=') >= 0])) except Exception, e: log.error('failed to complete debug command: %s' % e) sys.exit(1) else: sys.exit(0) if options.terminate is not None: if options.terminate == '': log.error('must specify callid to terminate') sys.exit(1) try: send_command('terminate', callid=options.terminate) except Exception, e: log.error('failed to terminate session: %s' % e) else: sys.exit(0) if options.fork: try: - process.daemonize(pid_file) + process.daemonize(options.pid_file) except ProcessError, e: log.fatal(str(e)) sys.exit(1) log.start_syslog(name) log.msg("Starting %s %s" % (fullname, callcontrol.__version__)) from callcontrol.controller import CallControlServer if not options.fork: from application.debug.memory import memory_dump try: cserver = CallControlServer() except Exception, e: log.error("failed to create SIP Call Control Server: %s" % e) log.err() sys.exit(1) try: cserver.run() except Exception, e: log.error("failed to start SIP Call Control Server: %s" % e) if not options.fork: memory_dump()