Example #1
0
    def __init__(self, apserver, name=None, host="0.0.0.0", port=22555, index=-1, device_id=None):
        MultiService.__init__(self)

        self.apserver = IAirPlayServer(apserver)

        if device_id:
            self.deviceid = device_id
        else:
            macstr = "%012X" % uuid.getnode()
            self.deviceid = ''.join("%s:" % macstr[i:i + 2] for i in range(0, len(macstr), 2))[:-1]

        # 0x77 instead of 0x07 in order to support AirPlay from ordinary apps;
        # also means that the body for play will be a binary plist.
        self.features = 0x77
        self.model = "AppleTV2,1"

        # create TCP server
        TCPServer(port, self.create_site(), 100, interface=host).setServiceParent(self)

        # create avahi service
        if (name is None):
            name = "Airplay Service on " + platform.node()
        zconf = ZeroconfService(name, port=port, stype="_airplay._tcp",
                                text=["deviceid=" + self.deviceid, "features=" + hex(self.features), "model=" + self.model],
                                index=index)
        zconf.setServiceParent(self)

        # for logging
        self.name_ = name
        self.host = host
        self.port = port
Example #2
0
    def __init__(self, ip_addr, sn_types=[], device_types=[], required_services=[]): # pylint: disable-msg=W0102
        """Initialize the service.

        Arguments:
        ip_addr           -- IP address for listening services.
        sn_types          -- list of device and/or service types to look for in
                             UPnP notifications and responses; other types will
                             be ignored. "upnp:rootdevice" is automatically
                             tracked, and should not be in this list.
        device_types      -- list of interesting device types, used to filter
                             out devices based on their "deviceType" attribute.
                             An empty list means that all types are interesting.
        required_services -- if non-empty, list of services that the device
                             must have for it to be considered

        """
        MultiService.__init__(self)
        self._builders = {}
        self._devices = {}
        self._ignored = []
        self._sn_types = ['upnp:rootdevice'] + sn_types
        self._dev_types = device_types
        self._req_services = required_services
        self._ip_addr = ip_addr

        # create the UPnP listener service
        UpnpService(self._datagram_handler, ip_addr).setServiceParent(self)
        
        # create the periodic M-SEARCH request service
        msearch = MSearchRequest(self._datagram_handler)
        TimerService(DISCOVERY_INTERVAL, self._msearch_discover,
                     msearch).setServiceParent(self)
