当前位置: 首页>>代码示例>>Python>>正文


Python LOG.redirect方法代码示例

本文整理汇总了Python中neubot.log.LOG.redirect方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.redirect方法的具体用法?Python LOG.redirect怎么用?Python LOG.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neubot.log.LOG的用法示例。


在下文中一共展示了LOG.redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):

    CONFIG.register_descriptions({
        "rendezvous.server.address": "Set rendezvous server address",
        "rendezvous.server.daemonize": "Enable daemon behavior",
        "rendezvous.server.ports": "List of rendezvous server ports",
        "rendezvous.server.update_uri": "Where to download updates from",
        "rendezvous.server.update_version": "Update Neubot version number",
        "rendezvous.geoip_wrapper.country_database": "Path of the GeoIP country database",
        "rendezvous.server.default": "Default test server to use",
    })

    common.main("rendezvous.server", "Rendezvous server", args)
    conf = CONFIG.copy()

    HTTP_SERVER.configure(conf)
    for port in conf["rendezvous.server.ports"].split(","):
        HTTP_SERVER.listen((conf["rendezvous.server.address"], int(port)))

    # Really start this module
    run(POLLER, conf)

    if conf["rendezvous.server.daemonize"]:
        system.change_dir()
        system.go_background()
        LOG.redirect()

    system.drop_privileges(LOG.error)
    POLLER.loop()
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:31,代码来源:server.py

示例2: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):

    CONFIG.register_descriptions({
        "speedtest.negotiate.address": "Address to listen to",
        "speedtest.negotiate.auth_only": "Enable doing tests for authorized clients only",
        "speedtest.negotiate.daemonize": "Enable going in background",
        "speedtest.negotiate.port": "Port to listen to",
    })

    common.main("speedtest.negotiate", "Speedtest negotiation server", args)

    conf = CONFIG.copy()

    server = ServerSpeedtest(POLLER)
    server.configure(conf)
    server.listen((conf["speedtest.negotiate.address"],
                  conf["speedtest.negotiate.port"]))

    if conf["speedtest.negotiate.daemonize"]:
        system.change_dir()
        system.go_background()
        LOG.redirect()

    system.drop_privileges(LOG.error)
    POLLER.loop()
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:27,代码来源:negotiate.py

示例3: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):

    daemonize = True
    blink = False
    nohide = True

    try:
        options, arguments = getopt.getopt(args[1:], "BdnqVv", ["help"])
    except getopt.GetoptError:
        sys.stderr.write(USAGE % args[0])
        sys.exit(1)

    for name, value in options:
        if name == "-B":
            blink = True
        elif name == "-d":
            daemonize = False
        elif name == "--help":
            sys.stdout.write(HELP % args[0])
            sys.exit(0)
        elif name == "-n":
            nohide = True
        elif name == "-q":
            nohide = False
        elif name == "-V":
            sys.stderr.write(VERSION + "\n")
            sys.exit(0)
        elif name == "-v":
            LOG.verbose()

    if len(arguments) >= 3:
        sys.stderr.write(USAGE % args[0])
        sys.exit(1)
    elif len(arguments) == 2:
        address = arguments[0]
        port = arguments[1]
    elif len(arguments) == 1:
        address = ADDRESS
        port = arguments[0]
    else:
        address = ADDRESS
        port = PORT

    if daemonize:
        system.change_dir()
        system.go_background()
        LOG.redirect()
    system.drop_privileges(LOG.error)

    gtk.gdk.threads_init()
    icon = StatusIcon(address, port, blink, nohide)
    tracker = StateTrackerThread(icon, address, port)
    tracker.daemon = True
    tracker.start()

    gtk.gdk.threads_enter()
    gtk.main()
    gtk.gdk.threads_leave()
    tracker.interrupt()
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:61,代码来源:statusicon.py

示例4: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):
    """ Main function """

    if not system.has_enough_privs():
        sys.exit('FATAL: you must be root')

    common.main("agent", "Run in background, periodically run tests", args)

    conf = CONFIG.copy()

    privacy.complain_if_needed()

    BACKEND.use_backend("neubot")
    BACKEND.datadir_init()

    # FIXME We're ignoring agent.api.{address,port} that are now
    # deprecated and should be removed soon.
    background_api.start_api()

    if conf["agent.daemonize"]:
        LOG.redirect()
        system.go_background()

    if conf["agent.use_syslog"]:
        LOG.redirect()

    #
    # When we run as an agent we also save logs into
    # the database, to easily access and show them via
    # the web user interface.
    #
    LOG.use_database()

    logging.info('%s for POSIX: starting up', utils_version.PRODUCT)

    system.drop_privileges()

    if os.getuid() == 0 or os.geteuid() == 0:
        logging.error('agent: still running as root')
        os._exit(1)

    if conf["agent.rendezvous"]:
        BACKGROUND_RENDEZVOUS.start()

    POLLER.loop()

    logging.info('%s for POSIX: shutting down', utils_version.PRODUCT)
    LOG.writeback()

    #
    # Make sure that we do not leave the database
    # in an inconsistent state.
    #
    DATABASE.close()
