| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | # Copyright (C) 2008 AG Projects |
|---|
| 4 | # |
|---|
| 5 | |
|---|
| 6 | """MediaProxy Dispatcher component""" |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | if __name__ == "__main__": |
|---|
| 10 | import sys |
|---|
| 11 | from optparse import OptionParser |
|---|
| 12 | from application.process import process, ProcessError |
|---|
| 13 | from application import log |
|---|
| 14 | import mediaproxy |
|---|
| 15 | |
|---|
| 16 | name = "media-dispatcher" |
|---|
| 17 | fullname = "MediaProxy Dispatcher" |
|---|
| 18 | description = "MediaProxy Dispatcher component" |
|---|
| 19 | |
|---|
| 20 | default_pid = mediaproxy.runtime_directory + '/dispatcher.pid' |
|---|
| 21 | |
|---|
| 22 | parser = OptionParser(version="%%prog %s" % mediaproxy.__version__) |
|---|
| 23 | parser.add_option("--no-fork", action="store_false", dest="fork", default=1, help="run the process in the foreground (for debugging)") |
|---|
| 24 | parser.add_option("--pid", dest="pid_file", default=default_pid, help="pid file (%s)" % default_pid, metavar="File") |
|---|
| 25 | (options, args) = parser.parse_args() |
|---|
| 26 | |
|---|
| 27 | pid_file = options.pid_file |
|---|
| 28 | |
|---|
| 29 | process._system_config_directory = mediaproxy.system_config_directory |
|---|
| 30 | try: |
|---|
| 31 | process.runtime_directory = mediaproxy.runtime_directory |
|---|
| 32 | except ProcessError, e: |
|---|
| 33 | log.fatal("Cannot start %s: %s" % (fullname, e)) |
|---|
| 34 | sys.exit(1) |
|---|
| 35 | |
|---|
| 36 | if options.fork: |
|---|
| 37 | try: |
|---|
| 38 | process.daemonize(pid_file) |
|---|
| 39 | except ProcessError, e: |
|---|
| 40 | log.fatal("Cannot start %s: %s" % (fullname, e)) |
|---|
| 41 | sys.exit(1) |
|---|
| 42 | log.startSyslog(name) |
|---|
| 43 | |
|---|
| 44 | log.msg("Starting %s %s" % (fullname, mediaproxy.__version__)) |
|---|
| 45 | |
|---|
| 46 | from mediaproxy.dispatcher import Dispatcher |
|---|
| 47 | |
|---|
| 48 | if not options.fork: |
|---|
| 49 | from application.debug.memory import * |
|---|
| 50 | |
|---|
| 51 | try: |
|---|
| 52 | dispatcher = Dispatcher() |
|---|
| 53 | except Exception, e: |
|---|
| 54 | log.fatal("failed to create %s: %s" % (fullname, e)) |
|---|
| 55 | if e.__class__ is not RuntimeError: |
|---|
| 56 | log.err() |
|---|
| 57 | sys.exit(1) |
|---|
| 58 | |
|---|
| 59 | dispatcher.run() |
|---|
| 60 | |
|---|
| 61 | if not options.fork: |
|---|
| 62 | #from application.debug.memory import * |
|---|
| 63 | memory_dump() |
|---|