Example #3
0
 def __init__(self, kz_client, interval, partitioner_path, buckets,
              time_boundary, log, got_buckets,
              clock=None):
     """
     :param log: a bound log
     :param kz_client: txKazoo client
     :param partitioner_path: ZooKeeper path, used for partitioning
     :param buckets: iterable of buckets to distribute between
         nodes. Ideally there should be at least as many elements as nodes
         taking part in this partitioner. This should be a sequence of str.
     :param time_boundary: time to wait for partitioning to stabilize.
     :param got_buckets: Callable which will be called with a list of
         buckets when buckets have been allocated to this node.
     :param clock: clock to use for checking the buckets on an interval.
     """
     MultiService.__init__(self)
     self.kz_client = kz_client
     self.partitioner_path = partitioner_path
     self.buckets = buckets
     self.log = log
     self.got_buckets = got_buckets
     self.time_boundary = time_boundary
     ts = TimerService(interval, self.check_partition)
     ts.setServiceParent(self)
     ts.clock = clock
     self._old_buckets = []
 def makeService(self, options):
     if not os.path.isfile(options['config']):
         raise ConfigNotFoundException()
     
     config = yaml.load(open(options['config']), OrderedDictYAMLLoader)
     
     self.processProtocol = processProtocol = protocol.ProcessProtocol()
     reactor.spawnProcess(processProtocol, config['config']['udpxy'],
         args=[config['config']['udpxy'],
               '-T',
               '-m', config['config']['iptv_if'],
               '-p', str(config['config']['udpxy_port']),
               '-a', '127.0.0.1',
               '-c', '10'])
     
     from tidaltv.server import TidalTVServer
     tidaltvserver = TidalTVServer(configfile=config, use_ssl=os.path.isfile(config['config']['ssl']))
     
     if config['config']['broadcast_keepalive']:
         from tidaltv.broadcast import KeepAliver
         keepaliver = KeepAliver(config, tidaltvserver.channel_watchers)
     
     site = server.Site(tidaltvserver)
     ms = MultiService()
     tidaltvport = int(config['config']['port'])
     if os.path.isfile(config['config']['ssl']):
         from OpenSSL import SSL
         ms.addService(internet.SSLServer(tidaltvport, site,
                                          ServerContextFactory(config['config']['ssl'])))
     else:
         ms.addService(internet.TCPServer(tidaltvport, site))
     return ms
    def stopService(self):
        """
        Stop all child services, then stop the subprocess, if it's running.
        """

        if self.delayedShutdown:
            # We're still in the process of initializing the database, so
            # delay shutdown until the shutdownDeferred fires.
            d = self.shutdownDeferred = Deferred()
            d.addCallback(lambda ignored: MultiService.stopService(self))
        else:
            d = MultiService.stopService(self)

        def superStopped(result):
            # If pg_ctl's startup wasn't successful, don't bother to stop the
            # database.  (This also happens in command-line tools.)
            if self.shouldStopDatabase:
                monitor = _PostgresMonitor()
                pgCtl = self.pgCtl()
                # FIXME: why is this 'logfile' and not self.logfile?
                self.reactor.spawnProcess(monitor, pgCtl,
                    [pgCtl, '-l', 'logfile', 'stop'],
                    env=self.env, path=self.workingDir.path,
                    uid=self.uid, gid=self.gid,
                )
                return monitor.completionDeferred
        return d.addCallback(superStopped)
    def makeService(self, options):
        tracker_service = MultiService()
        tracker_service.setName("Trustchain Crawler")

        def run():
            crypto = ECCrypto()
            dispersy = Dispersy(StandaloneEndpoint(options["port"], options["ip"]),
                                options["statedir"],
                                u'dispersy.db',
                                crypto)
            if not dispersy.start():
                raise RuntimeError("Unable to start Dispersy")
            master_member = TriblerChainCommunityCrawler.get_master_members(dispersy)[0]
            my_member = dispersy.get_member(private_key=crypto.key_to_bin(crypto.generate_key(u"curve25519")))
            TriblerChainCommunityCrawler.init_community(dispersy, master_member, my_member)

            self._stopping = False

            def signal_handler(sig, frame):
                msg("Received signal '%s' in %s (shutting down)" % (sig, frame))
                if not self._stopping:
                    self._stopping = True
                    dispersy.stop().addCallback(lambda _: reactor.stop())

            signal.signal(signal.SIGINT, signal_handler)
            signal.signal(signal.SIGTERM, signal_handler)

        reactor.exitCode = 0
        reactor.callWhenRunning(run)
        return tracker_service
Example #7
0
    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)
Example #8
0
    def __init__(self):
        MultiService.__init__(self)

        # Init pilots service --------------------------------------------------
        from minic.service.pilots import PilotsService
        pilots = PilotsService()
        pilots.setServiceParent(self)

        # Init objects service -------------------------------------------------
        from minic.service.objects import ObjectsService
        objects = ObjectsService()
        objects.setServiceParent(self)

        # Init missions service ------------------------------------------------
        from minic.service.missions import MissionsService
        log_watcher = LogWatchingService()
        missions = MissionsService(log_watcher)
        log_parser = EventLogParser((pilots, objects, missions, ))
        log_watcher.set_parser(log_parser)
        missions.setServiceParent(self)

        # Init console and DeviceLink parsers ----------------------------------
        console_parser = ConsoleParser((pilots, missions, ))
        device_link_parser = DeviceLinkParser()
        log_parser = EventLogParser((pilots, objects, missions, ))

        # Group parsers and services -------------------------------------------
        self.parsers = namedtuple(
            'commander_parsers', ['console', 'device_link', 'log'])(
            console_parser, device_link_parser, log_parser)
        self.services = namedtuple(
            'commander_services', ['pilots', 'objects', 'missions'])(
            pilots, objects, missions)
Example #9
0
    def __init__(self, config=None):
        MultiService.__init__(self)
        self.config = config

        # Create a tasks queue
        self.tasks = Tasks()
        self.tasks.setServiceParent(self)