开发者ID:EverlastingFire,项目名称:neubot,代码行数:56,代码来源:agent.py

示例5: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):

    CONFIG.register_descriptions({
        # General variables
        "net.stream.certfile": "Set SSL certfile path",
        "net.stream.ipv6": "Enable IPv6",
        "net.stream.key": "Set key for ARC4",
        "net.stream.secure": "Enable SSL",
        "net.stream.server_side": "Enable SSL server-side mode",
        "net.stream.rcvbuf": "Set sock recv buffer (0 = use default)",
        "net.stream.sndbuf": "Set sock send buffer (0 = use default)",
        # For main()
        "net.stream.address": "Set client or server address",
        "net.stream.chunk": "Chunk written by each write",
        "net.stream.clients": "Set number of client connections",
        "net.stream.daemonize": "Enable daemon behavior",
        "net.stream.duration": "Set duration of a test",
        "net.stream.listen": "Enable server mode",
        "net.stream.port": "Set client or server port",
        "net.stream.proto": "Set proto (chargen, discard, or echo)",
    })

    common.main("net.stream", "TCP bulk transfer test", args)

    conf = CONFIG.copy()

    endpoint = (conf["net.stream.address"], conf["net.stream.port"])

    if not conf["net.stream.proto"]:
        if conf["net.stream.listen"]:
            conf["net.stream.proto"] = "chargen"
        else:
            conf["net.stream.proto"] = "discard"
    elif conf["net.stream.proto"] not in ("chargen", "discard", "echo"):
        common.write_help(sys.stderr, "net.stream", "TCP bulk transfer test")
        sys.exit(1)

    handler = GenericHandler(POLLER)
    handler.configure(conf)

    if conf["net.stream.listen"]:
        if conf["net.stream.daemonize"]:
            system.change_dir()
            system.go_background()
            LOG.redirect()
        system.drop_privileges(LOG.error)
        conf["net.stream.server_side"] = True
        handler.listen(endpoint)
    else:
        handler.connect(endpoint, count=conf["net.stream.clients"])

    POLLER.loop()
    sys.exit(0)
开发者ID:DavideAllavena,项目名称:neubot,代码行数:55,代码来源:stream.py

示例6: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):

    config.register_descriptions()
    common.main("bittorrent", "Neubot BitTorrent module", args)
    conf = CONFIG.copy()
    config.finalize_conf(conf)

    if conf["bittorrent.listen"]:

        #
        # If we need to negotiate and we're runing
        # standalone we also need to bring up the
        # global HTTP server.
        #
        if conf["bittorrent.negotiate"]:
            HTTP_SERVER.configure(conf)
            HTTP_SERVER.listen((conf["bittorrent.address"],
                               conf["bittorrent.negotiate.port"]))
            conf["negotiate.listen"] = True
            negotiate.run(POLLER, conf)

        #
        # Drop privileges after listen() so we can
        # bind() to privileged ports
        #
        if conf["bittorrent.daemonize"]:
            system.change_dir()
            system.go_background()
            LOG.redirect()

        system.drop_privileges(LOG.error)

    else:
        #
        # When we're connecting to a remote host to perform a test
        # we want Neubot to quit at the end of the test.  When this
        # happens the test code publishes the "testdone" event, so
        # here we prepare to intercept the event and break our main
        # loop.
        #
        NOTIFIER.subscribe("testdone", lambda event, ctx: POLLER.break_loop())

    run(POLLER, conf)

    POLLER.loop()
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:47,代码来源:__init__.py

