Пример #1
0
    def configure_services(self, configuration):
        read_configuration()

        for section in configuration.sections():
            if section.startswith("world "):
                factory = BravoFactory(section[6:])
                server = TCPServer(factory.port, factory,
                    interface=factory.interface)
                server.setName(factory.name)
                self.addService(server)
            elif section.startswith("irc "):
                try:
                    from bravo.irc import BravoIRC
                except ImportError:
                    log.msg("Couldn't import IRC stuff!")
                else:
                    factory = BravoIRC(self.namedServices, section[4:])
                    client = TCPClient(factory.host, factory.port, factory)
                    client.setName(factory.name)
                    self.addService()
            elif section.startswith("infiniproxy "):
                factory = BetaProxyFactory(section[12:])
                server = TCPServer(factory.port, factory)
                server.setName(factory.name)
                self.addService(server)
            elif section.startswith("infininode "):
                factory = InfiniNodeFactory(section[11:])
                server = TCPServer(factory.port, factory)
                server.setName(factory.name)
                self.addService(server)
Пример #2
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))
Пример #3
0
    def makeService(self, opts):
        from carchive._conf import ConfigDict
        from carchive.archmiddle.proxy import buildResource
        from carchive.archmiddle.info import InfoCache, KeyNameMap

        server = ConfigDict(opts['config'], 'server')
        mapping = ConfigDict(opts['config'], 'mapping')

        handle = Log2Twisted()
        handle.setFormatter(logging.Formatter("%(message)s"))
        root = logging.getLogger()
        root.addHandler(handle)
        root.setLevel(server.getint('log.level', logging.INFO))

        # turn down the noise level...
        CRL = logging.getLogger('carchive.rpcmunge')
        if CRL.isEnabledFor(logging.DEBUG):
            CRL.setLevel(logging.INFO)

        mservice = service.MultiService()

        _M = []
        for k, v in mapping.iteritems():
            v = v.split()
            _M.append((k, int(v[0]), v[1:]))

        KM = KeyNameMap(_M)
        info = InfoCache(server['url'], KM)

        root, leaf = buildResource(info, reactor)
        fact = Site(root)

        info.pvlimit = server.getint('cache.limit', 500)
        info.timeout = server.getfloat('cache.timeout', 3600)

        mservice.addService(
            TCPServer(server.getint('port'),
                      fact,
                      interface=server.get('interface', '')))

        if ShellFactory and server.getint('manhole.port', 0):
            print 'Opening Manhole'
            SF = ShellFactory()
            SS = TCPServer(server.getint('manhole.port', 0),
                           SF,
                           interface='127.0.0.1')

            # populate manhole shell locals
            SF.namespace['site'] = fact
            SF.namespace['node'] = leaf
            SF.namespace['info'] = info

            mservice.addService(SS)
        else:
            print 'No Manhole'

        return mservice
Пример #4
0
def setupReceivers(root_service, settings):
    from carbon.protocols import MetricLineReceiver, MetricPickleReceiver, MetricDatagramReceiver

    for protocol, interface, port in [
        (MetricLineReceiver, settings.LINE_RECEIVER_INTERFACE,
         settings.LINE_RECEIVER_PORT),
        (MetricPickleReceiver, settings.PICKLE_RECEIVER_INTERFACE,
         settings.PICKLE_RECEIVER_PORT)
    ]:
        if port:
            factory = ServerFactory()
            factory.protocol = protocol
            service = TCPServer(port, factory, interface=interface)
            service.setServiceParent(root_service)

    if settings.ENABLE_UDP_LISTENER:
        service = UDPServer(int(settings.UDP_RECEIVER_PORT),
                            MetricDatagramReceiver(),
                            interface=settings.UDP_RECEIVER_INTERFACE)
        service.setServiceParent(root_service)

    if settings.ENABLE_AMQP:
        from carbon import amqp_listener
        amqp_host = settings.AMQP_HOST
        amqp_port = settings.AMQP_PORT
        amqp_user = settings.AMQP_USER
        amqp_password = settings.AMQP_PASSWORD
        amqp_verbose = settings.AMQP_VERBOSE
        amqp_vhost = settings.AMQP_VHOST
        amqp_spec = settings.AMQP_SPEC
        amqp_exchange_name = settings.AMQP_EXCHANGE

        factory = amqp_listener.createAMQPListener(
            amqp_user,
            amqp_password,
            vhost=amqp_vhost,
            spec=amqp_spec,
            exchange_name=amqp_exchange_name,
            verbose=amqp_verbose)
        service = TCPClient(amqp_host, amqp_port, factory)
        service.setServiceParent(root_service)

    if settings.ENABLE_MANHOLE:
        from carbon import manhole

        factory = manhole.createManholeListener()
        service = TCPServer(settings.MANHOLE_PORT,
                            factory,
                            interface=settings.MANHOLE_INTERFACE)
        service.setServiceParent(root_service)