Example #10
0
 def __init__(self, logger, cbdata, webdata=None, debug=False, isExe=False):
     MultiService.__init__(self)
     self.logger = logger
     self.cbdata = cbdata
     self.webdata = webdata
     self.debug = debug
     self.isExe = isExe
Example #11
0
    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)
Example #12
0
    def __init__(self, ssl_cert, ssl_key, ssl_cert_chain, ssl_port,
                 dest_host, dest_port, server_name, status_port):
        """ Create a rageServerService.

        @param ssl_cert: the certificate text.
        @param ssl_key: the key text.
        @param ssl_port: the port to listen on with ssl.
        @param dest_host: destination hostname.
        @param dest_port: destination port.
        @param server_name: name of this server.
        """
        MultiService.__init__(self)
        self.heartbeat_writer = None
        if server_name is None:
            server_name = "anonymous_instance"
        self.server_name = server_name
        self.factory = SSLProxyFactory(ssl_port, dest_host, dest_port,
                                       self.server_name)
        ssl_context_factory = ProxyContextFactory(ssl_cert, ssl_key,
                                                  ssl_cert_chain)
        self.ssl_service = SSLServer(ssl_port, self.factory,
                                     ssl_context_factory)
        self.ssl_service.setName("SSL")
        self.ssl_service.setServiceParent(self)
        # setup the status service
        self.status_service = create_status_service(self.factory, status_port)
        self.status_service.setServiceParent(self)
        # disable ssl compression
        if config.ssl_proxy.disable_ssl_compression:
            disable_ssl_compression(logger)
Example #13
0
 def __init__(self,
              kz_client,
              interval,
              partitioner_path,
              buckets,
              time_boundary,
              log,
              got_buckets,
              clock=None):
     """
     :param log: a bound log
     :param kz_client: txKazoo client
     :param partitioner_path: ZooKeeper path, used for partitioning
     :param buckets: iterable of buckets to distribute between
         nodes. Ideally there should be at least as many elements as nodes
         taking part in this partitioner. This should be a sequence of str.
     :param time_boundary: time to wait for partitioning to stabilize.
     :param got_buckets: Callable which will be called with a list of
         buckets when buckets have been allocated to this node.
     :param clock: clock to use for checking the buckets on an interval.
     """
     MultiService.__init__(self)
     self.kz_client = kz_client
     self.partitioner_path = partitioner_path
     self.buckets = buckets
     self.log = log
     self.got_buckets = got_buckets
     self.time_boundary = time_boundary
     ts = TimerService(interval, self.check_partition)
     ts.setServiceParent(self)
     ts.clock = clock
     self._old_buckets = []
Example #14
0
 def __init__(self, shared_path, server_name, server_path, jar_file=None):
     MultiService.__init__(self)
     self.shared_path = shared_path
     self.server_name = server_name
     self.server_path = server_path
     self.jar_file = jar_file
     self.players = set()
Example #15
0
    def __init__(
        self, dataStoreDirectory, subServiceFactory,
        dsnUser=None,
        testMode=False,
        reactor=None,
    ):
        """
        Initialize a L{OracleService} pointed at a data store directory.

        @param dataStoreDirectory: the directory to
        @type dataStoreDirectory: L{twext.python.filepath.CachingFilePath}

        @param subServiceFactory: a 1-arg callable that will be called with a
            1-arg callable which returns a DB-API cursor.
        @type subServiceFactory: C{callable}
        """

        MultiService.__init__(self)
        self.subServiceFactory = subServiceFactory
        self.dataStoreDirectory = dataStoreDirectory
        self.workingDir = self.dataStoreDirectory.child("working")

        self.dsnUser = dsnUser
        self.testMode = testMode

        self._reactor = reactor
Example #16
0
File: Client.py Project: isnok/mpmf
 def __init__(self, parser):
     MultiService.__init__(self)
     NamedComponentized.__init__(self, parser.parse_args().game)
     if not self.config.verbose:
         HTTPClientFactory.noisy = False
     registerGlobal(self, IClient)
     self.addService(IWebWorld(self))