示例7: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):
    common.main("agent", "Run in background, periodically run tests", args)

    conf = CONFIG.copy()

    privacy.complain_if_needed()

    if conf["agent.api"]:
        server = HTTP_SERVER
        LOG.debug("* API server root directory: %s" % WWW)
        conf["http.server.rootdir"] = WWW
        conf["http.server.ssi"] = True
        conf["http.server.bind_or_die"] = True
        server.configure(conf)
        server.register_child(ServerAPI(POLLER), "/api")
        server.listen((conf["agent.api.address"], conf["agent.api.port"]))

    if conf["agent.daemonize"]:
        system.change_dir()
        system.go_background()
        system.write_pidfile()
        LOG.redirect()

    if conf["agent.use_syslog"]:
        LOG.redirect()

    system.drop_privileges(LOG.error)

    #
    # When we run as an agent we also save logs into
    # the database, to easily access and show them via
    # the web user interface.
    #
    LOG.use_database()

    if conf["agent.rendezvous"]:
        client = ClientRendezvous(POLLER)
        client.configure(conf)
        client.connect_uri()

    POLLER.loop()
开发者ID:DavideAllavena,项目名称:neubot,代码行数:43,代码来源:agent.py

示例8: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):

    ''' main() function of this module '''

    CONFIG.register_descriptions({
        "http.server.address": "Address to listen to",
        "http.server.class": "Use alternate ServerHTTP-like class",
        "http.server.daemonize": "Run in background as a daemon",
        "http.server.mime": "Enable code that guess mime types",
        "http.server.ports": "List of ports to listen to",
        "http.server.rootdir": "Root directory for static pages",
        "http.server.ssi": "Enable server-side includes",
    })

    common.main("http.server", "Neubot simple HTTP server", args)
    conf = CONFIG.copy()

    if conf["http.server.class"]:
        make_child = utils.import_class(conf["http.server.class"])
        server = make_child(POLLER)
    else:
        server = HTTP_SERVER

    server.configure(conf)

    if conf["http.server.rootdir"] == ".":
        conf["http.server.rootdir"] = os.path.abspath(".")

    for port in conf["http.server.ports"].split(","):
        if port:
            server.listen((conf["http.server.address"], int(port)))

    if conf["http.server.daemonize"]:
        system.change_dir()
        system.go_background()
        system.write_pidfile()
        LOG.redirect()

    system.drop_privileges(LOG.error)

    POLLER.loop()
开发者ID:DavideAllavena,项目名称:neubot,代码行数:43,代码来源:server.py

示例9: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):
    LOG.redirect()

    #
    # XXX With Windows we need to kill on_gui_login before
    # updating because otherwise the various DLLs are locked
    # and the procedure fails.  This piece of code ASSUMES
    # that we have already killed the Neubot Agent so we can
    # safely kill all the remaining neubotw.exe instances
    # using brute force.
    #
    if sys.platform == "win32":
        options, arguments = getopt.getopt(args[1:], "k")
        for name, value in options:
            if name == "-k":
                _proc_win32._kill_process("neubotw.exe")
                sys.exit(0)

    # Give daemon some time to breathe first
    time.sleep(30)
    realmain(args, lambda: random.randrange(300, 1500))
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:23,代码来源:on_gui_login.py

示例10: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]

