示例#1
0
    def info(cls, timeout=600):
        config_object = Config()
        config = config_object.get_config()

        main_url = "{}://{}.{}{}".format(
            "https" if config.get("https") == Config.TRUE else "http",
            config.get("kpi_subdomain"), config.get("public_domain_name"),
            ":{}".format(config.get("exposed_nginx_docker_port"))
            if config.get("exposed_nginx_docker_port")
            and str(config.get("exposed_nginx_docker_port")) != "80" else "")

        stop = False
        start = int(time.time())
        success = False
        hostname = "{}.{}".format(config.get("kpi_subdomain"),
                                  config.get("public_domain_name"))
        nginx_port = 443 if config.get("https") == Config.TRUE else int(
            config.get("exposed_nginx_docker_port", "80"))
        https = config.get("https") == Config.TRUE
        already_retried = None if config_object.first_time else False
        while not stop:
            if Network.status_check(hostname, "/service_health/", nginx_port,
                                    https) == Network.STATUS_OK_200:
                stop = True
                success = True
            elif int(time.time()) - start >= timeout:
                if timeout > 0:
                    # sometimes frontend can not communicate with backend. docker-compose down/up fixes it.
                    if already_retried is False:
                        CLI.colored_print((
                            "\n`KoBoToolbox` has not started yet, sometimes frontend containers "
                            "can not communicate with backend containers.\n"
                            "Let's restart frontend containers.\n"),
                                          CLI.COLOR_INFO)
                        already_retried = True
                        start = int(time.time())
                        cls.restart_frontend()
                        continue
                    else:
                        if config_object.first_time and already_retried is None:
                            CLI.colored_print(
                                "\n`KoBoToolbox` has not started yet, wait for another {} seconds!"
                                .format(timeout), CLI.COLOR_INFO)
                            start = int(time.time())
                            already_retried = False
                            continue
                stop = True
            else:
                sys.stdout.write(".")
                sys.stdout.flush()
                time.sleep(10)

        # Create a new line
        print("")

        if success:
            username = config.get("super_user_username")
            password = config.get("super_user_password")
            username_chars_count = len(username) + 6
            password_chars_count = len(password) + 10
            url_chars_count = len(main_url) + 6
            max_chars_count = max(username_chars_count, password_chars_count,
                                  url_chars_count)

            CLI.colored_print("╔═{}═╗".format("═" * max_chars_count),
                              CLI.COLOR_WARNING)
            CLI.colored_print(
                "║ Ready {} ║".format(" " * (max_chars_count - len("Ready "))),
                CLI.COLOR_WARNING)
            CLI.colored_print(
                "║ URL: {}/{} ║".format(
                    main_url, " " * (max_chars_count - url_chars_count)),
                CLI.COLOR_WARNING)
            CLI.colored_print(
                "║ User: {}{} ║".format(
                    username, " " * (max_chars_count - username_chars_count)),
                CLI.COLOR_WARNING)
            CLI.colored_print(
                "║ Password: {}{} ║".format(
                    password, " " * (max_chars_count - password_chars_count)),
                CLI.COLOR_WARNING)
            CLI.colored_print("╚═{}═╝".format("═" * max_chars_count),
                              CLI.COLOR_WARNING)
        else:
            CLI.colored_print(
                "Something went wrong! Please look at docker logs",
                CLI.COLOR_ERROR)

        return success
