def main(): try: import twisted except ImportError: print "Orbited requires Twisted, which is not installed. See http://twistedmatrix.com/trac/ for installation instructions." sys.exit(1) ################# # This corrects a bug in Twisted 8.2.0 for certain Python 2.6 builds on Windows # Twisted ticket: http://twistedmatrix.com/trac/ticket/3868 # -mario try: from twisted.python import lockfile except ImportError: from orbited import __path__ as orbited_path sys.path.append(os.path.join(orbited_path[0],"hotfixes","win32api")) from twisted.python import lockfile lockfile.kill = None ################# from optparse import OptionParser parser = OptionParser() parser.add_option( "-c", "--config", dest="config", default=None, help="path to configuration file" ) parser.add_option( "-v", "--version", dest="version", action="store_true", default=False, help="print Orbited version" ) parser.add_option( "-p", "--profile", dest="profile", action="store_true", default=False, help="run Orbited with a profiler" ) parser.add_option( "-q", "--quickstart", dest="quickstart", action="store_true", default=False, help="run Orbited on port 8000 and MorbidQ on port 61613" ) parser.add_option( "-d", "--daemon", dest="daemon", action="store_true", default=False, help="run Orbited as a daemon (requires the python-daemon package)" ) parser.add_option( "--pid-file", dest="pidfile", default="/var/run/orbited/orbited.pid", help=("use PIDFILE as the orbited daemon pid file", "; defaults to '/var/run/orbited/orbited.pid'"), ) MemoryUtil.add_options_to_parser(parser) (options, args) = parser.parse_args() if args: print 'the "orbited" command does not accept positional arguments. type "orbited -h" for options.' sys.exit(1) if options.version: print "Orbited version: %s" % (version,) sys.exit(0) global logger if options.quickstart: logging.basicConfig() logger = logging.getLogger(__name__) config.map['[listen]'].append('http://:8000') config.map['[listen]'].append('stomp://:61613') config.map['[access]'][('localhost',61613)] = ['*'] logger.info("Quickstarting Orbited") else: # load configuration from configuration # file and from command line arguments. config.setup(options=options) logging.config.fileConfig(options.config) logger = logging.getLogger(__name__) logger.info("Starting Orbited with config file %s" % options.config) if options.daemon: try: from daemon import DaemonContext from daemon.pidfile import PIDLockFile pidlock = PIDLockFile(options.pidfile) daemon = DaemonContext(pidfile=pidlock) logger.debug('daemonizing with pid file %r', options.pidfile) daemon.open() logger.debug('daemonized!') except Exception, exc: logger.debug(exc)
def main(): try: import twisted except ImportError: print "Orbited requires Twisted, which is not installed. See http://twistedmatrix.com/trac/ for installation instructions." sys.exit(1) ################# # This corrects a bug in Twisted 8.2.0 for certain Python 2.6 builds on Windows # Twisted ticket: http://twistedmatrix.com/trac/ticket/3868 # -mario try: from twisted.python import lockfile except ImportError: from orbited import __path__ as orbited_path sys.path.append(os.path.join(orbited_path[0], "hotfixes", "win32api")) from twisted.python import lockfile lockfile.kill = None ################# from optparse import OptionParser parser = OptionParser() parser.add_option("-c", "--config", dest="config", default=None, help="path to configuration file") parser.add_option("-v", "--version", dest="version", action="store_true", default=False, help="print Orbited version") parser.add_option("-p", "--profile", dest="profile", action="store_true", default=False, help="run Orbited with a profiler") parser.add_option( "-q", "--quickstart", dest="quickstart", action="store_true", default=False, help="run Orbited on port 8000 and MorbidQ on port 61613") parser.add_option( "-d", "--daemon", dest="daemon", action="store_true", default=False, help="run Orbited as a daemon (requires the python-daemon package)") parser.add_option( "--pid-file", dest="pidfile", default="/var/run/orbited/orbited.pid", help=("use PIDFILE as the orbited daemon pid file", "; defaults to '/var/run/orbited/orbited.pid'"), ) MemoryUtil.add_options_to_parser(parser) (options, args) = parser.parse_args() if args: print 'the "orbited" command does not accept positional arguments. type "orbited -h" for options.' sys.exit(1) if options.version: print "Orbited version: %s" % (version, ) sys.exit(0) global logger if options.quickstart: logging.basicConfig() logger = logging.getLogger(__name__) config.map['[listen]'].append('http://:8000') config.map['[listen]'].append('stomp://:61613') config.map['[access]'][('localhost', 61613)] = ['*'] logger.info("Quickstarting Orbited") else: # load configuration from configuration # file and from command line arguments. config.setup(options=options) logging.config.fileConfig(options.config) logger = logging.getLogger(__name__) logger.info("Starting Orbited with config file %s" % options.config) if options.daemon: try: from daemon import DaemonContext from daemon.pidfile import PIDLockFile pidlock = PIDLockFile(options.pidfile) daemon = DaemonContext(pidfile=pidlock) logger.debug('daemonizing with pid file %r', options.pidfile) daemon.open() logger.debug('daemonized!') except Exception, exc: logger.debug(exc)
gid = gr.gr_gid else: gid = pw.pw_gid gr = grp.getgrgid(gid) group = gr.gr_name except Exception, e: logger.error('Aborting; Unknown user or group: %s' % e) sys.exit(1) logger.info('switching to user %s (uid=%d) and group %s (gid=%d)' % (user, uid, group, gid)) os.setgid(gid) os.setuid(uid) else: logger.error('Aborting; You must define a user (and optionally a group) in the configuration file.') sys.exit(1) if MemoryUtil.manhole_requested(options): memory_util = MemoryUtil(options) memory_util.install(reactor) if options.profile: import hotshot prof = hotshot.Profile("orbited.profile") logger.info("running Orbited in profile mode") logger.info("for information on profiler, see http://orbited.org/wiki/Profiler") prof.runcall(reactor.run) prof.close() else: reactor.run() class URLParseResult(object):
gr = grp.getgrgid(gid) group = gr.gr_name except Exception, e: logger.error('Aborting; Unknown user or group: %s' % e) sys.exit(1) logger.info('switching to user %s (uid=%d) and group %s (gid=%d)' % (user, uid, group, gid)) os.setgid(gid) os.setuid(uid) else: logger.error( 'Aborting; You must define a user (and optionally a group) in the configuration file.' ) sys.exit(1) if MemoryUtil.manhole_requested(options): memory_util = MemoryUtil(options) memory_util.install(reactor) if options.profile: import hotshot prof = hotshot.Profile("orbited.profile") logger.info("running Orbited in profile mode") logger.info( "for information on profiler, see http://orbited.org/wiki/Profiler" ) prof.runcall(reactor.run) prof.close() else: reactor.run()