#.........这里部分代码省略.........
    HTTP_SERVER.configure(conf)

    #
    # New-new style: don't bother with abstraction and start the fucking
    # server by invoking its listen() method.
    #
    if CONFIG['server.raw']:
        logging.debug('server: starting raw server... in progress')
        RAW_SERVER_EX.listen((address, 12345),
          CONFIG['prefer_ipv6'], 0, '')
        logging.debug('server: starting raw server... complete')

    if conf['server.skype']:
        logging.debug('server: starting skype server... in progress')
        SKYPE_SERVER_EX.listen((":: 0.0.0.0", 45678),
            CONFIG['prefer_ipv6'], 0, '')
        logging.debug('server: starting skype server... complete')

    #
    # New-style modules are started just setting a
    # bunch of conf[] variables and then invoking
    # their run() method in order to kick them off.
    # This is now depricated in favor of the new-
    # new style described above.
    #

    if conf["server.negotiate"]:
        negotiate.run(POLLER, conf)

    if conf["server.bittorrent"]:
        conf["bittorrent.address"] = address
        conf["bittorrent.listen"] = True
        conf["bittorrent.negotiate"] = True
        bittorrent.run(POLLER, conf)

    if conf['server.speedtest']:
        #conf['speedtest.listen'] = 1           # Not yet
        #conf['speedtest.negotiate'] = 1        # Not yet
        neubot.speedtest.wrapper.run(POLLER, conf)

    # Migrating from old style to new style
    if conf["server.rendezvous"]:
        #conf["rendezvous.listen"] = True       # Not yet
        neubot.rendezvous.server.run()

    #
    # Historically Neubot runs on port 9773 and
    # 8080 but we would like to switch to port 80
    # in the long term period, because it's rare
    # that they filter it.
    # OTOH it looks like it's not possible to
    # do that easily w/ M-Lab because the port
    # is already taken.
    #
    ports = (80, 8080, 9773)
    for port in ports:
        HTTP_SERVER.listen((address, port))

    #
    # Start server-side API for Nagios plugin
    # to query the state of the server.
    # functionalities.
    #
    if conf["server.sapi"]:
        server = ServerSideAPI(POLLER)
        server.configure(conf)
        HTTP_SERVER.register_child(server, "/sapi")

    #
    # Create localhost-only debug server
    #
    if CONFIG['server.debug']:
        logging.info('server: Starting debug server at {127.0.0.1,::1}:9774')
        server = DebugAPI(POLLER)
        server.configure(conf)
        server.listen(('127.0.0.1 ::1', 9774))

    # Probe existing modules and ask them to attach to us
    utils_modules.modprobe(None, "server", {
        "http_server": HTTP_SERVER,
        "negotiate_server": NEGOTIATE_SERVER,
    })

    #
    # Go background and drop privileges,
    # then enter into the main loop.
    #
    if conf["server.daemonize"]:
        LOG.redirect()
        system.go_background()

    sigterm_handler = lambda signo, frame: POLLER.break_loop()
    signal.signal(signal.SIGTERM, sigterm_handler)

    logging.info('Neubot server -- starting up')
    system.drop_privileges()
    POLLER.loop()

    logging.info('Neubot server -- shutting down')
    utils_posix.remove_pidfile('/var/run/neubot.pid')
开发者ID:claudiuperta,项目名称:neubot,代码行数:104,代码来源:server.py

示例11: Exception

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
if __name__ == "__main__":

    logging.info("INFO w/ logging.info")
    logging.debug("DEBUG w/ logging.debug")
    logging.warning("WARNING w/ logging.warning")
    logging.error("ERROR w/ logging.error")

    print compat.json.dumps(LOG.listify())

    access_logger = logging.getLogger('access')
    access_logger.info('Test access logger')

    try:
        raise Exception("Testing exc_info")
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        logging.error('EXCEPTION', exc_info=1)

    oops("Testing the new oops feature")

    # Testing variadic args
    logging.warning("WARNING %s", "variadic warning")

    LOG.redirect()

    logging.info("INFO w/ logging.info")
    logging.debug("DEBUG w/ logging.debug")
    logging.warning("WARNING w/ logging.warning")
    logging.error("ERROR w/ logging.error")
开发者ID:EverlastingFire,项目名称:neubot,代码行数:32,代码来源:log.py

示例12: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):

    config.register_descriptions()
    common.main("bittorrent", "Neubot BitTorrent module", args)
    conf = CONFIG.copy()
    config.finalize_conf(conf)

    if conf["bittorrent.listen"]:

        #
        # If we need to negotiate and we're runing
        # standalone we also need to bring up the
        # global HTTP server.
        #
        if conf["bittorrent.negotiate"]:
            HTTP_SERVER.configure(conf)
            HTTP_SERVER.listen((conf["bittorrent.address"],
                               conf["bittorrent.negotiate.port"]))
            conf["negotiate.listen"] = True
            negotiate.run(POLLER, conf)

        #
        # Drop privileges after listen() so we can
        # bind() to privileged ports
        #
        if conf["bittorrent.daemonize"]:
            system.change_dir()
            system.go_background()
            LOG.redirect()

        system.drop_privileges(LOG.error)

    else:

        #
        # If possible use the runner, which will execute the
        # test in the context of the neubot daemon.  Then exit
        # to bypass the run() invokation that is below here.
        # If the runner fails, fallback to the usual code path,
        # which executes the test in the context of the local
        # process.
        # Set 'runned.enabled' to 0 to bypass the runner and
        # run the test locally.
        #
        if (utils.intify(conf['runner.enabled']) and
            runner_clnt.runner_client(conf["agent.api.address"],
                                      conf["agent.api.port"],
                                      LOG.noisy, "bittorrent")):
            sys.exit(0)

        LOG.info('Will run the test in the local context...')

        #
        # When we're connecting to a remote host to perform a test
        # we want Neubot to quit at the end of the test.  When this
        # happens the test code publishes the "testdone" event, so
        # here we prepare to intercept the event and break our main
        # loop.
        #
        NOTIFIER.subscribe("testdone", lambda event, ctx: POLLER.break_loop())

    run(POLLER, conf)

    POLLER.loop()
