Example #1
0
def run(**kwargs):
    config = load_config(os.path.join(repo_root, "config.json"),
                         **kwargs)

    global logger
    logger = config.logger
    set_logger(logger)

    bind_address = config["bind_address"]

    if config["check_subdomains"]:
        check_subdomains(config)

    stash_address = None
    if bind_address:
        stash_address = (config.server_host, get_port(config.server_host))
        logger.debug("Going to use port %d for stash" % stash_address[1])

    with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
        servers = start(config, config.ssl_env, build_routes(config["aliases"]), **kwargs)

        try:
            while any(item.is_alive() for item in iter_procs(servers)):
                for item in iter_procs(servers):
                    item.join(1)
        except KeyboardInterrupt:
            logger.info("Shutting down")
Example #2
0
def run(**kwargs):
    with build_config(os.path.join(repo_root, "config.json"),
                      **kwargs) as config:
        global logger
        logger = config.logger
        set_logger(logger)

        bind_address = config["bind_address"]

        if kwargs.get("alias_file"):
            with open(kwargs["alias_file"], 'r') as alias_file:
                for line in alias_file:
                    alias, doc_root = [x.strip() for x in line.split(',')]
                    config["aliases"].append({
                        'url-path': alias,
                        'local-dir': doc_root,
                    })

        if config["check_subdomains"]:
            check_subdomains(config)

        stash_address = None
        if bind_address:
            stash_address = (config.server_host, get_port(""))
            logger.debug("Going to use port %d for stash" % stash_address[1])

        with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
            servers = start(config, build_routes(config["aliases"]), **kwargs)

            try:
                while any(item.is_alive() for item in iter_procs(servers)):
                    for item in iter_procs(servers):
                        item.join(1)
            except KeyboardInterrupt:
                logger.info("Shutting down")
Example #3
0
def run(**kwargs):
    config = load_config(os.path.join(repo_root, "config.default.json"),
                         os.path.join(repo_root, "config.json"), **kwargs)

    setup_logger(config["log_level"])

    with get_ssl_environment(config) as ssl_env:
        ports = get_ports(config, ssl_env)
        config = normalise_config(config, ports)
        host = config["host"]
        bind_hostname = config["bind_hostname"]

        if config["check_subdomains"]:
            paths = get_paths(config)
            ssl_config = get_ssl_config(config, ssl_env)
            check_subdomains(host, paths, bind_hostname, ssl_config,
                             config["aliases"])

        stash_address = None
        if bind_hostname:
            stash_address = (host, get_port())

        with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
            servers = start(config, ssl_env, build_routes(config["aliases"]),
                            **kwargs)

            try:
                while any(item.is_alive() for item in iter_procs(servers)):
                    for item in iter_procs(servers):
                        item.join(1)
            except KeyboardInterrupt:
                logger.info("Shutting down")
Example #4
0
def run(**kwargs):
    received_signal = threading.Event()

    with build_config(os.path.join(repo_root, "config.json"),
                      **kwargs) as config:
        global logger
        logger = config.logger
        set_logger(logger)
        # Configure the root logger to cover third-party libraries.
        logging.getLogger().setLevel(config.log_level)

        def handle_signal(signum, frame):
            logger.debug("Received signal %s. Shutting down.", signum)
            received_signal.set()

        bind_address = config["bind_address"]

        if kwargs.get("alias_file"):
            with open(kwargs["alias_file"], 'r') as alias_file:
                for line in alias_file:
                    alias, doc_root = [x.strip() for x in line.split(',')]
                    config["aliases"].append({
                        'url-path': alias,
                        'local-dir': doc_root,
                    })

        if config["check_subdomains"]:
            check_subdomains(config)

        stash_address = None
        if bind_address:
            stash_address = (config.server_host, get_port(""))
            logger.debug("Going to use port %d for stash" % stash_address[1])

        with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
            servers = start(config, build_routes(config["aliases"]), **kwargs)
            signal.signal(signal.SIGTERM, handle_signal)
            signal.signal(signal.SIGINT, handle_signal)

            while (all(subproc.is_alive() for subproc in iter_procs(servers))
                   and not received_signal.is_set()):
                for subproc in iter_procs(servers):
                    subproc.join(1)

            failed_subproc = 0
            for subproc in iter_procs(servers):
                if subproc.is_alive():
                    logger.info('Status of subprocess "%s": running' %
                                subproc.name)
                else:
                    if subproc.exitcode == 0:
                        logger.info(
                            'Status of subprocess "%s": exited correctly' %
                            subproc.name)
                    else:
                        logger.warning(
                            'Status of subprocess "%s": failed. Exit with non-zero status: %d'
                            % (subproc.name, subproc.exitcode))
                        failed_subproc += 1
            return failed_subproc