Пример #5
0
def application(config):
    app = Application("Scrapyd")
    http_port = int(environ.get('PORT', config.getint('http_port', 6800)))
    config.cp.set('scrapyd', 'database_url', environ.get('DATABASE_URL'))

    poller = Psycopg2QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = Psycopg2SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    launcher = Launcher(config, app)
    timer = TimerService(5, poller.poll)
    webservice = TCPServer(http_port, server.Site(Root(config, app)))
    log.msg("Scrapyd web console available at http://localhost:%s/ (HEROKU)" %
            http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
Пример #6
0
def createCacheService(config):
    from carbon.cache import MetricCache, UDPForward
    from carbon.conf import settings
    from carbon.protocols import CacheManagementHandler

    # Configure application components
    events.metricReceived.addHandler(MetricCache.store)

    root_service = createBaseService(config)
    factory = ServerFactory()
    factory.protocol = CacheManagementHandler
    service = TCPServer(int(settings.CACHE_QUERY_PORT),
                        factory,
                        interface=settings.CACHE_QUERY_INTERFACE)
    service.setServiceParent(root_service)

    # have to import this *after* settings are defined
    from carbon.writer import WriterService

    service = WriterService()
    service.setServiceParent(root_service)

    # Turn on UDP forwarding
    if settings.ENABLE_UDP_FORWARDING:
        udp_forward = UDPForward()
        events.metricReceived.addHandler(udp_forward.sendDatapoint)

    if settings.USE_FLOW_CONTROL:
        events.cacheFull.addHandler(events.pauseReceivingMetrics)
        events.cacheSpaceAvailable.addHandler(events.resumeReceivingMetrics)

    return root_service
Пример #7
0
    def makeService(self, opts):
        from carchive.a2aproxy.resource import buildResource
        from carchive.util import LimitedSite, LimitedTCPServer

        L = logging.INFO
        if opts['debug']:
            L = logging.DEBUG

        handle = Log2Twisted()
        handle.setFormatter(
            logging.Formatter("%(levelname)s:%(name)s %(message)s"))
        root = logging.getLogger()
        root.addHandler(handle)
        root.setLevel(L)

        serv = service.MultiService()

        fact = LimitedSite(buildResource(opts['appl']))

        serv.addService(
            LimitedTCPServer(opts['port'], fact, interface=opts['ip']))

        if ShellFactory and opts['manhole']:
            print 'Opening Manhole'
            SF = ShellFactory()
            SS = TCPServer(opts['manhole'], SF, interface='127.0.0.1')

            # populate manhole shell locals
            SF.namespace['site'] = fact

            serv.addService(SS)
        else:
            print 'No Manhole'

        return serv
Пример #8
0
 def makeService(self, options):
     config = options
     import cap
     import sys
     sys.path.insert(1,cap.__path__[0])
     del sys.modules["cap"]
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cap.settings")
     mysql_url = options["mysql_url"].strip()
     try:
         a, b = mysql_url.split(":")
         mysql_host = a
         mysql_port, mysql_db = b.split("/")
         mysql_port = int(mysql_port)
     except:
         print "mysql相关配置错误"
         raise Exception("mysql相关配置错误")
     else:
         mysql_user = options["mysql_user"]
         mysql_password = options["mysql_password"]
     os.config = [mysql_host,mysql_port,mysql_db,mysql_user,mysql_password]
     from django.core.handlers.wsgi import WSGIHandler
     application = WSGIHandler()
     resource = WSGIResource(reactor, reactor.getThreadPool(), application)
     ui_service=TCPServer(9912,server.Site(resource),interface=config["host"])
     return ui_service
Пример #9
0
def createBaseService(options):
    root_service = RurouniRootService()
    root_service.setName('rurouni')

    receive_services = (
        (settings.LINE_RECEIVER_INTERFACE,
         settings.LINE_RECEIVER_PORT,
         protocols.MetricLineReceiver
        ),
        (settings.PICKLE_RECEIVER_INTERFACE,
         settings.PICKLE_RECEIVER_PORT,
         protocols.MetricPickleReceiver
        ),
    )
    for interface, port, protocol in receive_services:
        if port:
            factory = ServerFactory()
            factory.protocol = protocol
            service = TCPServer(int(port), factory, interface=interface)
            service.setServiceParent(root_service)

    from rurouni.state.instrumentation import InstrumentationService
    service = InstrumentationService()
    service.setServiceParent(root_service)

    return root_service
Пример #10
0
def application(config):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    launcher = Launcher(config, app)
    timer = TimerService(5, poller.poll)
    webservice = TCPServer(http_port,
                           server.Site(Root(config, app)),
                           interface=bind_address)
    log.msg("Scrapyd web console available at http://%s:%s/" %
            (bind_address, http_port))

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
Пример #11
0
    def makeService(self, options):
        port, site, application = setupApplication(options)
        # Check database health.
        logging.info('Checking database health.')
        try:
            verifyStore()
        except Exception as error:
            logging.error(error)
            logging.critical('Shutting down.')
            sys.exit(1)
        else:
            logging.info('Database is up-to-date.')

        # Log configuration parameters.
        config = getConfig()
        logging.info('PID is %s', os.getpid())
        logging.info('service/temp-path is %s',
                     config.get('service', 'temp-path'))
        logging.info('service/max-threads is %s',
                     config.get('service', 'max-threads'))
        logging.info('service/port is %s', config.get('service', 'port'))
        logging.info('store/main-uri is %s', config.get('store', 'main-uri'))
        logging.info('index/url is %s', config.get('index', 'url'))

        # Register the application.
        return TCPServer(int(options['port']), site)
Пример #12
0
    def _configure_web_server(self, config, controller):
        interfaces, https, key_file, cert_file, chain_file, _, _ = \
            self._validate_web_config(config)

        site = server.Site(get_web_app(config, controller))
        web_servers = []

        for interface, port in interfaces:
            if https:
                cf = SSLCertOptions(key_file, cert_file, chain_file)
                web_server = SSLServer(port, site, cf, interface=interface)
                method = 'https'
            else:
                web_server = TCPServer(port, site, interface=interface)
                method = 'http'

            web_servers.append(web_server)

            if ':' in interface:
                interface = '[{}]'.format(interface)
            log.msg(format="Scrapy-Do web interface is available at "
                    "%(method)s://%(interface)s:%(port)s/",
                    method=method,
                    interface=interface,
                    port=port)

        return web_servers
Пример #13
0
 def run_interface(config):
     factory = ServerFactory()
     factory.protocol = lambda: TelnetTransport(JunctionTelnetInterface)
     port = int(config['App']['TelnetInterfacePort'])
     logging.info("starting telnet cli interface on port %d" % port)
     service = TCPServer(port, factory)
     service.startService()
Пример #14
0
def createCacheService(config):
    from carbon.cache import MetricCache
    from carbon.conf import settings
    from carbon.protocols import CacheManagementHandler

    # Configure application components
    events.metricReceived.addHandler(MetricCache.store)

    root_service = createBaseService(config)
    factory = ServerFactory()
    factory.protocol = CacheManagementHandler
    service = TCPServer(int(settings.CACHE_QUERY_PORT),
                        factory,
                        interface=settings.CACHE_QUERY_INTERFACE,
                        backlog=settings.CACHE_QUERY_BACKLOG)
    service.setServiceParent(root_service)

    # have to import this *after* settings are defined
    from carbon.writer import WriterService

    service = WriterService()
    service.setServiceParent(root_service)

    if settings.USE_FLOW_CONTROL:
        events.cacheFull.addHandler(events.pauseReceivingMetrics)
        events.cacheSpaceAvailable.addHandler(events.resumeReceivingMetrics)

    return root_service
Пример #15
0
    def makeService(self, options):
        """
        Create a service which will run a scram server.

        @param options: mapping of configuration
        """

        from scram.network import ScramFactory
        from scram.world import (TCP_SERVICE_NAME, SCRAM_SERVICE_NAME,
                                 ScramService, World)

        from twisted.internet import reactor
        from twisted.application.service import MultiService
        from twisted.protocols.policies import TrafficLoggingFactory

        world = World(granularity=60, platformClock=reactor)

        service = MultiService()

        factory = ScramFactory(world)
        if options['log-directory'] is not None:
            factory = TrafficLoggingFactory(
                factory, join(options['log-directory'], 'scram'))

        tcp = TCPServer(options['port'], factory, interface='127.0.0.1')
        tcp.setName(TCP_SERVICE_NAME)
        tcp.setServiceParent(service)

        scram = ScramService(world)
        scram.setName(SCRAM_SERVICE_NAME)
        scram.setServiceParent(service)

        return service
Пример #16
0
def setupManhole(application, config):
    """Setup an SSH manhole for the API service.

    The manhole port is taken from the C{manhole-port} option in the config
    file. If this option is not provided the api port plus 100 is used.

    @param application: The fluidinfo API L{Application} object.
    @param config: The configuration object.
    """
    servicePort = config.getint('service', 'port')
    if config.has_option('service', 'manhole-port'):
        manholePort = config.getint('service', 'manhole-port')
    else:
        manholePort = servicePort + 100

    def getManhole(_):
        manhole = Manhole(globals())
        ps1 = 'fluidinfo-api [%d] > ' % servicePort
        ps2 = '... '.rjust(len(ps1))
        manhole.ps = (ps1, ps2)
        return manhole

    realm = TerminalRealm()
    realm.chainedProtocolFactory.protocolFactory = getManhole
    portal = Portal(realm)
    portal.registerChecker(SSHPublicKeyDatabase())
    factory = ConchFactory(portal)
    manholeService = TCPServer(manholePort, factory, interface='127.0.0.1')
    manholeService.setServiceParent(application)
Пример #17
0
def create_status_service(proxy_server, port):
    """Create the status service."""
    root = resource.Resource()
    root.putChild('status', _Status(proxy_server))
    site = server.Site(root)
    service = TCPServer(port, site)
    return service
Пример #18
0
def application(config):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')
    poll_interval = config.getfloat('poll_interval', 5)

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
    laucls = load_object(laupath)
    launcher = laucls(config, app)

    timer = TimerService(poll_interval, poller.poll)
    webservice = TCPServer(http_port,
                           server.Site(Root(config, app)),
                           interface=bind_address)
    log.msg(
        format=
        "Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
        bind_address=bind_address,
        http_port=http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
Пример #19
0
def get_application(arguments):
    ServiceRoot = load_object(settings.SERVICE_ROOT)
    site = Site(ServiceRoot())
    application = Application('scrapyrt')
    server = TCPServer(arguments.port, site, interface=arguments.ip)
    server.setServiceParent(application)
    return application
Пример #20
0
 def __init__(self, **options):
     MultiService.__init__(self)
     self.addService(
         TCPServer(
             options['port'],
             PeerchatProxyServerFactory(options['game'], options['host'],
                                        6667)))
Пример #21
0
 def add_maybe_ssl(self, port, factory, ssl_cf):
     # type: (int, ServerFactory, Optional[Any]) -> None
     """Add a Service from factory, optionally behind TLS"""
     self.addService(
         SSLServer(port, factory, contextFactory=ssl_cf, reactor=reactor)
         if ssl_cf else
         TCPServer(port, factory, reactor=reactor)
     )
Пример #22
0
    def setup(self, cfg):

        BasePlugin.setup(self, cfg)

        self.factory = TelnetFactory(plugin=self)
        self.factory.plugin = self

        self.client = TCPServer(self.cfg.get("port", 9999), self.factory)
Пример #23
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)
Пример #24
0
def getService(library, port=3689):
    """Return a DAAP server service instance attached to the given port."""
    from twisted.application.internet import TCPServer
    from twisted.web import server

    Resource.library = library

    return TCPServer(port, server.Site(server.Site(RootResource())))
Пример #25
0
    def registry(self):
        root = NestRoot(self.app, debug=False)
        for (path, service) in self.webservices.items():
            root.putChild(path.encode('utf-8'), service(root))

        server = TCPServer(self.port, Site(root), interface=self.host)
        server.setServiceParent(self.app)
        return self.app
Пример #26
0
    def build(cls, root_service):
        if not settings.ENABLE_MANHOLE:
            return

        factory = createManholeListener()
        service = TCPServer(settings.MANHOLE_PORT,
                            factory,
                            interface=settings.MANHOLE_INTERFACE)
        service.setServiceParent(root_service)
Пример #27
0
 def makeService(self, options):
     config = valid_config()
     s = MultiService()
     from crondeamon.slave import service as subrpc
     serverfactory = server.Site(subrpc.MainRpc())
     slave_service = TCPServer(int(config["slaveport"]),
                               serverfactory,
                               interface=config["host"])
     slave_service.setServiceParent(s)
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cap.settings")
     from django.core.handlers.wsgi import WSGIHandler
     application = WSGIHandler()
     resource = WSGIResource(reactor, reactor.getThreadPool(), application)
     ui_service = TCPServer(int(config["uiport"]),
                            server.Site(resource),
                            interface=config["host"])
     ui_service.setServiceParent(s)
     return s
Пример #28
0
    def makeService(self, options):
        config = options
        s = MultiService()

        from cap_twisted import service as mainrpc
        serverfactory = server.Site(mainrpc.MainRpc(config["master"],config["work_dir"]))
        slave_service = TCPServer(9913, serverfactory, interface=config["host"])
        slave_service.setServiceParent(s)
        return s
Пример #29
0
    def configure_services(self, configuration):
        read_configuration()

        for section in configuration.sections():
            if section.startswith("world "):
                factory = BravoFactory(section[6:])
                server = TCPServer(factory.port,
                                   factory,
                                   interface=factory.interface)
                self.addService(server)
            elif section.startswith("irc "):
                factory = BravoIRC(worlds, section[4:])
                self.addService(TCPClient(factory.host, factory.port, factory))
            elif section.startswith("infiniproxy "):
                factory = BetaProxyFactory(section[12:])
                self.addService(TCPServer(factory.port, factory))
            elif section.startswith("infininode "):
                factory = InfiniNodeFactory(section[11:])
                self.addService(TCPServer(factory.port, factory))
Пример #30
0
 def __init__(self, **options):
     basePort = 18710
     MultiService.__init__(self)
     sCtx = OpenSSLContextFactoryFactory.getFactory('fesl.ea.com')
     sFact = Mercs2LoginFactory()
     #sFact = makeTLSFwdFactory('fesl.fwdCli', 'fesl.fwdSer')('mercs2-pc.fesl.ea.com', basePort)
     self.addService(SSLServer(basePort, sFact, sCtx))
     sFact = Mercs2TheaterFactory()
     #sFact = makeTCPFwdFactory('theater.fwdCli', 'theater.fwdSer')('mercs2-pc.theater.ea.com', basePort+5)
     self.addService(TCPServer(basePort + 5, sFact))