def setupSite(backend): from orbited import logging, config config.map['[access]'][('localhost',61613)] = ['*'] logging.setup(config.map) import orbited.start orbited.start.logger = logging.get_logger('orbited.start') root = static.File(os.path.dirname(backhardding.__file__) + "/html") root.putChild('control', BackharddiNGControl(backend)) static_files = static.File(os.path.dirname(orbited.__file__) + "/static") root.putChild('static', static_files) orbited.start._setup_protocols(root) site = server.Site(root,'/dev/null') return site
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) import platform if platform.system() == "Windows": try: import win32api except ImportError: print "Orbited for Windows requires the Python for Windows Extensions, which are not installed. See http://python.net/crew/mhammond/win32/ for installation instructions." sys.exit(1) 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", ) (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) if options.quickstart: config.map["[listen]"].append("http://:8000") config.map["[listen]"].append("stomp://:61613") config.map["[access]"][("localhost", 61613)] = ["*"] print "Quickstarting Orbited" else: # load configuration from configuration # file and from command line arguments. config.setup(options=options) logging.setup(config.map) # we can now safely get loggers. global logger logger = logging.get_logger("orbited.start") # NB: we need to install the reactor before using twisted. reactor_name = config.map["[global]"].get("reactor") if reactor_name: install = _import("twisted.internet.%sreactor.install" % reactor_name) install() logger.info("using %s reactor" % reactor_name) ############ # This crude garbage corrects a bug in twisted # Orbited ticket: http://orbited.org/ticket/111 # Twisted ticket: http://twistedmatrix.com/trac/ticket/2447 import twisted.web.http twisted.web.http.HTTPChannel.setTimeout = lambda self, arg: None twisted.web.http.HTTPChannel.resetTimeout = lambda self: None ############ from twisted.internet import reactor from twisted.web import resource from twisted.web import server from twisted.web import static import orbited.system root = resource.Resource() static_files = static.File(os.path.join(os.path.dirname(__file__), "static")) root.putChild("static", static_files) root.putChild("system", orbited.system.SystemResource()) if config.map["[test]"]["stompdispatcher.enabled"] == "1": logger.info("stompdispatcher enabled") # static_files.putChild('orbited.swf', static.File(os.path.join(os.path.dirname(__file__), 'flash', 'orbited.swf'))) site = server.Site(root) _setup_protocols(root) _setup_static(root, config.map) start_listening(site, config.map, logger) # switch uid and gid to configured user and group. if os.name == "posix" and os.getuid() == 0: user = config.map["[global]"].get("user") group = config.map["[global]"].get("group") if user: import pwd import grp try: pw = pwd.getpwnam(user) uid = pw.pw_uid if group: gr = grp.getgrnam(group) 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)
Start all server components of dotMap. Each component is a 'Twisted Service': - Django (using twisted.web.wsgi) - Orbited (using the orbited 'cometsession' and 'proxy' modules) - Stomp pub/sub server (using the 'morbid' module from MorbidQ) - RestQMessageProxy (Orbited messages filter/logger/modifier) """ from twisted.web import static, resource, server from twisted.application import internet, service from morbid import StompFactory # Config from orbited import logging, config logging.setup(config.map) INTERFACE = "localhost" #INTERFACE = "spatiallab.ist.psu.edu" #Runtime config, is there a cleaner way?: config.map["[access]"]={(INTERFACE, 9999):"*"} STATIC_PORT = 8000 RESTQ_PROXY_PORT = 5000 STOMP_PORT = 9999 #The below depend on Orbited's logging.setup(...), from above. from orbited import cometsession from orbited import proxy #local imports from djangoweb.twisted_wsgi import get_root_resource from realtime.stompfactory import get_stomp_factory
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) import platform if platform.system() == "Windows": try: import win32api except ImportError: print "Orbited for Windows requires the Python for Windows Extensions, which are not installed. See http://python.net/crew/mhammond/win32/ for installation instructions." sys.exit(1) 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") (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) if options.quickstart: config.map['[listen]'].append('http://:8000') config.map['[listen]'].append('stomp://:61613') config.map['[access]'][('localhost', 61613)] = ['*'] print "Quickstarting Orbited" else: # load configuration from configuration # file and from command line arguments. config.setup(options=options) logging.setup(config.map) # we can now safely get loggers. global logger logger = logging.get_logger('orbited.start') # NB: we need to install the reactor before using twisted. reactor_name = config.map['[global]'].get('reactor') if reactor_name: install = _import('twisted.internet.%sreactor.install' % reactor_name) install() logger.info('using %s reactor' % reactor_name) ############ # This crude garbage corrects a bug in twisted # Orbited ticket: http://orbited.org/ticket/111 # Twisted ticket: http://twistedmatrix.com/trac/ticket/2447 import twisted.web.http twisted.web.http.HTTPChannel.setTimeout = lambda self, arg: None twisted.web.http.HTTPChannel.resetTimeout = lambda self: None ############ from twisted.internet import reactor from twisted.web import resource from twisted.web import server from twisted.web import static import orbited.system root = resource.Resource() static_files = static.File( os.path.join(os.path.dirname(__file__), 'static')) root.putChild('static', static_files) root.putChild('system', orbited.system.SystemResource()) if config.map['[test]']['stompdispatcher.enabled'] == '1': logger.info('stompdispatcher enabled') #static_files.putChild('orbited.swf', static.File(os.path.join(os.path.dirname(__file__), 'flash', 'orbited.swf'))) site = server.Site(root) _setup_protocols(root) _setup_static(root, config.map) start_listening(site, config.map, logger) # switch uid and gid to configured user and group. if os.name == 'posix' and os.getuid() == 0: user = config.map['[global]'].get('user') group = config.map['[global]'].get('group') if user: import pwd import grp try: pw = pwd.getpwnam(user) uid = pw.pw_uid if group: gr = grp.getgrnam(group) 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)
Start all server components of Hotdot. Each component is a 'Twisted Service': - Django (using twisted.web.wsgi) - Orbited (using the orbited 'cometsession' and 'proxy' modules) - Stomp pub/sub server (using the 'morbid' module from MorbidQ) - RestQMessageProxy (Orbited messages filter/logger/modifier) """ from twisted.web import static, resource, server from twisted.application import internet, service from morbid import StompFactory # Config from orbited import logging, config logging.setup(config.map) INTERFACE = "localhost" #Runtime config, is there a cleaner way?: config.map["[access]"]={(INTERFACE, 9999):"*"} STATIC_PORT = 8000 RESTQ_PROXY_PORT = 5000 STOMP_PORT = 9999 #The below depend on Orbited's logging.setup(...), from above. from orbited import cometsession from orbited import proxy #local imports from djangoweb.twisted_wsgi import get_root_resource from realtime.stompfactory import get_stomp_factory from realtime.message_handlers import MESSAGE_HANDLERS
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" ) (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) if options.quickstart: config.map['[listen]'].append('http://:8000') config.map['[listen]'].append('stomp://:61613') config.map['[access]'][('localhost',61613)] = ['*'] print "Quickstarting Orbited" else: # load configuration from configuration # file and from command line arguments. config.setup(options=options) logging.setup(config.map) # we can now safely get loggers. global logger; logger = logging.get_logger('orbited.start') # NB: we need to install the reactor before using twisted. reactor_name = config.map['[global]'].get('reactor') if reactor_name: install = _import('twisted.internet.%sreactor.install' % reactor_name) install() logger.info('using %s reactor' % reactor_name) ############ # This crude garbage corrects a bug in twisted # Orbited ticket: http://orbited.org/ticket/111 # Twisted ticket: http://twistedmatrix.com/trac/ticket/2447 import twisted.web.http twisted.web.http.HTTPChannel.setTimeout = lambda self, arg: None twisted.web.http.HTTPChannel.resetTimeout = lambda self: None ############ from twisted.internet import reactor from twisted.web import resource from twisted.web import server from twisted.web import static import orbited.system root = resource.Resource() static_files = static.File(os.path.join(os.path.dirname(__file__), 'static')) root.putChild('static', static_files) root.putChild('system', orbited.system.SystemResource()) if config.map['[test]']['stompdispatcher.enabled'] == '1': logger.info('stompdispatcher enabled') #static_files.putChild('orbited.swf', static.File(os.path.join(os.path.dirname(__file__), 'flash', 'orbited.swf'))) site = server.Site(root) _setup_protocols(root) _setup_static(root, config.map) start_listening(site, config.map, logger) # switch uid and gid to configured user and group. if os.name == 'posix' and os.getuid() == 0: user = config.map['[global]'].get('user') group = config.map['[global]'].get('group') if user: import pwd import grp try: pw = pwd.getpwnam(user) uid = pw.pw_uid if group: gr = grp.getgrnam(group) 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)