示例#2
0
    def info(cls, timeout=600):
        config_object = Config()
        config = config_object.get_config()

        main_url = "{}://{}.{}{}".format(
            "https" if config.get("https") == Config.TRUE else "http",
            config.get("kpi_subdomain"),
            config.get("public_domain_name"),
            ":{}".format(config.get("exposed_nginx_docker_port")) if config.get("exposed_nginx_docker_port")
                                                                     and str(
                config.get("exposed_nginx_docker_port")) != Config.DEFAULT_NGINX_PORT else ""
        )

        stop = False
        start = int(time.time())
        success = False
        hostname = "{}.{}".format(config.get("kpi_subdomain"), config.get("public_domain_name"))
        nginx_port = int(Config.DEFAULT_NGINX_HTTPS_PORT) if config.get("https") == Config.TRUE \
            else int(config.get("exposed_nginx_docker_port", Config.DEFAULT_NGINX_PORT))
        https = config.get("https") == Config.TRUE
        already_retried = False
        while not stop:
            if Network.status_check(hostname, "/service_health/", nginx_port, https) == Network.STATUS_OK_200:
                stop = True
                success = True
            elif int(time.time()) - start >= timeout:
                if timeout > 0:
                    CLI.colored_print(
                        "\n`KoBoToolbox` has not started yet. This is can be normal with low CPU/RAM computers.\n",
                        CLI.COLOR_INFO)
                    CLI.colored_print("Wait for another {} seconds?".format(timeout), CLI.COLOR_SUCCESS)
                    CLI.colored_print("\t1) Yes")
                    CLI.colored_print("\t2) No")
                    response = CLI.get_response([Config.TRUE, Config.FALSE], Config.TRUE)

                    if response == Config.TRUE:
                        start = int(time.time())
                        continue
                    else:
                        if already_retried is False:
                            already_retried = True
                            CLI.colored_print(("\nSometimes frontend containers "
                                               "can not communicate with backend containers.\n"
                                               "Restarting the frontend containers usually fixes it.\n"),
                                              CLI.COLOR_INFO)
                            CLI.colored_print("Do you want to try?".format(timeout), CLI.COLOR_SUCCESS)
                            CLI.colored_print("\t1) Yes")
                            CLI.colored_print("\t2) No")
                            response = CLI.get_response([Config.TRUE, Config.FALSE], Config.TRUE)
                            if response == Config.TRUE:
                                start = int(time.time())
                                cls.restart_frontend()
                                continue
                stop = True
            else:
                sys.stdout.write(".")
                sys.stdout.flush()
                time.sleep(10)

        # Create a new line
        print("")

        if success:
            username = config.get("super_user_username")
            password = config.get("super_user_password")
            username_chars_count = len(username) + 6
            password_chars_count = len(password) + 10
            url_chars_count = len(main_url) + 6
            max_chars_count = max(username_chars_count, password_chars_count, url_chars_count)

            CLI.colored_print("╔═{}═╗".format("═" * max_chars_count), CLI.COLOR_WARNING)
            CLI.colored_print("║ Ready {} ║".format(
                " " * (max_chars_count - len("Ready "))), CLI.COLOR_WARNING)
            CLI.colored_print("║ URL: {}/{} ║".format(
                main_url, " " * (max_chars_count - url_chars_count)), CLI.COLOR_WARNING)
            CLI.colored_print("║ User: {}{} ║".format(
                username, " " * (max_chars_count - username_chars_count)), CLI.COLOR_WARNING)
            CLI.colored_print("║ Password: {}{} ║".format(
                password, " " * (max_chars_count - password_chars_count)), CLI.COLOR_WARNING)
            CLI.colored_print("╚═{}═╝".format("═" * max_chars_count), CLI.COLOR_WARNING)
        else:
            CLI.colored_print("KoBoToolbox could not start! Please try `python3 run.py --logs` to see the logs.", CLI.COLOR_ERROR)

        return success
示例#3
0
    def info(cls, timeout=600):
        config = Config()
        dict_ = config.get_dict()

        nginx_port = dict_['exposed_nginx_docker_port']

        main_url = '{}://{}.{}{}'.format(
            'https' if dict_['https'] else 'http', dict_['kpi_subdomain'],
            dict_['public_domain_name'], ':{}'.format(nginx_port) if
            (nginx_port
             and str(nginx_port) != Config.DEFAULT_NGINX_PORT) else '')

        stop = False
        start = int(time.time())
        success = False
        hostname = '{}.{}'.format(dict_['kpi_subdomain'],
                                  dict_['public_domain_name'])
        https = dict_['https']
        nginx_port = int(Config.DEFAULT_NGINX_HTTPS_PORT) \
            if https else int(dict_['exposed_nginx_docker_port'])
        already_retried = False
        while not stop:
            if Network.status_check(hostname, '/service_health/', nginx_port,
                                    https) == Network.STATUS_OK_200:
                stop = True
                success = True
            elif int(time.time()) - start >= timeout:
                if timeout > 0:
                    CLI.colored_print(
                        '\n`KoBoToolbox` has not started yet. '
                        'This is can be normal with low CPU/RAM computers.\n',
                        CLI.COLOR_INFO)
                    question = 'Wait for another {} seconds?'.format(timeout)
                    response = CLI.yes_no_question(question)
                    if response:
                        start = int(time.time())
                        continue
                    else:
                        if not already_retried:
                            already_retried = True
                            CLI.colored_print(
                                '\nSometimes front-end containers cannot '
                                'communicate with back-end containers.\n'
                                'Restarting the front-end containers usually '
                                'fixes it.\n', CLI.COLOR_INFO)
                            question = 'Would you like to try?'
                            response = CLI.yes_no_question(question)
                            if response:
                                start = int(time.time())
                                cls.restart_frontend()
                                continue
                stop = True
            else:
                sys.stdout.write('.')
                sys.stdout.flush()
                time.sleep(10)

        # Create a new line
        print('')

        if success:
            username = dict_['super_user_username']
            password = dict_['super_user_password']

            message = ('Ready\n'
                       'URL: {url}\n'
                       'User: {username}\n'
                       'Password: {password}').format(url=main_url,
                                                      username=username,
                                                      password=password)
            CLI.framed_print(message, color=CLI.COLOR_SUCCESS)

        else:
            message = ('KoBoToolbox could not start!\n'
                       'Please try `python3 run.py --logs` to see the logs.')
            CLI.framed_print(message, color=CLI.COLOR_ERROR)

        return success