-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcall-control
executable file
·90 lines (72 loc) · 3.32 KB
/
call-control
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python3
"""Call control engine for OpenSIPS"""
if __name__ == '__main__':
import callcontrol
import sys
from application import log
from application.process import process, ProcessError
from argparse import ArgumentParser
name = 'call-control'
fullname = 'SIP call-control engine'
description = 'Implementation of a call-control engine for SIP'
process.configuration.user_directory = None
process.configuration.subdirectory = 'callcontrol'
process.runtime.subdirectory = 'callcontrol'
parser = ArgumentParser(usage='%(prog)s [options]')
parser.add_argument('--version', action='version', version='%(prog)s {}'.format(callcontrol.__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 the terminal')
parser.add_argument('--config-dir', dest='config_directory', default=None, help='the configuration directory ({})'.format(process.configuration.system_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
try:
process.runtime.create_directory()
except ProcessError as e:
log.critical('Cannot start %s: %s', fullname, e)
sys.exit(1)
if options.systemd:
from systemd.journal import JournalHandler
log.set_handler(JournalHandler(SYSLOG_IDENTIFIER=name))
log.capture_output()
elif options.fork:
try:
process.daemonize(pidfile='{}.pid'.format(name))
except ProcessError as e:
log.critical('Cannot start %s: %s', fullname, e)
sys.exit(1)
log.use_syslog(name)
log.info('Starting %s %s', fullname, callcontrol.__version__)
try:
process.wait_for_network(wait_time=10, wait_message='Waiting for network to become available...')
except KeyboardInterrupt:
sys.exit(0)
except RuntimeError as e:
log.critical('Cannot start %s: %s' % (fullname, e))
sys.exit(1)
from callcontrol.controller import CallControlServer
if options.debug:
log.level.current = log.level.DEBUG
if options.debug_memory:
from application.debug.memory import memory_dump
try:
server = CallControlServer()
except Exception as e:
log.critical('Could not create %s: %s', fullname, e)
if type(e) is not RuntimeError:
log.exception()
sys.exit(1)
try:
server.run()
except Exception as e:
log.critical('Could not run %s: %s', fullname, e)
if type(e) is not RuntimeError:
log.exception()
if options.debug_memory:
memory_dump()