Example #1
0
def run_server(config_file=""):
    if config_file != "":
        config_dir = os.path.dirname(config_file)
        if (not os.path.exists(config_dir)) or (not os.path.isdir(config_dir)):
            print "Error in the config file."
    else:
        config_dir = os.getcwd() + "/configs"
        config_file = config_dir + "/genesis2.conf"

    make_log(config_dir)
    logger = logging.getLogger("genesis2")
    logger.info("Genesis %s" % version())
    if os.path.isfile(config_file):
        logger.info("Using config file %s" % config_file)
    else:
        # Shutdown
        logger.critical("The %s is not a file." % config_file)
        exit(-1)

    # Read config
    config = Config()
    if os.path.exists(config_file) and os.path.isfile(config_file):
        config.load(config_file)
    else:
        logger.critical("The %s doesn't exist" % config_file)
        exit(-1)

    # (kudrom) TODO: I should delete the GenesisManager and substitute it with a Plugin
    GenesisManager(config)

    platform = detect_platform()
    logger.info("Detected platform: %s" % platform)

    # Load plugins
    import genesis2.plugins

    # Load apps
    path_apps = config.get("genesis2", "path_apps", None)
    if path_apps is None:
        path_apps = os.getcwd() + "/apps"
    logger.info("Using %s as path apps." % path_apps)
    appmgr = AppManager(path_apps=path_apps)
    appmgr.load_apps()

    # (kudrom) TODO: Register a new ComponentMgr

    # (kudrom) TODO: we should use an iptables plugin
    # Make sure correct kernel modules are enabled
    # genesis2.utils.shell('modprobe ip_tables')

    if not hasattr(genesis2.apis, "PGenesis2Server"):
        logger.error("There's no plugin for PGenesis2Server registered in the system")
        exit(-1)

    # The server is a plugin to ease its replacement
    logger.info("Starting server")
    server = getattr(genesis2.apis, "PGenesis2Server")
    server.initialize(config)
    server.serve_forever()
Example #2
0
def make_report(app, err):
    """
    Formats a bug report.
    """
    # (kudrom) TODO: It's broken
    pr = ""
    for p in sorted(PluginLoader.list_plugins().keys()):
        pr += p + "\n"

    # Finalize the reported log
    app.log.blackbox.stop()

    buf = app.log.blackbox.buffer.split("\n")
    if len(buf) >= 50:
        buf = buf[-50:]
        buf.insert(0, "(Showing only the last 50 entries)\n")
    buf = "\n".join(buf)

    return (
        "Genesis %s bug report\n"
        + "--------------------\n\n"
        + "System: %s\n"
        + "Detected platform: %s\n"
        + "Detected distro: %s\n"
        + "Python: %s\n\n"
        + "Config path: %s\n\n"
        + "%s\n\n"
        "Loaded plugins:\n%s\n\n" + "Log:\n%s\n"
    ) % (
        version(),
        shell("uname -a"),
        detect_platform(),
        detect_distro(),
        ".".join([str(x) for x in arkos_platform.python_version_tuple()]),
        app.config.filename,
        err,
        pr,
        buf,
    )