Example #17
0
    def __init__(self, settings=None, channel=None):

        MultiService.__init__(self)

        # Make channel object from application settings configuration object
        self.setupChannel(channel=channel)

        # Shortcut to global settings
        self.config = settings

        if not 'port' in self.config['grafana']:
            self.config['grafana']['port'] = '3000'

        name = self.__class__.__name__
        log.info('Starting GrafanaManager "{}". grafana={}:{}'.format(
            name,
            self.config['grafana']['host'],
            self.config['grafana']['port']))

        # Initialize key cache
        # Utility functions for remembering whether the dashboard has been created already.
        # This is important as we would otherwise talk to Grafana for each ingress measurement (on each hit).
        self.keycache = KeyCache()

        # Boot further child services
        self.boot_workers()

        # Connect to Grafana API
        self.connect()
Example #18
0
    def __init__(self, config):
        MultiService.__init__(self)
        import os
        from bouser.utils import safe_traverse

        from twisted.internet import reactor
        from twisted.application import strports
        from bouser.web.resource import DefaultRootResource
        from bouser.web.site import BouserSite
        from bouser.proxied_logger import proxiedLogFormatter

        root_resource = DefaultRootResource()
        current_dir = os.path.dirname(__file__)
        site = BouserSite(
            root_resource,
            static_path=safe_traverse(config, 'static-path', default=os.path.join(current_dir, 'static')),
            template_path=safe_traverse(config, 'template-path', default=os.path.join(current_dir, 'templates')),
            logFormatter=proxiedLogFormatter)

        description = config.get('strport', 'tcp:%s:interface=%s' % (
            config.get('port', 5000),
            config.get('host', '127.0.0.1')
        ))

        self.cors_domain = config.get('cors-domain', 'http://127.0.0.1:5000/')
        allowed_domains = set(filter(None, config.get('allowed-domains', '').replace(',', ' ').split(' ')))
        self.allowed_domains = set(allowed_domains) | {self.cors_domain}

        service = strports.service(description, site, reactor=reactor)
        service.setServiceParent(self)

        self.root_resource = root_resource
        self.site = site
        self.service = service
    def __init__(self):
        MultiService.__init__(self)

        # Init shared storage which is used to share information about server
        # to the ouside world
        self.shared_storage = get_storage()

        # Init pilots service
        from commander.service.pilots import PilotService
        self.pilots = PilotService()
        self.pilots.setServiceParent(self)

        # Init objects service
        from commander.service.objects import ObjectsService
        self.objects = ObjectsService()
        self.objects.setServiceParent(self)

        # Init missions service with log watcher
        from commander.service.missions import MissionService
        log_watcher = LogWatchingService(settings.IL2_EVENTS_LOG_PATH)
        self.missions = MissionService(log_watcher)
        self.log_parser = EventLogParser(
            (self.pilots, self.objects, self.missions, ))
        log_watcher.set_parser(self.log_parser)
        self.missions.setServiceParent(self)

        # Init console and DeviceLink parsers
        self.console_parser = ConsoleParser((self.pilots, self.missions, ))
        self.dl_parser = DeviceLinkParser()
Example #20
0
 def __init__(self, parser):
     MultiService.__init__(self)
     NamedComponentized.__init__(self, parser.parse_args().game)
     if not self.config.verbose:
         HTTPClientFactory.noisy = False
     registerGlobal(self, IClient)
     self.addService(IWebWorld(self))
Example #21
0
    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
Example #22
0
 def __init__(self, options):
     MultiService.__init__(self)
     self.options = options
     self.config = {}
     self.common_config = {}
     self.modules = {}
     self.fail = False
Example #23
0
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)
Example #24
0
 def __init__(self, options):
     MultiService.__init__(self)
     self.options = options
     self.config = {}
     self.common_config = {}
     self.modules = []
     self.fail = False