Example #5
0
def run(**kwargs):
    received_signal = threading.Event()

    with build_config(os.path.join(repo_root, "config.json"),
                      **kwargs) as config:
        global logger
        logger = config.logger
        set_logger(logger)
        # Configure the root logger to cover third-party libraries.
        logging.getLogger().setLevel(config.log_level)

        def handle_signal(signum, frame):
            logger.debug("Received signal %s. Shutting down.", signum)
            received_signal.set()

        bind_address = config["bind_address"]

        if kwargs.get("alias_file"):
            with open(kwargs["alias_file"], 'r') as alias_file:
                for line in alias_file:
                    alias, doc_root = [x.strip() for x in line.split(',')]
                    config["aliases"].append({
                        'url-path': alias,
                        'local-dir': doc_root,
                    })

        if config["check_subdomains"]:
            check_subdomains(config)

        stash_address = None
        if bind_address:
            stash_address = (config.server_host, get_port(""))
            logger.debug("Going to use port %d for stash" % stash_address[1])

        with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
            servers = start(config, build_routes(config["aliases"]), **kwargs)
            signal.signal(signal.SIGTERM, handle_signal)
            signal.signal(signal.SIGINT, handle_signal)

            while (all(item.is_alive() for item in iter_procs(servers))
                   and not received_signal.is_set()):
                for item in iter_procs(servers):
                    item.join(1)
            exited = [
                item for item in iter_procs(servers) if not item.is_alive()
            ]
            subject = "subprocess" if len(exited) == 1 else "subprocesses"

            logger.info("%s %s exited:" % (len(exited), subject))

            for item in iter_procs(servers):
                logger.info("Status of %s:\t%s" %
                            (item.name,
                             "running" if item.is_alive() else "not running"))
Example #6
0
def run(**kwargs):
    with build_config(os.path.join(repo_root, "config.json"),
                      **kwargs) as config:
        global logger
        logger = config.logger
        set_logger(logger)

        bind_address = config["bind_address"]

        # Creating wave specific config if kwargs is_wave = true
        wave_cfg = None
        if kwargs.get("is_wave") is True:
            wave_cfg = {
                "is_wave": kwargs.get("is_wave"),
                "report": kwargs.get("report")
            }


        if kwargs.get("alias_file"):
            with open(kwargs["alias_file"], 'r') as alias_file:
                for line in alias_file:
                    alias, doc_root = [x.strip() for x in line.split(',')]
                    config["aliases"].append({
                        'url-path': alias,
                        'local-dir': doc_root,
                    })

        if config["check_subdomains"]:
            # added wave_cfg to pass on to build_routes to init wave handler
            check_subdomains(config, wave_cfg)

        stash_address = None
        if bind_address:
            stash_address = (config.server_host, get_port(""))
            logger.debug("Going to use port %d for stash" % stash_address[1])

        with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
            servers = start(config, build_routes(config["aliases"], wave_cfg), **kwargs)

            try:
                while all(item.is_alive() for item in iter_procs(servers)):
                    for item in iter_procs(servers):
                        item.join(1)
                exited = [item for item in iter_procs(servers) if not item.is_alive()]
                subject = "subprocess" if len(exited) == 1 else "subprocesses"

                logger.info("%s %s exited:" % (len(exited), subject))

                for item in iter_procs(servers):
                    logger.info("Status of %s:\t%s" % (item.name, "running" if item.is_alive() else "not running"))
            except KeyboardInterrupt:
                logger.info("Shutting down")
Example #7
0
def main():
    kwargs = vars(get_parser().parse_args())
    config = load_config("config.default.json", "config.json", **kwargs)

    setup_logger(config["log_level"])

    with stash.StashServer((config["host"], get_port()),
                           authkey=str(uuid.uuid4())):
        with get_ssl_environment(config) as ssl_env:
            config_, servers = start(config, ssl_env, default_routes(),
                                     **kwargs)

            try:
                while any(item.is_alive() for item in iter_procs(servers)):
                    for item in iter_procs(servers):
                        item.join(1)
            except KeyboardInterrupt:
                logger.info("Shutting down")
