def startService(self): MultiService.startService(self) def _set_api_endpoint(port): endpoint = client_endpoint_from_address(port.getHost()) if endpoint is not None: self.config.api_client_endpoint = endpoint return None def _stop_reactor(failure): self.config.api_client_endpoint = None self._run_deferred.errback(failure) return None observe = self._listen_endpoint.observe() observe.addCallback(_set_api_endpoint) observe.addErrback(_stop_reactor) ds = [observe] for magic_folder in self._iter_magic_folder_services(): ds.append(magic_folder.ready()) # double-check that our api-endpoint exists properly in the "output" file self.config._write_api_client_endpoint() # The integration tests look for this message. You cannot get rid of # it (without also changing the tests). self.log.info("Completed initial Magic Folder setup", ) self._starting = gatherResults(ds)
def startService(self): MultiService.startService(self) clusterDir = self.dataStoreDirectory.child("cluster") workingDir = self.dataStoreDirectory.child("working") env = self.env = os.environ.copy() env.update(PGDATA=clusterDir.path, PGHOST=self.socketDir.path) initdb = which("initdb")[0] if not self.socketDir.isdir(): self.socketDir.createDirectory() if self.uid and self.gid: os.chown(self.socketDir.path, self.uid, self.gid) if self.dataStoreDirectory.isdir(): self.startDatabase() else: self.dataStoreDirectory.createDirectory() workingDir.createDirectory() if self.uid and self.gid: os.chown(self.dataStoreDirectory.path, self.uid, self.gid) os.chown(workingDir.path, self.uid, self.gid) dbInited = Deferred() reactor.spawnProcess( CapturingProcessProtocol(dbInited, None), initdb, [initdb], env, workingDir.path, uid=self.uid, gid=self.gid, ) def doCreate(result): self.startDatabase() dbInited.addCallback(doCreate)
def startService(self): global configurations, expectations print "Loaded configurations: " + str(configurations) reload(sys) sys.setdefaultencoding('utf8') Expectations.display(expectations) MultiService.startService(self)
class TestTCPRedirect(TestUDPRedirect): def setUp(self): self.service = MultiService() self.received = [] class Collect(LineReceiver): def lineReceived(cself, data): self.got_data(data) class CollectFactory(Factory): def buildProtocol(self, addr): return Collect() self.port = reactor.listenTCP(0, CollectFactory()) self.processor = TestMessageProcessor() self.router = Router(self.processor, r"any => redirect_tcp 127.0.0.1 %s" % (self.port.getHost().port,), service=self.service) self.service.startService() return self.router.ready
def startService(self): # create WebSocket echo service and make it a child of our app service svc = EchoService(self.port) svc.setName("EchoService") svc.setServiceParent(self) MultiService.startService(self)
class TestServicesBase: run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=5) def setUp(self): super(TestServicesBase, self).setUp() self.observers = theLogPublisher.observers[:] self.services = MultiService() self.services.privilegedStartService() self.services.startService() def tearDown(self): super(TestServicesBase, self).tearDown() d = self.services.stopService() # The log file must be read in right after services have stopped, # before the temporary directory where the log lives is removed. d.addBoth(lambda ignore: self.addDetailFromLog()) d.addBoth(lambda ignore: self.assertNoObserversLeftBehind()) return d def addDetailFromLog(self): content = content_from_file(self.log_filename, buffer_now=True) self.addDetail("log", content) def assertNoObserversLeftBehind(self): self.assertEqual(self.observers, theLogPublisher.observers)
def run_proxy(args=None): service = MultiService() options = get_options(args) open_log(os.path.join(options['gamedir'], 'proxy.log')) pidfile = os.path.join(options['gamedir'], 'proxy.pid') check_pid(pidfile) config.read(options.config_paths()) port = config.getint('Proxy', 'AMP port') factory = ReconnectingClientFactory() factory.maxDelay = 1 factory.protocol = AmpClientProtocol client = internet.TCPClient('127.0.0.1', port, factory) service.addService(client) ports_str = config.get('Proxy', 'telnet ports') for portVal in ports_str.split(','): try: port = int(portVal) except ValueError: continue factory = ServerFactory() factory.protocol = ProxyTelnetSession child = internet.TCPServer(port, factory) child.setName("ProxyTelnet%d" % port) service.addService(child) service.startService() reactor.run() os.remove(pidfile)
def startService(self): # create WebSocket echo service and make it a child of our app service svc = EchoService(self.port) svc.setName("EchoService") svc.setServiceParent(self) MultiService.startService(self)
def startService(self) -> None: options = self._options server_directory = options.get('servdir') or 'my_cipolla_server' server_directory = os.path.expanduser(server_directory) cfgfile = options.get('config-file') or 'cipolla.cfg' # if not len(logging._handlers): # logging.basicConfig() if not os.path.exists(server_directory): fatal( "The specified server directory, {!r}, does not exist. Use the -i flag to create it." .format(server_directory)) os.chdir(server_directory) logger.info("Using server directory; {!r}".format( os.path.abspath(os.curdir))) ConfigManager(cfgfile) cipolla = CipollaServer() cipolla.root_service.setServiceParent(self) MultiService.startService(self) logger.cipolla_event("Server started.") # type: ignore
def startService(self): # Set up configuration manager self.config = self._build_config_manager() yield self.config.prepare() yield self.prepareService() MultiService.startService(self)
def startService(self): self.setupService() self.log(log.info, u'Starting') # Start ourselves as Twisted Service MultiService.startService(self) # Start all worker tasks self.startTasks()
def startService(self): log.msg('...Booting...', system="Bouser") self.reload_config() log.callWithContext({"system": "Bootstrap"}, boot.send, self) log.callWithContext({"system": "Checking Dependencies"}, check_deps.send, self) if self.fail: raise RuntimeError('Not all dependencies satisfied') else: MultiService.startService(self)
def startService(self): MultiService.startService(self) self.happy = self.find_happy_shares() self._poller = PeriodicService( self.reactor, 5, self._update_status, ) self._poller.setServiceParent(self)
def startService(self): MultiService.startService(self) self.activateDelayedShutdown() clusterDir = self.dataStoreDirectory.child(self.clusterName) env = self.env = os.environ.copy() env.update(PGDATA=clusterDir.path, PGHOST=self.host, PGUSER=self.spawnedDBUser) if self.socketDir: if not self.socketDir.isdir(): log.info("Creating {dir}", dir=self.socketDir.path.decode("utf-8")) self.socketDir.createDirectory() if self.uid and self.gid: os.chown(self.socketDir.path, self.uid, self.gid) os.chmod(self.socketDir.path, 0770) if not self.dataStoreDirectory.isdir(): log.info("Creating {dir}", dir=self.dataStoreDirectory.path.decode("utf-8")) self.dataStoreDirectory.createDirectory() if not self.workingDir.isdir(): log.info("Creating {dir}", dir=self.workingDir.path.decode("utf-8")) self.workingDir.createDirectory() if self.uid and self.gid: os.chown(self.dataStoreDirectory.path, self.uid, self.gid) os.chown(self.workingDir.path, self.uid, self.gid) if not clusterDir.isdir(): # No cluster directory, run initdb log.info("Running initdb for {dir}", dir=clusterDir.path.decode("utf-8")) dbInited = Deferred() self.reactor.spawnProcess( CapturingProcessProtocol(dbInited, None), self._initdb, [self._initdb, "-E", "UTF8", "-U", self.spawnedDBUser], env=env, path=self.workingDir.path, uid=self.uid, gid=self.gid, ) def doCreate(result): if result.find("FATAL:") != -1: log.error(result) raise InternalDataStoreError( "Unable to initialize postgres database: {}" .format(result) ) self.startDatabase() dbInited.addCallback(doCreate) else: log.info("Cluster already exists at {dir}", dir=clusterDir.path.decode("utf-8")) self.startDatabase()
def startService(self): MultiService.startService(self) self.activateDelayedShutdown() clusterDir = self.dataStoreDirectory.child(self.clusterName) env = self.env = os.environ.copy() env.update(PGDATA=clusterDir.path, PGHOST=self.host, PGUSER=self.spawnedDBUser) initdb = self.initdb() if self.socketDir: if not self.socketDir.isdir(): log.warn("Creating {dir}", dir=self.socketDir.path) self.socketDir.createDirectory() if self.uid and self.gid: os.chown(self.socketDir.path, self.uid, self.gid) os.chmod(self.socketDir.path, 0770) if not self.dataStoreDirectory.isdir(): log.warn("Creating {dir}", dir=self.dataStoreDirectory.path) self.dataStoreDirectory.createDirectory() if not self.workingDir.isdir(): log.warn("Creating {dir}", dir=self.workingDir.path) self.workingDir.createDirectory() if self.uid and self.gid: os.chown(self.dataStoreDirectory.path, self.uid, self.gid) os.chown(self.workingDir.path, self.uid, self.gid) if not clusterDir.isdir(): # No cluster directory, run initdb log.warn("Running initdb for {dir}", dir=clusterDir.path) dbInited = Deferred() self.reactor.spawnProcess( CapturingProcessProtocol(dbInited, None), initdb, [initdb, "-E", "UTF8", "-U", self.spawnedDBUser], env=env, path=self.workingDir.path, uid=self.uid, gid=self.gid, ) def doCreate(result): if result.find("FATAL:") != -1: log.error(result) raise RuntimeError( "Unable to initialize postgres database: {}" .format(result) ) self.startDatabase() dbInited.addCallback(doCreate) else: log.warn("Cluster already exists at {dir}", dir=clusterDir.path) self.startDatabase()
def startService(self): MultiService.startService(self) ds = [] for magic_folder in self._iter_magic_folder_services(): ds.append(magic_folder.ready()) # The integration tests look for this message. You cannot get rid of # it (without also changing the tests). print("Completed initial Magic Folder setup") self._starting = gatherResults(ds)
def startService(self): log.msg('...Booting...', system="Bouser") yield self.reload_config() log.callWithContext({"system": "Bootstrap"}, boot.send, self) log.callWithContext({"system": "Checking Dependencies"}, check_deps.send, self) if self.fail: raise RuntimeError('Not all dependencies satisfied') else: MultiService.startService(self)
def startService(self): if not self._path.exists(): self._path.makedirs() self._config_path = self._path.child(b"current_configuration.v1.json") if self._config_path.exists(): self._deployment = wire_decode(self._config_path.getContent()) else: self._deployment = Deployment(nodes=frozenset()) self._sync_save(self._deployment) MultiService.startService(self) _LOG_STARTUP(configuration=self.get()).write(self.logger)
def startService(self): MultiService.startService(self) staticPath = FilePath(__file__).sibling("static") root = NoListDirFile(staticPath.path) root.putChild('api', SockJSResource(Factory.forProtocol(DaneDoctorProtocol))) webService = StreamServerEndpointService( serverFromString(self._reactor, "tcp:8080"), Site(root)) webService.setServiceParent(self)
def startService(self): MultiService.startService(self) self._listener = reactor.listenTCP(CoreHttpConfig.HTTP_PORT, channel.HTTPFactory(self._site)) self.log_info("started core service") self.upnp_service = UPNPService() # load enabled services try: for name in conf.get("CORE_ENABLED_PLUGINS", []): self.enablePlugin(name) self.log_debug("started all enabled services") except Exception, e: raise e
def start_site(reactor, site, secure_ports, insecure_ports, redirect_to_port): parent = MultiService() for secure in secure_ports: StreamServerEndpointService(secure, site).setServiceParent(parent) if insecure_ports: redirector = make_redirector_site(redirect_to_port) for insecure in insecure_ports: StreamServerEndpointService(insecure, redirector).setServiceParent(parent) parent.privilegedStartService() parent.startService()
def start_site(reactor, site, secure_ports, insecure_ports, redirect_to_port): parent = MultiService() for secure in secure_ports: StreamServerEndpointService(secure, site).setServiceParent(parent) if insecure_ports: redirector = make_redirector_site(redirect_to_port) for insecure in insecure_ports: StreamServerEndpointService(insecure, redirector).setServiceParent(parent) parent.privilegedStartService() parent.startService()
def startService(self): if not self._path.exists(): self._path.makedirs() self._config_path = self._path.child(b"current_configuration.v1.json") if self._config_path.exists(): self._deployment = wire_decode( self._config_path.getContent()) else: self._deployment = Deployment(nodes=frozenset()) self._sync_save(self._deployment) MultiService.startService(self) _LOG_STARTUP(configuration=self.get()).write(self.logger)
class ServerManagerFrameImpl(ServerManagerFrame): def __init__(self, *args, **kw): super(self.__class__, self).__init__(*args, **kw) #self.hostsDialog = HostsDialogImpl(self) #servers = dict([((gethostbyname(k[0]), k[1]), v) for k, v in servers.iteritems()]) # TODO?: make this Service a serialized Application then load from XML self.services = MultiService() for klass, addresses in servers.iteritems(): module, klass = klass.rsplit('.', 1) self.services.addService( __import__(module).__dict__[klass](addresses)) # setup log window class Redirect(object): def write(inner, *args, **kw): self.text_ctrl_log.AppendText(args[0]) def flush(self, *args, **kw): pass log.startLogging(Redirect()) def isValidClick(self, button, other): if other.GetValue(): button.SetValue(True) other.SetValue(False) return True else: button.SetValue(not button.GetValue()) return False def StartServer(self, event): # NOTE: button is already flipped by the time we get here button = self.button_start other = self.button_stop if not self.isValidClick(button, other): return self.services.startService() def StopServer(self, event): # NOTE: button is already flipped by the time we get here button = self.button_stop other = self.button_start if not self.isValidClick(button, other): return self.services.stopService() def OnHostsButton(self, event): self.hostsDialog.Show(not self.hostsDialog.IsShown())
def startService(self): MultiService.startService(self) if not self.dataStoreDirectory.isdir(): log.info("Creating {dir}", dir=self.dataStoreDirectory.path) self.dataStoreDirectory.createDirectory() if not self.workingDir.isdir(): log.info("Creating {dir}", dir=self.workingDir.path) self.workingDir.createDirectory() self.subServiceFactory(self.produceConnection, self).setServiceParent(self)
def startService(self): print "RconManager.startService..." self.mongo = self.getRootService().getMongo() servers = yield self.mongo.servers.find() for server in servers: print "Starting server:",server factory = getClientRconFactory(server, self) client = TCPClient(server["ip"], int(server["port"]), factory) client.setServiceParent(self) server["factory"] = factory self.servers[server["tag"]] = server print self.servers MultiService.startService(self)
def startService(self): MultiService.startService(self) staticPath = FilePath(__file__).sibling("static") root = NoListDirFile(staticPath.path) root.putChild('api', SockJSResource( Factory.forProtocol(DaneDoctorProtocol)) ) webService = StreamServerEndpointService( serverFromString(self._reactor, "tcp:8080"), Site(root) ) webService.setServiceParent(self)
def startService(self): MultiService.startService(self) if not self.dataStoreDirectory.isdir(): log.info("Creating {dir}", dir=self.dataStoreDirectory.path) self.dataStoreDirectory.createDirectory() if not self.workingDir.isdir(): log.info("Creating {dir}", dir=self.workingDir.path) self.workingDir.createDirectory() self.subServiceFactory( self.produceConnection, self ).setServiceParent(self)
def startService(self): MultiService.startService(self) self.activateDelayedShutdown() clusterDir = self.dataStoreDirectory.child(self.clusterName) env = self.env = os.environ.copy() env.update(PGDATA=clusterDir.path, PGHOST=self.host, PGUSER=self.spawnedDBUser) initdb = self.initdb() if self.socketDir: if not self.socketDir.isdir(): self.socketDir.createDirectory() if self.uid and self.gid: os.chown(self.socketDir.path, self.uid, self.gid) os.chmod(self.socketDir.path, 0770) if self.dataStoreDirectory.isdir(): self.startDatabase() else: self.dataStoreDirectory.createDirectory() if not self.workingDir.isdir(): self.workingDir.createDirectory() if self.uid and self.gid: os.chown(self.dataStoreDirectory.path, self.uid, self.gid) os.chown(self.workingDir.path, self.uid, self.gid) dbInited = Deferred() self.reactor.spawnProcess( CapturingProcessProtocol(dbInited, None), initdb, [initdb, "-E", "UTF8", "-U", self.spawnedDBUser], env=env, path=self.workingDir.path, uid=self.uid, gid=self.gid, ) def doCreate(result): if result.find("FATAL:") != -1: log.error(result) raise RuntimeError( "Unable to initialize postgres database: {}" .format(result) ) self.startDatabase() dbInited.addCallback(doCreate)
class ServerManagerFrameImpl(ServerManagerFrame): def __init__(self, *args, **kw): super(self.__class__, self).__init__(*args, **kw) #self.hostsDialog = HostsDialogImpl(self) #servers = dict([((gethostbyname(k[0]), k[1]), v) for k, v in servers.iteritems()]) # TODO?: make this Service a serialized Application then load from XML self.services = MultiService() for klass, addresses in servers.iteritems(): module, klass = klass.rsplit('.', 1) self.services.addService(__import__(module).__dict__[klass](addresses)) # setup log window class Redirect(object): def write(inner, *args, **kw): self.text_ctrl_log.AppendText(args[0]) def flush(self, *args, **kw): pass log.startLogging(Redirect()) def isValidClick(self, button, other): if other.GetValue(): button.SetValue(True) other.SetValue(False) return True else: button.SetValue(not button.GetValue()) return False def StartServer(self, event): # NOTE: button is already flipped by the time we get here button = self.button_start other = self.button_stop if not self.isValidClick(button, other): return self.services.startService() def StopServer(self, event): # NOTE: button is already flipped by the time we get here button = self.button_stop other = self.button_start if not self.isValidClick(button, other): return self.services.stopService() def OnHostsButton(self, event): self.hostsDialog.Show(not self.hostsDialog.IsShown())
def startService(self): MultiService.startService(self) ds = [] for (name, mf_config) in self.magic_folder_configs.items(): mf = MagicFolder.from_config( ClientStandIn(self.tahoe_client, self.config), name, mf_config, ) self.magic_folder_services[name] = mf mf.setServiceParent(self) ds.append(mf.ready()) # The integration tests look for this message. You cannot get rid of # it. print("Completed initial Magic Folder setup") self._starting = gatherResults(ds)
def setUp(self): """ L{PeerConnectionPool} requires access to a database and the reactor. """ self.store = yield buildStore(self, None) def doit(txn): return txn.execSQL(schemaText) yield inTransaction(lambda: self.store.newTransaction("bonus schema"), doit) def indirectedTransactionFactory(*a): """ Allow tests to replace 'self.store.newTransaction' to provide fixtures with extra methods on a test-by-test basis. """ return self.store.newTransaction(*a) def deschema(): @inlineCallbacks def deletestuff(txn): for stmt in dropSQL: yield txn.execSQL(stmt) return inTransaction(lambda *a: self.store.newTransaction(*a), deletestuff) self.addCleanup(deschema) from twisted.internet import reactor self.node1 = PeerConnectionPool( reactor, indirectedTransactionFactory, 0, schema) self.node2 = PeerConnectionPool( reactor, indirectedTransactionFactory, 0, schema) class FireMeService(Service, object): def __init__(self, d): super(FireMeService, self).__init__() self.d = d def startService(self): self.d.callback(None) d1 = Deferred() d2 = Deferred() FireMeService(d1).setServiceParent(self.node1) FireMeService(d2).setServiceParent(self.node2) ms = MultiService() self.node1.setServiceParent(ms) self.node2.setServiceParent(ms) ms.startService() self.addCleanup(ms.stopService) yield gatherResults([d1, d2]) self.store.queuer = self.node1
def start_services(reactor, endpoint, backend): top_service = MultiService() api_service = create_api_service(endpoint, backend) api_service.setServiceParent(top_service) backend_service = BackendService(backend) backend_service.setServiceParent(top_service) # XXX Setting _raiseSynchronously makes startService raise an exception # on error rather than just logging and dropping it. # This should be a public API, Twisted bug #8170. api_service._raiseSynchronously = True top_service.startService() reactor.addSystemEventTrigger( "before", "shutdown", lambda: top_service.stopService, )
def start_services(reactor, endpoint, backend): top_service = MultiService() api_service = create_api_service(endpoint, backend) api_service.setServiceParent(top_service) backend_service = BackendService(backend) backend_service.setServiceParent(top_service) # XXX Setting _raiseSynchronously makes startService raise an exception # on error rather than just logging and dropping it. # This should be a public API, Twisted bug #8170. api_service._raiseSynchronously = True top_service.startService() reactor.addSystemEventTrigger( "before", "shutdown", lambda: top_service.stopService, )
def startService(self): self.mongo = yield txmongo.MongoConnectionPool() if self.config['web']['enable']: ww = watweb.Application(self, self.config['web']) ws = TCPServer(self.config['web']['port'], ww, interface=self.config['web']['bind']).setServiceParent(self) if self.config['irc']['enable']: self.ic = watirc.getwatircClient(self, self.config['irc']) self.ic.setServiceParent(self) if self.config['rcon']['enable']: self.rc = RconManager(self, self.config['rcon']) self.rc.setServiceParent(self) if self.config['twitter']['enable']: twcfg = self.config['twitter'] self.tw = Twython(twcfg['app_key'], twcfg['app_secret'], twcfg['oauth_token'], twcfg['oauth_secret']) if self.config['stats']['enable']: self.st = StatsProvider(self, self.config['stats']) MultiService.startService(self)
def startService(self): pool = CreatePool() if False: factory = Factory() factory.protocol = Echo else: root = File(".") factory = Site(root) #hub_websocket_sslcontext = tlsctx.TlsContextFactory(cfg["hub-websocket-tlskey-pem"], cfg["hub-websocket-tlscert-pem"]) context = ssl.DefaultOpenSSLContextFactory('server.key', 'server.crt') service = internet.SSLServer(8090, factory, context) service.setServiceParent(self) MultiService.startService(self)
def startService(self): pool = CreatePool() if False: factory = Factory() factory.protocol = Echo else: root = File(".") factory = Site(root) #hub_websocket_sslcontext = tlsctx.TlsContextFactory(cfg["hub-websocket-tlskey-pem"], cfg["hub-websocket-tlscert-pem"]) context = ssl.DefaultOpenSSLContextFactory('server.key', 'server.crt') service = internet.SSLServer(8090, factory, context) service.setServiceParent(self) MultiService.startService(self)
def startService(self): """Start listening on two ports.""" logger.info("- - - - - SERVER STARTING") # setup stats in the factory yield MultiService.startService(self) # only start the HeartbeatWriter if the interval is > 0 heartbeat_interval = float(config.ssl_proxy.heartbeat_interval) if heartbeat_interval > 0: self.heartbeat_writer = stdio.StandardIO( supervisor_utils.HeartbeatWriter(heartbeat_interval, logger))
def startService(self): """ Start commander service. This will start all main work to be done by subservices. Call this method after the connection with game console is successfully established. """ self._load_server_config() self._share_data() yield self._greet_n_kick_all() yield MultiService.startService(self)
def startService(self): """Start listening on two ports.""" logger.info("- - - - - SERVER STARTING") # setup stats in the factory yield MultiService.startService(self) # only start the HeartbeatWriter if the interval is > 0 heartbeat_interval = float(config.ssl_proxy.heartbeat_interval) if heartbeat_interval > 0: self.heartbeat_writer = stdio.StandardIO( supervisor_utils.HeartbeatWriter(heartbeat_interval, logger))
def startService(self): self.init_game() logging.info("Starting services...") # Gather Twisted services and register them to our application. for plugin in self.plugins.active_plugins("TwistedService"): service = plugin.get_service() if isinstance(service, Service): self.addService(service) # Setup the AMP server if we are using proxy. if config.getboolean('Proxy', 'enabled'): service = proxy_sessions.AMP_server( self, config.getint('Proxy', 'AMP port')) self.addService(service) # Fire server startup hooks. self.invoke_hook('server_startup') self.db.on_server_startup() MultiService.startService(self)
def startService(self): self.init_game() logging.info("Starting services...") # Gather Twisted services and register them to our application. for plugin in self.plugins.active_plugins("TwistedService"): service = plugin.get_service() if isinstance(service, Service): self.addService(service) # Setup the AMP server if we are using proxy. if config.getboolean('Proxy', 'enabled'): service = proxy_sessions.AMP_server( self, config.getint('Proxy', 'AMP port')) self.addService(service) # Fire server startup hooks. self.invoke_hook('server_startup') self.db.on_server_startup() MultiService.startService(self)
def startService(self): cfgpr = ConfigParser() # TODO: config location from argparse or something cfgpr.read('config/config.ini') ip = cfgpr.get('main', 'ip') port = cfgpr.getint('main', 'port') tag = cfgpr.get('main', 'tag') password = cfgpr.get('main', 'password') server_data = { 'ip': ip, 'port': port, 'tag': tag, # TODO: what is this: 'secret': password, # TODO: refactor how this kind of data is passed and stored in factory } factory = getClientRconFactory(server_data) client = TCPClient(server_data["ip"], server_data["port"], factory) client.setServiceParent(self) self.server["factory"] = factory MultiService.startService(self)
def startService(self): options = self._options server_directory = options.get('servdir') or 'my_spyd_server' server_directory = os.path.expanduser(server_directory) if not len(logging._handlers): logging.basicConfig() if options.get('init'): if os.path.exists(server_directory): fatal("The {!r} directory already exists, please only use the -i with a server directory path which does not exist and should be created.".format(server_directory)) data_path = spyd_root_module.__path__ + ['data'] data_path = os.path.join(*data_path) shutil.copytree(data_path, server_directory) if os.path.exists(server_directory): success("The specified server directory has been created; {!r} Remove the -i flag to run.".format(server_directory)) else: fatal("Error failed to create the specified server directory.") if not os.path.exists(server_directory): fatal("The specified server directory, {!r}, does not exist. Use the -i flag to create it.".format(server_directory)) os.chdir(server_directory) logger.info("Using server directory; {!r}".format(os.path.abspath(os.curdir))) config = config_loader('config.json') spyd = SpydServer(config) spyd.root_service.setServiceParent(self) MultiService.startService(self) logger.spyd_event("Server started.")
class TestUDPRedirect(TxTestCase): def setUp(self): self.service = MultiService() self.received = [] class Collect(DatagramProtocol): def datagramReceived(cself, data, host_port): self.got_data(data) self.port = reactor.listenUDP(0, Collect()) self.processor = TestMessageProcessor() self.router = Router(self.processor, r"any => redirect_udp 127.0.0.1 %s" % (self.port.getHost().port,), service=self.service) self.service.startService() return self.router.ready @defer.inlineCallbacks def tearDown(self): yield self.service.stopService() self.port.stopListening() def test_redirect(self): """ Any message gets dropped with the drop rule. """ message = "gorets:1|c" d = defer.Deferred() def got_data(data): self.assertEqual(data, message) d.callback(True) self.got_data = got_data self.router.process(message) return d
def startService(self): self.setupService() self.log(log.info, u'Starting') MultiService.startService(self)
def _main_async(reactor, argv=None, _abort_for_test=False): if argv is None: argv = sys.argv if not _abort_for_test: # Configure logging. Some log messages would be discarded if we did not set up things early # TODO: Consult best practices for Python and Twisted logging. # TODO: Logs which are observably relevant should be sent to the client (e.g. the warning of refusing to have more receivers active) logging.basicConfig(level=logging.INFO) log.startLoggingWithObserver(log.PythonLoggingObserver(loggerName='shinysdr').emit, False) # Option parsing is done before importing the main modules so as to avoid the cost of initializing gnuradio if we are aborting early. TODO: Make that happen for createConfig too. argParser = argparse.ArgumentParser(prog=argv[0]) argParser.add_argument('configFile', metavar='CONFIG', help='path of configuration file') argParser.add_argument('--create', dest='createConfig', action='store_true', help='write template configuration file to CONFIG and exit') argParser.add_argument('-g, --go', dest='openBrowser', action='store_true', help='open the UI in a web browser') argParser.add_argument('--force-run', dest='force_run', action='store_true', help='Run DSP even if no client is connected (for debugging).') args = argParser.parse_args(args=argv[1:]) # Verify we can actually run. # Note that this must be done before we actually load core modules, because we might get an import error then. yield check_versions() # We don't actually use shinysdr.devices directly, but we want it to be guaranteed available in the context of the config file. import shinysdr.devices as lazy_devices import shinysdr.source as lazy_source # legacy shim # Load config file if args.createConfig: with open(args.configFile, 'w') as f: f.write(make_default_config()) log.msg('Created default configuration file at: ' + args.configFile) sys.exit(0) # TODO: Consider using a return value or something instead else: configObj = Config(reactor) execute_config(configObj, args.configFile) yield configObj._wait_and_validate() stateFile = configObj._state_filename def noteDirty(): if stateFile is not None: # just immediately write (revisit this when more performance is needed) with open(stateFile, 'w') as f: json.dump(top.state_to_json(), f) def restore(root, get_defaults): if stateFile is not None: if os.path.isfile(stateFile): root.state_from_json(json.load(open(stateFile, 'r'))) # make a backup in case this code version misreads the state and loses things on save (but only if the load succeeded, in case the file but not its backup is bad) shutil.copyfile(stateFile, stateFile + '~') else: root.state_from_json(get_defaults(root)) log.msg('Constructing flow graph...') top = configObj._create_top_block() singleton_reactor.addSystemEventTrigger('during', 'shutdown', top.close_all_devices) log.msg('Restoring state...') restore(top, top_defaults) log.msg('Starting web server...') services = MultiService() for maker in configObj._service_makers: IService(maker(top, noteDirty)).setServiceParent(services) services.startService() log.msg('ShinySDR is ready.') for service in services: # TODO: should have an interface (currently no proper module to put it in) service.announce(args.openBrowser) if args.force_run: log.msg('force_run') from gnuradio.gr import msg_queue top.monitor.get_fft_distributor().subscribe(msg_queue(limit=2)) if _abort_for_test: services.stopService() defer.returnValue((top, noteDirty)) else: yield defer.Deferred() # never fires
def startService(self): MultiService.startService(self) self.reactor.connectTCP(self.host, self.port, self.factory)
def startService(self): self.setupService() #self.log(log.info, u'Starting') MultiService.startService(self) self.metrics_twingo = LoopingCall(self.process_metrics) self.metrics_twingo.start(self.metrics.interval, now=True)
def startService(self): if not self._path.exists(): self._path.makedirs() self.load_configuration() MultiService.startService(self) _LOG_STARTUP(configuration=self.get()).write(self.logger)
def startService(self): MultiService.startService(self)
def _main_async(reactor, argv=None, _abort_for_test=False): if argv is None: argv = sys.argv if not _abort_for_test: # Configure logging. Some log messages would be discarded if we did not set up things early # TODO: Consult best practices for Python and Twisted logging. # TODO: Logs which are observably relevant should be sent to the client (e.g. the warning of refusing to have more receivers active) logging.basicConfig(level=logging.INFO) log.startLoggingWithObserver( log.PythonLoggingObserver(loggerName='shinysdr').emit, False) # Option parsing is done before importing the main modules so as to avoid the cost of initializing gnuradio if we are aborting early. TODO: Make that happen for createConfig too. argParser = argparse.ArgumentParser(prog=argv[0]) argParser.add_argument('config_path', metavar='CONFIG', help='path of configuration directory or file') argParser.add_argument( '--create', dest='createConfig', action='store_true', help='write template configuration file to CONFIG and exit') argParser.add_argument('-g, --go', dest='openBrowser', action='store_true', help='open the UI in a web browser') argParser.add_argument( '--force-run', dest='force_run', action='store_true', help='Run DSP even if no client is connected (for debugging).') args = argParser.parse_args(args=argv[1:]) # Verify we can actually run. # Note that this must be done before we actually load core modules, because we might get an import error then. version_report = yield _check_versions() if version_report: print >> sys.stderr, version_report sys.exit(1) # We don't actually use shinysdr.devices directly, but we want it to be guaranteed available in the context of the config file. # pylint: disable=unused-variable import shinysdr.devices as lazy_devices import shinysdr.source as lazy_source # legacy shim # Load config file if args.createConfig: write_default_config(args.config_path) log.msg('Created default configuration at: ' + args.config_path) sys.exit(0) # TODO: Consider using a return value or something instead else: configObj = Config(reactor) execute_config(configObj, args.config_path) yield configObj._wait_and_validate() stateFile = configObj._state_filename def restore(root, get_defaults): if stateFile is not None: if os.path.isfile(stateFile): root.state_from_json(json.load(open(stateFile, 'r'))) # make a backup in case this code version misreads the state and loses things on save (but only if the load succeeded, in case the file but not its backup is bad) shutil.copyfile(stateFile, stateFile + '~') else: root.state_from_json(get_defaults(root)) log.msg('Constructing...') app = configObj._create_app() singleton_reactor.addSystemEventTrigger('during', 'shutdown', app.close_all_devices) log.msg('Restoring state...') restore(app, _app_defaults) # Set up persistence if stateFile is not None: def eventually_write(): log.msg('Scheduling state write.') def actually_write(): log.msg('Performing state write...') current_state = pcd.get() with open(stateFile, 'w') as f: json.dump(current_state, f) log.msg('...done') reactor.callLater(_PERSISTENCE_DELAY, actually_write) pcd = PersistenceChangeDetector(app, eventually_write, the_subscription_context) # Start implicit write-to-disk loop, but don't actually write. # This is because it is useful in some failure modes to not immediately overwrite a good state file with a bad one on startup. pcd.get() log.msg('Starting web server...') services = MultiService() for maker in configObj._service_makers: IService(maker(app)).setServiceParent(services) services.startService() log.msg('ShinySDR is ready.') for service in services: # TODO: should have an interface (currently no proper module to put it in) service.announce(args.openBrowser) if args.force_run: log.msg('force_run') from gnuradio.gr import msg_queue # TODO kludge, make this less digging into guts app.get_receive_flowgraph().monitor.get_fft_distributor().subscribe( msg_queue(limit=2)) if _abort_for_test: services.stopService() defer.returnValue(app) else: yield defer.Deferred() # never fires
def _main_async(reactor, argv=None, _abort_for_test=False): if argv is None: argv = sys.argv if not _abort_for_test: # Some log messages would be discarded if we did not set up things early. configure_logging() # Option parsing is done before importing the main modules so as to avoid the cost of initializing gnuradio if we are aborting early. TODO: Make that happen for createConfig too. argParser = argparse.ArgumentParser(prog=argv[0]) argParser.add_argument('config_path', metavar='CONFIG', help='path of configuration directory or file') argParser.add_argument('--create', dest='createConfig', action='store_true', help='write template configuration file to CONFIG and exit') argParser.add_argument('-g, --go', dest='openBrowser', action='store_true', help='open the UI in a web browser') argParser.add_argument('--force-run', dest='force_run', action='store_true', help='Run DSP even if no client is connected (for debugging).') args = argParser.parse_args(args=argv[1:]) # Verify we can actually run. # Note that this must be done before we actually load core modules, because we might get an import error then. version_report = yield _check_versions() if version_report: print(version_report, file=sys.stderr) sys.exit(1) # Write config file and exit if asked ... if args.createConfig: write_default_config(args.config_path) _log.info('Created default configuration at: {config_path}', config_path=args.config_path) sys.exit(0) # TODO: Consider using a return value or something instead # ... else read config file config_obj = Config(reactor=reactor, log=_log) execute_config(config_obj, args.config_path) yield config_obj._wait_and_validate() _log.info('Constructing...') app = config_obj._create_app() reactor.addSystemEventTrigger('during', 'shutdown', app.close_all_devices) _log.info('Restoring state...') pfg = PersistenceFileGlue( reactor=reactor, root_object=app, filename=config_obj._state_filename, get_defaults=_app_defaults) _log.info('Starting web server...') services = MultiService() for maker in config_obj._service_makers: IService(maker(app)).setServiceParent(services) services.startService() _log.info('ShinySDR is ready.') for service in services: # TODO: should have an interface (currently no proper module to put it in) service.announce(args.openBrowser) if args.force_run: _log.debug('force_run') # TODO kludge, make this less digging into guts app.get_receive_flowgraph().get_monitor().state()['fft'].subscribe2(lambda v: None, the_subscription_context) if _abort_for_test: services.stopService() yield pfg.sync() defer.returnValue(app) else: yield defer.Deferred() # never fires
def startService(self): MultiService.startService(self) self.reactor.connectTCP(self.host, self.port, self.factory)
def startService(self): self.periodicTask.start(self.T, now=False) # call every T seconds BaseMultiService.startService(self)
def startService(self): if not self._path.exists(): self._path.makedirs() self.load_configuration() MultiService.startService(self) _LOG_STARTUP(configuration=self.get()).write(self.logger)