def run(): global application, stop_application #pragma: no cover app.startApplication(application, None) #pragma: no cover if stop_application: stop_application.addCallback( lambda x: reactor.stop()) #pragma: no cover reactor.run() #pragma: no cover
def execute(config_file): global config config = _get_config(config_file) log.startLogging(sys.stderr) application = get_application(config) app.startApplication(application, False) reactor.run() #@UndefinedVariable
def siptrackd_twisted_init(object_store, application): log.msg('Loading object store, this might take a while') yield object_store.init() log.msg('Object store loading complete') log.msg('Starting rpc listener') app.startApplication(application, False) log.msg('Running')
def startApplication(self, application): """ Configure global process state based on the given application and run the application. @param application: An object which can be adapted to L{service.IProcess} and L{service.IService}. """ process = service.IProcess(application) if not self.config['originalname']: launchWithName(process.processName) self.setupEnvironment(self.config['chroot'], self.config['rundir'], self.config['nodaemon'], self.config['umask'], self.config['pidfile']) service.IService(application).privilegedStartService() uid, gid = self.config['uid'], self.config['gid'] if uid is None: uid = process.uid if gid is None: gid = process.gid if uid is not None and gid is None: gid = pwd.getpwuid(uid).pw_gid self.shedPrivileges(self.config['euid'], uid, gid) app.startApplication(application, not self.config['no_save'])
def daemon(): from twisted.internet import glib2reactor glib2reactor.install() from twisted.internet import reactor main_app = Application("Audio Failure Monitor") #, uid, gid) services = IServiceCollection(main_app) options = DaemonOptions() options.parseOptions() application = options.getService() application.infotub.setServiceParent(services) application.coretub.setServiceParent(services) app.startApplication(main_app, False) reactor.addSystemEventTrigger('before', 'shutdown', logging.getLogger(__name__).info, 'Stopping AFM') logging.getLogger(__name__).info("AFM Started") try: reactor.run() except KeyboardInterrupt: reactor.stop()
def startApplication(self, application): """ Configure global process state based on the given application and run the application. @param application: An object which can be adapted to L{service.IProcess} and L{service.IService}. """ process = service.IProcess(application) if not self.config['originalname']: launchWithName(process.processName) self.setupEnvironment( self.config['chroot'], self.config['rundir'], self.config['nodaemon'], self.config['umask'], self.config['pidfile']) service.IService(application).privilegedStartService() uid, gid = self.config['uid'], self.config['gid'] if uid is None: uid = process.uid if gid is None: gid = process.gid self.shedPrivileges(self.config['euid'], uid, gid) app.startApplication(application, not self.config['no_save'])
def handle_noargs(self, *args, **options): ## ! XXX: `from django.utils import autoreload`? Might put it into ## xmppface or xmppwoker from xmppface.s2scfg import cfg_override from xmppface.s2sbase import setup_twisted_app application = setup_twisted_app(cfg_override(settings)) startApplication(application, False) reactor.run()
def execute(): try: config = _get_config() except NotConfigured: config = None log.startLogging(sys.stderr) application = get_application(config) app.startApplication(application, False) reactor.run()
def postApplication(self): """ Start the application and run the reactor. """ service.IService(self.application).privilegedStartService() app.startApplication(self.application, not self.config['no_save']) app.startApplication(internet.TimerService(0.1, lambda:None), 0) self.startReactor(None, self.oldstdout, self.oldstderr) log.msg("Server Shut Down.")
def runApp(res): """ Start the actual service Application. """ log.debug("[D] %s %s " % (__file__, __name__), "Class GLBaseRunner", "preApplication", "runApp") service.IService(self.application).privilegedStartService() app.startApplication(self.application, not self.config['no_save']) app.startApplication(internet.TimerService(0.1, lambda:None), 0) startAsynchronous()
def SvcDoRun(self): win32evtlogutil.AddSourceToRegistry(self._svc_name_, servicemanager.__file__) # Write a 'started' event to the event log... win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STARTED, 0, # category servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, ""), ) try: return_code = self.run_connectivity_tool() if return_code != 0: # raise Exception("Authentication Proxy Configuration has an error.") # We're choosing not to prevent auth proxy startup if there are # config errors for now, but once the configuration validation # proves to be stable we can go back to preventing startup. message = ("Your configuration is not valid. Check the output " "at {conn_tool_logs} for errors.".format( conn_tool_logs=self.conn_tool_logs)) self.log_error_during_startup(message) application = duoauthproxy.proxy.create_application() app.startApplication(application, 0) reactor.run(installSignalHandlers=0) except Exception: # service did not shut down cleanly message = traceback.format_exc() win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STOPPED, 0, # category servicemanager.EVENTLOG_ERROR_TYPE, ( self._svc_name_, " due to a failure:\n\n%s\n" "We could not start your Authentication Proxy due to an error. Likely this is a configuration error. To view the error output check the logs located at %s \n" "After fixing the errors you can run a test of your configuration using our validator located at %s" % (message, self.conn_tool_logs, self.conn_tool_path), ), ) else: # service shut down cleanly win32evtlogutil.ReportEvent( self._svc_name_, servicemanager.PYS_SERVICE_STOPPED, 0, # category servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, ""), ) win32event.SetEvent(self.hWaitStop)
def postApplication(self): """ Start the application and run the reactor. """ service.IService(self.application).privilegedStartService() app.startApplication(self.application, not self.config['no_save']) app.startApplication(internet.TimerService(0.1, lambda: None), 0) app.runReactorWithLogging(self.config, self.oldstdout, self.oldstderr) app.reportProfile(self.config['report-profile'], service.IProcess(self.application).processName) log.msg("Server Shut Down.")
def postApplication(self): """ Start the application and run the reactor. """ service.IService(self.application).privilegedStartService() app.startApplication(self.application, not self.config['no_save']) app.startApplication(internet.TimerService(0.1, lambda:None), 0) app.runReactorWithLogging(self.config, self.oldstdout, self.oldstderr) app.reportProfile(self.config['report-profile'], service.IProcess(self.application).processName) log.msg("Server Shut Down.")
def run(): if platform.system() != "Windows": if not sys.modules.has_key('twisted.internet.reactor'): print "installing epoll reactor" from twisted.internet import epollreactor epollreactor.install() else: print "reactor already installed" from twisted.internet import reactor application = makeApplication(sys.argv) app.startApplication(application, None) reactor.run()
def run(): if platform.system() != "Windows": if not sys.modules.has_key('twisted.internet.reactor'): print "installing poll reactor" pollreactor.install() else: print "poll reactor already installed" from twisted.internet import reactor application = makeApplication(sys.argv) app.startApplication(application, None) from twisted.internet import pollreactor reactor.run()
def start(self, portno=None): import sys lfname = self['logfile'] if lfname == '-': lf = sys.stdout else: lf = file(os.path.expanduser(lfname), 'ab+') log.startLogging(lf, setStdout=False) srv = self.getService() from twisted.application.app import startApplication startApplication(srv, False) reactor.run()
def run(): twisted_log.startLogging(sys.stdout) if platform.system() != "Windows": if 'twisted.internet.reactor' not in sys.modules: log.debug("installing epoll reactor") from twisted.internet import epollreactor epollreactor.install() else: log.debug("reactor already installed") from twisted.internet import reactor application = makeApplication(sys.argv) app.startApplication(application, None) reactor.run()
def run(appName): application = service.Application(appName) from sparked import tap config = tap.Options() config.parseOptions(sys.argv[1:]) svc = tap.makeService(config) svc.setServiceParent(application) app.startApplication(application, False) log.addObserver(log.FileLogObserver(sys.stdout).emit) reactor.run()
def startApplication(config, application): process = service.IProcess(application, None) if not config["originalname"]: launchWithName(process.processName) setupEnvironment(config) service.IService(application).privilegedStartService() uid, gid = mktap.getid(config["uid"], config["gid"]) if uid is None: uid = process.uid if gid is None: gid = process.gid shedPrivileges(config["euid"], uid, gid) app.startApplication(application, not config["no_save"])
def run(argv): twisted_log.startLoggingWithObserver(RefloggingObserver()) if platform.system() != "Windows": if 'twisted.internet.reactor' not in sys.modules: log.debug("installing epoll reactor") from twisted.internet import epollreactor epollreactor.install() else: log.debug("reactor already installed") from twisted.internet import reactor application = makeApplication(argv) app.startApplication(application, None) reactor.run()
def execute(): sys.path.insert(0, os.getcwd()) arguments = parse_arguments() if arguments.settings: settings.setmodule(arguments.settings) if arguments.set: for name, value in arguments.set: settings.set(name.upper(), value) settings.set('PROJECT_SETTINGS', find_scrapy_project(arguments.project)) settings.freeze() setup_logging() application = get_application(arguments) app.startApplication(application, save=False) reactor.run()
def start_services(config): client = XMPPClient(jid.internJID(config.credentials['jid']), config.credentials['password']) application = service.Application('commitbot') bot = CommitBot(config) bot.setHandlerParent(client) site = server.Site(WebHook(config, bot)) tcp_server = reactor.listenTCP(8888, site) app.startApplication(application, None) client.startService() reactor.run()
def startApplication(config, application): process = service.IProcess(application, None) if not config['originalname']: launchWithName(process.processName) setupEnvironment(config) service.IService(application).privilegedStartService() uid, gid = mktap.getid(config['uid'], config['gid']) if uid is None: uid = process.uid if gid is None: gid = process.gid shedPrivileges(config['euid'], uid, gid) app.startApplication(application, not config['no_save'])
def runApp(config): passphrase = app.getPassphrase(config['encrypted']) app.installReactor(config['reactor']) application = app.getApplication(config, passphrase) oldstdout = sys.stdout oldstderr = sys.stderr startLogging(config['logfile']) app.initialLog() os.chdir(config['rundir']) service.IService(application).privilegedStartService() app.startApplication(application, not config['no_save']) app.startApplication(internet.TimerService(0.1, lambda: None), 0) app.runReactorWithLogging(config, oldstdout, oldstderr) app.reportProfile(config['report-profile'], service.IProcess(application).processName) log.msg("Server Shut Down.")
def runApp(config): passphrase = app.getPassphrase(config['encrypted']) app.installReactor(config['reactor']) application = app.getApplication(config, passphrase) oldstdout = sys.stdout oldstderr = sys.stderr startLogging(config['logfile']) app.initialLog() os.chdir(config['rundir']) service.IService(application).privilegedStartService() app.startApplication(application, not config['no_save']) app.startApplication(internet.TimerService(0.1, lambda:None), 0) app.runReactorWithLogging(config, oldstdout, oldstderr) app.reportProfile(config['report-profile'], service.IProcess(application).processName) log.msg("Server Shut Down.")
def _inner_run(): # Initialize logging log.startLogging(sys.stdout) # Setup Twisted application application = service.Application('django') wsgi_root = wsgi_resource() root = Root(wsgi_root) main_site = server.Site(root) internet.TCPServer(int(self.port), main_site ).setServiceParent(application) service.IService(application).startService() app.startApplication(application, False) reactor.addSystemEventTrigger('before', 'shutdown', service.IService(application).stopService) reactor.run()
def SvcDoRun(self): import servicemanager from LJSocket import SocketServiceFactory, DeviceManager import ljsocketServiceTac self.CheckForQuit() try: f = file("C:\LJSocket.log", 'w') except: f = file("LJSocket.log", 'w') from twisted.python.log import startLogging from twisted.application.app import startApplication from twisted.internet import reactor startLogging(f) startApplication(ljsocketServiceTac.application, 0) #reactor.run() reactor.run(installSignalHandlers=0)
def _inner_run(): # Initialize logging log.startLogging(sys.stdout) # Setup Twisted application application = service.Application('django') root = Root(wsgi_resource()) # Handle static files root.putChild('static', StaticFileFinder('/')) main_site = server.Site(root) internet.TCPServer(int(self.port), main_site).setServiceParent(application) service.IService(application).startService() app.startApplication(application, False) reactor.addSystemEventTrigger('before', 'shutdown', service.IService(application).stopService) self._start_bebop(use_repl) reactor.run()
def run_landscape_service(configuration_class, service_class, args): """Run a Landscape service. This function instantiates the specified L{LandscapeService} subclass and attaches the resulting service object to a Twisted C{Application}. After that it starts the Twisted L{Application} and calls the L{LandscapeReactor.run} method of the L{LandscapeService}'s reactor. @param configuration_class: The service-specific subclass of L{Configuration} used to parse C{args} and build the C{service_class} object. @param service_class: The L{LandscapeService} subclass to create and start. @param args: Command line arguments used to initialize the configuration. """ # Let's consider adding this: # from twisted.python.log import ( # startLoggingWithObserver, PythonLoggingObserver) # startLoggingWithObserver(PythonLoggingObserver().emit, setStdout=False) configuration = configuration_class() configuration.load(args) init_logging(configuration, service_class.service_name) application = Application("landscape-%s" % (service_class.service_name,)) service = service_class(configuration) service.setServiceParent(application) if configuration.clones > 0: # Increase the timeout of AMP's MethodCalls # XXX: we should find a better way to expose this knot, and # not set it globally on the class from landscape.lib.amp import MethodCallSender MethodCallSender.timeout = 300 # Create clones here because LandscapeReactor.__init__ would otherwise # cancel all scheduled delayed calls clones = [] for i in range(configuration.clones): clone_config = configuration.clone() clone_config.computer_title += " Clone %d" % i clone_config.master_data_path = configuration.data_path clone_config.data_path += "-clone-%d" % i clone_config.log_dir += "-clone-%d" % i clone_config.is_clone = True clones.append(service_class(clone_config)) configuration.is_clone = False def start_clones(): # Spawn instances over the given time window start_clones_over = float(configuration.start_clones_over) delay = start_clones_over / configuration.clones for i, clone in enumerate(clones): def start(clone): clone.setServiceParent(application) clone.reactor.fire("run") service.reactor.call_later(delay * (i + 1), start, clone=clone) service.reactor.call_when_running(start_clones) startApplication(application, False) if configuration.ignore_sigint: signal.signal(signal.SIGINT, signal.SIG_IGN) service.reactor.run()
def render_POST(self, request): request.setHeader('Access-Control-Allow-Origin', get_allow_origin(request)) request.setHeader('Access-Control-Allow-Methods', 'POST') request.setHeader('Access-Control-Allow-Headers', 'x-prototype-version,x-requested-with,Content-Type') request.setHeader('Access-Control-Max-Age', 2520) # 42 hours data = simplejson.loads(request.content.getvalue()) try: if isinstance(data, list): for datum in data: log_json(datum) else: log_json(data) except Exception as e: logger_err.error(e) return '' root = Resource() root.putChild('send_log', Logger()) # create a resource to serve static files tmp_service = internet.TCPServer(settings['port'], Site(root)) application = service.Application('User-ALE') # attach the service to its parent application tmp_service.setServiceParent(application) startApplication(application, 0) reactor.run()
def run_twisted_app(): app = initialize_app('opencanaryd', config) startApplication(app, 0) logMsg('Canary running!!!') reactor.run()
get_allow_origin(request)) request.setHeader('Access-Control-Allow-Methods', 'POST') request.setHeader('Access-Control-Allow-Headers', 'x-prototype-version,x-requested-with,Content-Type') request.setHeader('Access-Control-Max-Age', 2520) # 42 hours data = simplejson.loads(request.content.getvalue()) try: if isinstance(data, list): for datum in data: log_json(request, datum) else: log_json(request, data) except Exception as e: logger_err.error(e) return '' root = Resource() root.putChild('send_log', Logger()) # create a resource to serve static files tmp_service = internet.TCPServer(settings['port'], Site(root)) application = service.Application('User-ALE') # attach the service to its parent application tmp_service.setServiceParent(application) startApplication(application, 0) reactor.run()
def run(): twisted_log.startLoggingWithObserver(RefloggingObserver()) application = makeApplication(sys.argv[1:]) app.startApplication(application, None) reactor.run()
from twisted.internet import reactor from twisted.python import log from scrapyd import Config from scrapyd.app import application def _get_config(args): scrapyd_config = Config() section = 'scrapyd' scrapyd_config.cp.set(section, 'http_port', args.http_port) if args.auth is not None: username, password = args.auth.split(":") scrapyd_config.cp.set(section, 'username', username) scrapyd_config.cp.set(section, 'password', password) return scrapyd_config if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('http_port', default=6800) parser.add_argument('--auth', default=None) args = parser.parse_args() log.startLogging(sys.stdout) conf = _get_config(args) application = application(config=conf) app.startApplication(application, False) reactor.run()
def xt_set_it(): from twisted.application.app import startApplication from twisted.internet import reactor startApplication(application, False) # reactor.run() return reactor
def test_startApplication(self): appl = service.Application("lala") app.startApplication(appl, 0) self.assert_(service.IService(appl).running)
def run(): app.startApplication(application, None) reactor.run()
def run(): application = makeApplication(sys.argv[1:]) app.startApplication(application, None) reactor.run()
def execute(): config = _get_config() log.startLogging(sys.stderr) application = get_application(config) app.startApplication(application, False) reactor.run()
def child_highestshaman(self, ctx): r = CACHED.get("highestshaman", None) if r: return r r = CACHED["highestshaman"] = self.highestprimaryclass(ctx, "Shaman") return r def child_highestmonk(self, ctx): r = CACHED.get("highestmonk", None) if r: return r r = CACHED["highestmonk"] = self.highestprimaryclass(ctx, "Monk") return r def child_highestdoomknight(self, ctx): r = CACHED.get("highestdoomknight", None) if r: return r r = CACHED["highestdoomknight"] = self.highestprimaryclass( ctx, "Doom Knight") return r reactor.callLater(0, GetWorldStats) application = service.Application("StatSite") strports.service("8000", appserver.NevowSite(StatSite())).setServiceParent(application) app.startApplication(application, None) reactor.run()
def _startApplication(self): if not platform.isWinNT(): twistd.startApplication(self, self.application) else: service.IService(self.application).privilegedStartService() app.startApplication(self.application, False)
def run(): global application, stop_application #pragma: no cover app.startApplication(application, None) #pragma: no cover if stop_application: stop_application.addCallback(lambda x: reactor.stop()) #pragma: no cover reactor.run() #pragma: no cover
r = CACHED.get("highestthief",None) if r: return r r=CACHED["highestthief"]=self.highestprimaryclass(ctx,"Thief") return r def child_highestshaman(self, ctx): r = CACHED.get("highestshaman",None) if r: return r r=CACHED["highestshaman"]=self.highestprimaryclass(ctx,"Shaman") return r def child_highestmonk(self, ctx): r = CACHED.get("highestmonk",None) if r: return r r=CACHED["highestmonk"]=self.highestprimaryclass(ctx,"Monk") return r def child_highestdoomknight(self, ctx): r = CACHED.get("highestdoomknight",None) if r: return r r=CACHED["highestdoomknight"]=self.highestprimaryclass(ctx,"Doom Knight") return r reactor.callLater(0,GetWorldStats) application = service.Application("StatSite") strports.service("8000", appserver.NevowSite(StatSite())).setServiceParent(application) app.startApplication(application,None) reactor.run()
def startApplication(self): """Start the application and setup shutdown hooks.""" app.startApplication(self.application, False)