Example #8
0
def run(**kwargs):
    config = load_config(os.path.join(repo_root, "config.default.json"),
                         os.path.join(repo_root, "config.json"),
                         **kwargs)

    setup_logger(config["log_level"])

    stash_address = None
    if config["bind_hostname"]:
        stash_address = (config["host"], get_port())

    with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
        with get_ssl_environment(config) as ssl_env:
            config_, servers = start(config, ssl_env, build_routes(config["aliases"]), **kwargs)

            try:
                while any(item.is_alive() for item in iter_procs(servers)):
                    for item in iter_procs(servers):
                        item.join(1)
            except KeyboardInterrupt:
                logger.info("Shutting down")
Example #9
0
def main():
    global logger
    datatime = time.strftime("%Y-%m-%d-%H-%M-%S")

    config = load_config(os.path.join(repo_root, "config.json"))

    logger_access = logging.getLogger("access")
    logger_access.setLevel(logging.DEBUG)
    rhandler_access = WPTFileHandler("log/wpt_access" + datatime + ".log",
                                     maxBytes=3 * 1024 * 1024,
                                     backupCount=5,
                                     wpt_type="access")
    logger_access.addHandler(rhandler_access)
    logger_access.propagate = False

    logger_error = logging.getLogger("error")
    logger_error.setLevel(logging.DEBUG)
    rhandler_error = WPTFileHandler("log/wpt_error" + datatime + ".log",
                                    maxBytes=10 * 1024,
                                    backupCount=5,
                                    wpt_type="error")
    logger_error.addHandler(rhandler_error)

    logger = default_logger(config["log_level"])

    with stash.StashServer((config["host"], get_port()),
                           authkey=str(uuid.uuid4())):
        with get_ssl_environment(config) as ssl_env:
            config_, servers = start(config, ssl_env)

            try:
                while any(item.is_alive() for item in iter_procs(servers)):
                    for item in iter_procs(servers):
                        item.join(1)
            except KeyboardInterrupt:
                logger.info("Shutting down")
Example #10
0
def run(config_cls=ConfigBuilder, route_builder=None, mp_context=None, log_handlers=None,
        **kwargs):
    logger = get_logger("INFO", log_handlers)

    if mp_context is None:
        if hasattr(multiprocessing, "get_context"):
            mp_context = multiprocessing.get_context()
        else:
            mp_context = MpContext()

    with build_config(logger,
                      os.path.join(repo_root, "config.json"),
                      config_cls=config_cls,
                      **kwargs) as config:
        # This sets the right log level
        logger = get_logger(config.log_level, log_handlers)

        bind_address = config["bind_address"]

        if kwargs.get("alias_file"):
            with open(kwargs["alias_file"]) as alias_file:
                for line in alias_file:
                    alias, doc_root = (x.strip() for x in line.split(','))
                    config["aliases"].append({
                        'url-path': alias,
                        'local-dir': doc_root,
                    })

        if route_builder is None:
            route_builder = get_route_builder
        routes = route_builder(logger, config.aliases, config).get_routes()

        if config["check_subdomains"]:
            check_subdomains(logger, config, routes, mp_context, log_handlers)

        stash_address = None
        if bind_address:
            stash_address = (config.server_host, get_port(""))
            logger.debug("Going to use port %d for stash" % stash_address[1])

        with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
            servers = start(logger, config, routes, mp_context, log_handlers, **kwargs)

            if not kwargs.get("exit_after_start"):
                try:
                    # Periodically check if all the servers are alive
                    server_process_exited = False
                    while not server_process_exited:
                        for server in iter_servers(servers):
                            server.proc.join(1)
                            if not server.proc.is_alive():
                                server_process_exited = True
                                break
                except KeyboardInterrupt:
                    pass

            failed_subproc = 0
            for server in iter_servers(servers):
                subproc = server.proc
                if subproc.is_alive():
                    logger.info('Status of subprocess "%s": running', subproc.name)
                    server.stop(timeout=1)

                if server.proc.exitcode == 0:
                    logger.info('Status of subprocess "%s": exited correctly', subproc.name)
                else:
                    logger.warning('Status of subprocess "%s": failed. Exit with non-zero status: %d',
                                   subproc.name, subproc.exitcode)
                    failed_subproc += 1
            return failed_subproc