开发者ID:DavideAllavena,项目名称:neubot,代码行数:66,代码来源:__init__.py

示例13: __start_neubot_agent

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def __start_neubot_agent():
    ''' Fork a new process and run neubot agent '''

    # Fork a new process
    pid = os.fork()
    if pid > 0:
        syslog.syslog(syslog.LOG_INFO, 'Neubot agent PID: %d' % pid)
        return pid

    #
    # The child code is surrounded by this giant try..except
    # because we don't want the child process to eventually
    # return to the caller.
    #
    try:
        syslog.openlog('neubot', syslog.LOG_PID, syslog.LOG_DAEMON)

        # Add neubot directory to python search path
        if not os.access(VERSIONDIR, os.R_OK|os.X_OK):
            raise RuntimeError('Cannot access: %s' % VERSIONDIR)

        if not VERSIONDIR in sys.path:
            syslog.syslog(syslog.LOG_ERR,
                          'Prepending "%s" to Python search path' %
                          VERSIONDIR)
            sys.path.insert(0, VERSIONDIR)

        # Import the required modules
        from neubot.log import LOG
        from neubot.net.poller import POLLER
        from neubot import agent

        #
        # Redirect logger to syslog now, so early errors in
        # agent.py:main() are logged.
        #
        LOG.redirect()

        #
        # Close all unneeded file descriptors, but save stdio,
        # which has just been redirected.
        #
        for tmpdesc in range(3, 64):
            try:
                os.close(tmpdesc)
            except OSError:
                pass
            except:
                pass

        # Handle SIGTERM gracefully
        sigterm_handler = lambda signo, frame: POLLER.break_loop()
        signal.signal(signal.SIGTERM, sigterm_handler)

        #
        # Here we're running as root but this is OK because
        # neubot/agent.py is going to drop the privileges to
        # the unprivileged user `_neubot`.
        #
        agent.main(['neubot/agent.py',
                    '-D agent.daemonize=OFF',
                    '-D agent.use_syslog=ON'])

    #
    # We must employ __exit() instead of sys.exit() because
    # the latter is catched below by our catch-all clauses and
    # the child process will start running the parent code.
    # OTOH __exit() exits immediately.
    #
    except:
        try:
            why = asyncore.compact_traceback()
            syslog.syslog(syslog.LOG_ERR,
                          'Unhandled exception in the Neubot agent: %s' %
                          str(why))
        except:
            pass
        __exit(1)
    else:
        __exit(0)
开发者ID:EverlastingFire,项目名称:neubot,代码行数:82,代码来源:unix.py

示例14: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]
def main(args):
    """ Starts the server module """

    #
    # Register descriptions in main() only so that
    # we don't advertise the name of knobs that aren't
    # relevant in the current context.
    #
    CONFIG.register_descriptions({
        "server.bittorrent": "Start up BitTorrent test and negotiate server",
        "server.daemonize": "Become a daemon and run in background",
        'server.debug': 'Run the localhost-only debug server',
        "server.negotiate": "Turn on negotiation infrastructure",
        "server.rendezvous": "Start up rendezvous server",
        "server.sapi": "Turn on Server-side API",
        "server.speedtest": "Start up Speedtest test and negotiate server",
    })

    common.main("server", "Neubot server-side component", args)
    conf = CONFIG.copy()

    #
    # Configure our global HTTP server and make
    # sure that we don't provide filesystem access
    # even by mistake.
    #
    conf["http.server.rootdir"] = ""
    HTTP_SERVER.configure(conf)

    #
    # New-style modules are started just setting a
    # bunch of conf[] variables and then invoking
    # their run() method in order to kick them off.
    #
    if conf["server.negotiate"]:
        negotiate.run(POLLER, conf)

    if conf["server.bittorrent"]:
        conf["bittorrent.listen"] = True
        conf["bittorrent.negotiate"] = True
        bittorrent.run(POLLER, conf)

    if conf['server.speedtest']:
        #conf['speedtest.listen'] = 1           # Not yet
        #conf['speedtest.negotiate'] = 1        # Not yet
        neubot.speedtest.wrapper.run(POLLER, conf)

    # Migrating from old style to new style
    if conf["server.rendezvous"]:
        #conf["rendezvous.listen"] = True       # Not yet
        neubot.rendezvous.server.run(POLLER, conf)

    #
    # Historically Neubot runs on port 9773 and
    # 8080 but we would like to switch to port 80
    # in the long term period, because it's rare
    # that they filter it.
    # OTOH it looks like it's not possible to
    # do that easily w/ M-Lab because the port
    # is already taken.
    #
    address = "0.0.0.0"
    ports = (80, 8080, 9773)
    for port in ports:
        HTTP_SERVER.listen((address, port))

    #
    # Start server-side API for Nagios plugin
    # to query the state of the server.
    # functionalities.
    #
    if conf["server.sapi"]:
        server = ServerSideAPI(POLLER)
        server.configure(conf)
        HTTP_SERVER.register_child(server, "/sapi")

    #
    # Create localhost-only debug server
    #
    if CONFIG['server.debug']:
        LOG.info('server: Starting debug server at 127.0.0.1:9774')
        server = DebugAPI(POLLER)
        server.configure(conf)
        server.listen(('127.0.0.1', 9774))

    #
    # Go background and drop privileges,
    # then enter into the main loop.
    #
    if conf["server.daemonize"]:
        system.change_dir()
        system.go_background()
        system.write_pidfile()
        LOG.redirect()

    system.drop_privileges(LOG.error)
    POLLER.loop()