Example #25
0
    def makeService(self, options):
        if options['data-dir'] != None:
            if not os.access(options['data-dir'], os.X_OK | os.W_OK):
                raise core.SmapException("Cannot access " + options['data-dir'])
            smapconf.SERVER['DataDir'] = options['data-dir']

        inst = loader.load(options['conf'])
        # override defaults with command-line args
        smapconf.SERVER.update(dict([(k.lower(), v) for (k, v) in
                                     options.iteritems() if v != None]))

        if 'SuggestThreadPool' in smapconf.SERVER:
            reactor.suggestThreadPoolSize(int(smapconf.SERVER['SuggestThreadPool']))

        inst.start()
        reactor.addSystemEventTrigger('before', 'shutdown', inst.stop)

        site = getSite(inst, docroot=smapconf.SERVER['docroot'])
        service = MultiService()

        # add HTTP and HTTPS servers to the twisted multiservice
        if 'port' in smapconf.SERVER:
            service.addService(internet.TCPServer(int(smapconf.SERVER['port']), site))
        if 'sslport' in smapconf.SERVER:
            service.addService(internet.SSLServer(int(smapconf.SERVER['sslport']), 
                                                  site, 
                                                  SslServerContextFactory(smapconf.SERVER)))
        return service
Example #26
0
    def __init__(self, application):

        # The following doesnt work because twisted uses old style classes
        # super(ClientControlService, self).__init__()
        MultiService.__init__(self)
        self.application = application
        self.data = []
Example #27
0
    def __init__(self, config_file):
        MultiService.__init__(self)

        self.config_file = SafeConfigParser()
        self.config_file.readfp(open(config_file))

        self.config = None
 def startService(self):
     global configurations, expectations
     print "Loaded configurations: " + str(configurations)
     reload(sys)
     sys.setdefaultencoding('utf8')
     Expectations.display(expectations)
     MultiService.startService(self)
Example #29
0
class MHubApp(object):
    """
    Core application container responsible for managing and running of configured plugins.

    :param cfg: Application configuration dictionary
    :type cfg: dict.
    """
    def __init__(self, cfg=None):
        """
        Constructor
        """

        self.cfg = cfg or dict()
        self.logger = logging.getLogger("app")

        self.reactor = reactor
        self.root_service = MultiService()
        self.service = MHubService(self.cfg, self.reactor, self)
        self.application = Application("mhub")
        self.root_service.setServiceParent(self.application)

    def get_application(self):
        """
        Get the Twisted application object.

        :returns: Application
        """

        return self.application
Example #30
0
    def __init__(self, settings=None, channel=None):

        MultiService.__init__(self)

        # Make channel object from application settings configuration object
        self.setupChannel(channel=channel)

        # Shortcut to global settings
        self.config = settings

        if not 'port' in self.config['grafana']:
            self.config['grafana']['port'] = '3000'

        name = self.__class__.__name__
        log.info('Starting GrafanaManager "{}". grafana={}:{}'.format(
            name, self.config['grafana']['host'],
            self.config['grafana']['port']))

        # Initialize key cache
        # Utility functions for remembering whether the dashboard has been created already.
        # This is important as we would otherwise talk to Grafana for each ingress measurement (on each hit).
        self.keycache = KeyCache()

        # Boot further child services
        self.boot_workers()

        # Connect to Grafana API
        self.connect()
Example #31
0
    def __init__(self, **options):
        MultiService.__init__(self)

        address = ('gpcm.gamespy.com', 29900)
        sFact = MowLoginServerFactory()
        #sFact = makeTCPFwdFactory('gamespy.gpcmCli', 'gamespy.gpcmSrv', makeRecv(ProxyClient), makeRecv(ProxyServer))(*address)
        self.addService(TCPServer(address[1], sFact))

        address = ('peerchat.gamespy.com', 6667)
        sFact = ProxyPeerchatServerFactory(gameId, *address)
        #sFact = makeTCPFwdFactory('gamespy.peerCli', 'gamespy.peerSrv', makeRecv(ProxyClient, True), makeRecv(ProxyServer, True))(*address)
        self.addService(TCPServer(address[1], sFact))

        address = ('%s.gamestats.gamespy.com' % (gameId, ), 29920)
        sFact = makeTCPFwdFactory('gamespy.stat1cli', 'gamespy.stat1srv',
                                  makeRecv(ProxyClient, True),
                                  makeRecv(ProxyServer, True))(*address)
        self.addService(TCPServer(address[1], sFact))

        # ('menofwarpc.master.gamespy.com', 29910), # 29910 UDP is keycheck ('gamespy' xor), 27900 for gameinfo/natneg(?)
        address = ('%s.master.gamespy.com' % (gameId, ), 28910)
        sFact = makeTCPFwdFactory('gamespy.masterCli', 'gamespy.masterSrv',
                                  makeRecv(ProxyClient, True),
                                  makeRecv(ProxyServer, True))(*address)
        #sFact = ProxyMasterServerFactory(gameId, *address)
        self.addService(TCPServer(address[1], sFact))
