Esempio n. 1
0
def services(port, background):
    """
    Start the kolibri background services.
    """

    create_startup_lock(None)
    recreate_cache()

    logger.info("Starting Kolibri background services")

    # Daemonize at this point, no more user output is needed
    if background:

        from django.conf import settings

        kolibri_log = settings.LOGGING["handlers"]["file"]["filename"]
        logger.info(
            "Going to background mode, logging to {0}".format(kolibri_log))

        kwargs = {}
        # Truncate the file
        if os.path.isfile(server.DAEMON_LOG):
            open(server.DAEMON_LOG, "w").truncate()
        kwargs["out_log"] = server.DAEMON_LOG
        kwargs["err_log"] = server.DAEMON_LOG

        become_daemon(**kwargs)

    server.start(port=port, serve_http=False)
Esempio n. 2
0
def start(port, background):
    """
    Start the server on given port.
    """

    serve_http = OPTIONS["Server"]["CHERRYPY_START"]

    if serve_http:
        # Check if the port is occupied
        check_other_kolibri_running(port)

    create_startup_lock(port)

    # Clear old sessions up
    call_command("clearsessions")
    recreate_cache()

    # On Mac, Python crashes when forking the process, so prevent daemonization until we can figure out
    # a better fix. See https://github.com/learningequality/kolibri/issues/4821
    if sys.platform == "darwin":
        background = False

    if not background:
        logger.info("Running Kolibri")

    else:
        logger.info("Running Kolibri as background process")

    if serve_http:

        __, urls = server.get_urls(listen_port=port)
        if not urls:
            logger.error(
                "Could not detect an IP address that Kolibri binds to, but try "
                "opening up the following addresses:\n")
            urls = [
                "http://{}:{}".format(ip, port)
                for ip in ("localhost", "127.0.0.1")
            ]
        else:
            logger.info("Kolibri running on:\n")
        for addr in urls:
            sys.stderr.write("\t{}\n".format(addr))
        sys.stderr.write("\n")
    else:
        logger.info("Starting Kolibri background workers")

    # Daemonize at this point, no more user output is needed
    if background:

        from django.conf import settings

        kolibri_log = settings.LOGGING["handlers"]["file"]["filename"]
        logger.info(
            "Going to background mode, logging to {0}".format(kolibri_log))

        kwargs = {}
        # Truncate the file
        if os.path.isfile(server.DAEMON_LOG):
            open(server.DAEMON_LOG, "w").truncate()
        kwargs["out_log"] = server.DAEMON_LOG
        kwargs["err_log"] = server.DAEMON_LOG

        become_daemon(**kwargs)

    server.start(port=port, serve_http=serve_http)