开发者ID:DavideAllavena,项目名称:neubot,代码行数:99,代码来源:server.py

示例15: main

# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import redirect [as 别名]

#.........这里部分代码省略.........

    logging.debug("server: using backend: %s... in progress", backend)
    if backend == "mlab":
        FILESYS.datadir_init()
        BACKEND.use_backend("mlab")
    elif backend == "neubot":
        DATABASE.connect()
        BACKEND.use_backend("neubot")
    else:
        BACKEND.use_backend("null")
    logging.debug("server: using backend: %s... complete", backend)

    for name, value in SETTINGS.items():
        CONFIG[name] = value

    conf = CONFIG.copy()

    #
    # Configure our global HTTP server and make
    # sure that we don't provide filesystem access
    # even by mistake.
    #
    conf["http.server.rootdir"] = ""
    HTTP_SERVER.configure(conf)

    #
    # New-new style: don't bother with abstraction and start the fucking
    # server by invoking its listen() method.
    #
    if CONFIG["server.raw"]:
        logging.debug("server: starting raw server... in progress")
        RAW_SERVER_EX.listen((":: 0.0.0.0", 12345), CONFIG["prefer_ipv6"], 0, "")
        logging.debug("server: starting raw server... complete")

    #
    # New-style modules are started just setting a
    # bunch of conf[] variables and then invoking
    # their run() method in order to kick them off.
    #
    if conf["server.negotiate"]:
        negotiate.run(POLLER, conf)

    if conf["server.bittorrent"]:
        conf["bittorrent.listen"] = True
        conf["bittorrent.negotiate"] = True
        bittorrent.run(POLLER, conf)

    if conf["server.speedtest"]:
        # conf['speedtest.listen'] = 1           # Not yet
        # conf['speedtest.negotiate'] = 1        # Not yet
        neubot.speedtest.wrapper.run(POLLER, conf)

    # Migrating from old style to new style
    if conf["server.rendezvous"]:
        # conf["rendezvous.listen"] = True       # Not yet
        neubot.rendezvous.server.run()

    #
    # Historically Neubot runs on port 9773 and
    # 8080 but we would like to switch to port 80
    # in the long term period, because it's rare
    # that they filter it.
    # OTOH it looks like it's not possible to
    # do that easily w/ M-Lab because the port
    # is already taken.
    #
    address = ":: 0.0.0.0"
    ports = (80, 8080, 9773)
    for port in ports:
        HTTP_SERVER.listen((address, port))

    #
    # Start server-side API for Nagios plugin
    # to query the state of the server.
    # functionalities.
    #
    if conf["server.sapi"]:
        server = ServerSideAPI(POLLER)
        server.configure(conf)
        HTTP_SERVER.register_child(server, "/sapi")

    #
    # Create localhost-only debug server
    #
    if CONFIG["server.debug"]:
        logging.info("server: Starting debug server at {127.0.0.1,::1}:9774")
        server = DebugAPI(POLLER)
        server.configure(conf)
        server.listen(("127.0.0.1 ::1", 9774))

    #
    # Go background and drop privileges,
    # then enter into the main loop.
    #
    if conf["server.daemonize"]:
        LOG.redirect()
        system.go_background()

    system.drop_privileges()
    POLLER.loop()
开发者ID:servetti-polito,项目名称:neubot-dash,代码行数:104,代码来源:server.py


注:本文中的neubot.log.LOG.redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。