Example #32
0
    def __attrs_post_init__(self):
        MultiService.__init__(self)
        if self.tahoe_client is None:
            self.tahoe_client = create_tahoe_client(
                self.config.tahoe_client_url,
                HTTPClient(Agent(self.reactor)),
            )
        self._listen_endpoint = serverFromString(
            self.reactor,
            self.config.api_endpoint,
        )
        web_service = magic_folder_web_service(
            self._listen_endpoint,
            self.config,
            self,
            self._get_auth_token,
            self.tahoe_client,
            self.status_service,
        )
        web_service.setServiceParent(self)

        # We can create the services for all configured folders right now.
        # They won't do anything until they are started which won't happen
        # until this service is started.
        self._create_magic_folder_services()
Example #33
0
    def __init__(self, ssl_cert, ssl_key, ssl_cert_chain, ssl_port, dest_host,
                 dest_port, server_name, status_port):
        """ Create a rageServerService.

        @param ssl_cert: the certificate text.
        @param ssl_key: the key text.
        @param ssl_port: the port to listen on with ssl.
        @param dest_host: destination hostname.
        @param dest_port: destination port.
        @param server_name: name of this server.
        """
        MultiService.__init__(self)
        self.heartbeat_writer = None
        if server_name is None:
            server_name = "anonymous_instance"
        self.server_name = server_name
        self.factory = SSLProxyFactory(ssl_port, dest_host, dest_port,
                                       self.server_name)
        ssl_context_factory = ProxyContextFactory(ssl_cert, ssl_key,
                                                  ssl_cert_chain)
        self.ssl_service = SSLServer(ssl_port, self.factory,
                                     ssl_context_factory)
        self.ssl_service.setName("SSL")
        self.ssl_service.setServiceParent(self)
        # setup the status service
        self.status_service = create_status_service(self.factory, status_port)
        self.status_service.setServiceParent(self)
        # disable ssl compression
        if config.ssl_proxy.disable_ssl_compression:
            disable_ssl_compression(logger)
 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)
Example #35
0
 def __init__(self, **options):
     MultiService.__init__(self)
     self.addService(
         TCPServer(
             options['port'],
             PeerchatProxyServerFactory(options['game'], options['host'],
                                        6667)))
Example #36
0
    def stopService(self):
        """
        Stop all child services, then stop the subprocess, if it's running.
        """

        if self.delayedShutdown:
            # We're still in the process of initializing the database, so
            # delay shutdown until the shutdownDeferred fires.
            d = self.shutdownDeferred = Deferred()
            d.addCallback(lambda ignored: MultiService.stopService(self))
        else:
            d = MultiService.stopService(self)

        def superStopped(result):
            # If pg_ctl's startup wasn't successful, don't bother to stop the
            # database.  (This also happens in command-line tools.)
            if self.shouldStopDatabase:
                monitor = _PostgresMonitor()
                pgCtl = self.pgCtl()
                # FIXME: why is this 'logfile' and not self.logfile?
                self.reactor.spawnProcess(
                    monitor, pgCtl,
                    [pgCtl, "-l", "logfile", "stop"],
                    env=self.env, path=self.workingDir.path,
                    uid=self.uid, gid=self.gid,
                )
                return monitor.completionDeferred
        return d.addCallback(superStopped)
Example #37
0
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
Example #38
0
    def __init__(
        self,
        dataStoreDirectory,
        subServiceFactory,
        dsnUser=None,
        testMode=False,
        reactor=None,
    ):
        """
        Initialize a L{OracleService} pointed at a data store directory.

        @param dataStoreDirectory: the directory to
        @type dataStoreDirectory: L{twext.python.filepath.CachingFilePath}

        @param subServiceFactory: a 1-arg callable that will be called with a
            1-arg callable which returns a DB-API cursor.
        @type subServiceFactory: C{callable}
        """

        MultiService.__init__(self)
        self.subServiceFactory = subServiceFactory
        self.dataStoreDirectory = dataStoreDirectory
        self.workingDir = self.dataStoreDirectory.child("working")

        self.dsnUser = dsnUser
        self.testMode = testMode

        self._reactor = reactor
Example #39
0
    def stopService(self):
        """
        Stop all child services, then stop the subprocess, if it's running.
        """

        if self.delayedShutdown:
            # We're still in the process of initializing the database, so
            # delay shutdown until the shutdownDeferred fires.
            d = self.shutdownDeferred = Deferred()
            d.addCallback(lambda ignored: MultiService.stopService(self))
        else:
            d = MultiService.stopService(self)

        def superStopped(result):
            # If pg_ctl's startup wasn't successful, don't bother to stop the
            # database.  (This also happens in command-line tools.)
            if self.shouldStopDatabase:
                monitor = PostgresMonitor()
                args = [
                    self._pgCtl, "stop",
                    "--log={}".format(self.logFile),
                ]
                log.info("Requesting postgres stop via: {args}", args=args)
                self.reactor.spawnProcess(
                    monitor, self._pgCtl,
                    args,
                    env=self.env, path=self.workingDir.path,
                    uid=self.uid, gid=self.gid,
                )
                return monitor.completionDeferred
        return d.addCallback(superStopped)
    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)
Example #41
0
    def __init__(self):
        MultiService.__init__(self)

        # Start up our AMP RPC.
        self.amp = TCPServer(25600, ConsoleRPCFactory(self))
        MultiService.addService(self, self.amp)

        self.configure_services(configuration)
Example #42
0
 def __init__(self, reactor):
     MultiService.__init__(self)
     self._deployment_state = DeploymentState()
     timer = TimerService(1, self._wipe_expired)
     timer.clock = reactor
     timer.setServiceParent(self)
     self._information_wipers = pmap()
     self._clock = reactor
Example #43
0
 def __init__(self, reactor):
     MultiService.__init__(self)
     self._deployment_state = DeploymentState()
     timer = TimerService(1, self._wipe_expired)
     timer.clock = reactor
     timer.setServiceParent(self)
     self._information_wipers = pmap()
     self._clock = reactor
Example #44
0
    def startService(self):
        # Set up configuration manager
        self.config = self._build_config_manager()
        yield self.config.prepare()

        yield self.prepareService()

        MultiService.startService(self)
Example #45
0
 def __init__(self):
     MultiService.__init__(self)
     convergence_loop = build_convergence_loop_fsm(self.reactor,
                                                   self.deployer)
     self.logger = convergence_loop.logger
     self.cluster_status = build_cluster_status_fsm(convergence_loop)
     self.factory = ReconnectingClientFactory.forProtocol(
         lambda: AgentAMP(self))
Example #46
0
    def __init__(self):
        MultiService.__init__(self)

        # Start up our AMP RPC.
        self.amp = TCPServer(25600, ConsoleRPCFactory(self))
        MultiService.addService(self, self.amp)

        self.configure_services(configuration)
Example #47
0
    def __init__(self):
        MultiService.__init__(self)

        self.config = read_configuration()
        self.factorylist = list()
        self.irc = False
        self.ircbots = list()
        self.configure_services()
Example #48
0
    def __init__(self):
        MultiService.__init__(self)

        self.config = read_configuration()
        self.factorylist = list()
        self.irc = False
        self.ircbots = list()
        self.configure_services()
 def __init__(self, host, port, password, hub, session_store):
     MultiService.__init__(self)
     self.host = host
     self.port = port
     self.password = password
     self.hub = hub
     self.session_store = session_store
     self.die = False
Example #50
0
    def makeService(self, options):
        if options['conf']:
            settings.conf = settings.load(options['conf'])

        # we better add 
        reactor.suggestThreadPoolSize(settings.conf['threadpool size'])

        if options['memdebug']:
            from twisted.internet import task
            import objgraph
            import gc
            def stats():
                print gc.collect()
                print
                print '\n'.join(map(str, objgraph.most_common_types(limit=10)))
            task.LoopingCall(stats).start(2)

        cp = adbapi.ConnectionPool(settings.conf['database']['module'],
                                   host=settings.conf['database']['host'],
                                   database=settings.conf['database']['db'],
                                   user=settings.conf['database']['user'],
                                   password=settings.conf['database']['password'],
                                   port=settings.conf['database']['port'],
                                   cp_min=5, cp_max=30,
                                   cp_reconnect=True)

        if options['subscribe']:
            subscribe(cp, settings)


        # create a single republisher to send the data out on
        http_repub = republisher.ReResource(cp)
        websocket_repub = republisher.WebSocketRepublishResource(cp)
        if settings.conf['mongo']['enabled']:
            mongo_repub = republisher.MongoRepublisher(cp)
        else:
            mongo_repub = None

        service = MultiService()
        for svc in settings.conf['server']:
            scfg = settings.conf['server'][svc]
            site = getSite(cp, 
                           resources=scfg['resources'],
                           http_repub=http_repub, 
                           websocket_repub=websocket_repub,
                           mongo_repub=mongo_repub)

            if not len(scfg['ssl']) > 1:
                service.addService(internet.TCPServer(scfg['port'],
                                                      site,
                                                      interface=scfg['interface']))
            else:
                service.addService(internet.SSLServer(scfg['port'],
                                                      site,
                                                      SslServerContextFactory(scfg['ssl']),
                                                      interface=scfg['interface']))

        return service
Example #51
0
 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)
Example #52
0
 def __init__(self):
     MultiService.__init__(self)
     convergence_loop = build_convergence_loop_fsm(
         self.reactor, self.deployer
     )
     self.logger = convergence_loop.logger
     self.cluster_status = build_cluster_status_fsm(convergence_loop)
     self.factory = ReconnectingClientFactory.forProtocol(
         lambda: AgentAMP(self))
Example #53
0
    def stopService(self):
        """
        Stop all child services, then stop the subprocess, if it's running.
        """

        if self.delayedShutdown:
            # We're still in the process of initializing the database, so
            # delay shutdown until the shutdownDeferred fires.
            d = self.shutdownDeferred = Deferred()
            d.addCallback(lambda ignored: MultiService.stopService(self))
        else:
            d = MultiService.stopService(self)

        def superStopped(result):
            # If pg_ctl's startup wasn't successful, don't bother to stop the
            # database.  (This also happens in command-line tools.)
            if self.shouldStopDatabase:

                # Compare pg_ctl inode with one we saw at the start; if different
                # (or missing), fall back to SIGTERM
                try:
                    newInode = os.stat(self._pgCtl).st_ino
                except OSError:
                    # Missing
                    newInode = -1

                if self._pgCtlInode != newInode:
                    # send SIGTERM to postgres
                    log.info("Postgres control script mismatch")
                    if self._postgresPid:
                        log.info("Sending SIGTERM to Postgres")
                        try:
                            os.kill(self._postgresPid, signal.SIGTERM)
                        except OSError:
                            pass
                    return succeed(None)
                else:
                    # use pg_ctl stop
                    monitor = PostgresMonitor()
                    args = [
                        self._pgCtl,
                        "stop",
                        "--log={}".format(self.logFile),
                    ]
                    log.info("Requesting postgres stop via: {args}", args=args)
                    self.reactor.spawnProcess(
                        monitor,
                        self._pgCtl,
                        args,
                        env=self.env,
                        path=self.workingDir.path,
                        uid=self.uid,
                        gid=self.gid,
                    )
                    return monitor.completionDeferred

        return d.addCallback(superStopped)
Example #54
0
    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()
Example #55
0
    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()
Example #56
0
    def makeService(self, options):
        """
        Construct a tracker service.
        """
        tracker_service = MultiService()
        tracker_service.setName("IPv8Tracker")

        reactor.callWhenRunning(self.start_tracker, options)

        return tracker_service
Example #57
0
    def makeService(self, options):
        """
        Construct a IPv8 service.
        """
        crawler_service = MultiService()
        crawler_service.setName("TrustChainCrawler")

        reactor.callWhenRunning(self.start_crawler, options)

        return crawler_service
Example #58
0
    def makeService(self, options):
        """
        Construct a IPv8 service.
        """
        ipv8_service = MultiService()
        ipv8_service.setName("IPv8Exitnode")

        reactor.callWhenRunning(self.start_ipv8, options)

        return ipv8_service
Example #59
0
 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)