Beispiel #1
0
def start_processes():
    processes = ['api', 'task', 'alert']
    # Start cmd processes
    for process in processes:
        env_var = 'DELFIN_' + process.upper() + '_INSTANCES'
        try:
            instances = os.environ.get(env_var)
            # Ignore multiple instance of api
            if not instances or process == 'api':
                instances = '1'
            start_process(process, int(instances))
        except CalledProcessError as cpe:
            logger.error("Got CPE error [%s]:[%s]" % (cpe, tb.print_exc()))
            return
        except ValueError as e:
            logger.error(
                "Got invalid [%s] environment variable:[%s]" % (env_var, e))
            return

    # Start exporter server process
    proc_path = os.path.join(delfin_source_path, 'delfin', 'exporter',
                             'prometheus', 'exporter_server.py')
    command = 'python3 ' + proc_path + ' --config-file ' + \
              conf_file + ' >' + DEVNULL + ' 2>&1 &'
    logger.info("Executing command [%s]", command)
    os.system(command)
    logger.info("Exporter process_started")
Beispiel #2
0
def create_delfin_db():
    try:
        db_path = os.path.join(delfin_source_path, 'script', 'create_db.py')
        subprocess.check_call(['python3', db_path, '--config-file', conf_file])
    except CalledProcessError as cpe:
        logger.error("Got CPE error [%s]:[%s]" % (cpe, tb.print_exc()))
        return
    logger.info('db created ')
Beispiel #3
0
def start_process(process, instances=1):
    for instance in range(0, instances):
        proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd',
                                 process + '.py')
        command = 'python3 ' + proc_path + ' --config-file ' + \
                  conf_file + ' >' + DEVNULL + ' 2>&1 &'
        logger.info("Executing command [%s]", command)
        os.system(command)
        logger.info("[%s] process_started", process)
Beispiel #4
0
def install_delfin():
    python_setup_comm = ['build', 'install']
    req_logs = os.path.join(delfin_log_dir, 'requirements.log')
    command = 'pip3 install -r requirements.txt >' + req_logs + ' 2>&1'
    logger.info("Executing [%s]", command)
    os.system(command)

    setup_file = os.path.join(delfin_source_path, 'setup.py')
    for command in python_setup_comm:
        try:
            command = 'python3 ' + setup_file + ' ' +\
                      command + ' >>' + logfile
            logger.info("Executing [%s]", command)
            os.system(command)
        except CalledProcessError as cpe:
            logger.error("Got CPE error [%s]:[%s]" % (cpe, tb.print_exc()))
            return
Beispiel #5
0
def main():
    global delfin_source_path
    cwd = os.getcwd()
    logger.info("Current dir is %s" % cwd)
    this_file_dir = os.path.dirname(os.path.realpath(__file__))
    delfin_source_path = os.path.join(this_file_dir, "../")

    logger.info("delfins [%s]" % delfin_source_path)
    os.chdir(delfin_source_path)
    logger.info(os.getcwd())

    # create required directories
    create_dir(delfin_etc_dir)
    create_dir(delfin_var_dir)

    # Copy required files
    # Copy api-paste.ini
    ini_file_src = os.path.join(delfin_source_path, 'etc', 'delfin',
                                'api-paste.ini')
    ini_file_dest = os.path.join(delfin_etc_dir, 'api-paste.ini')
    copy_files(ini_file_src, ini_file_dest)

    # Copy the conf file
    conf_file_src = os.path.join(delfin_source_path, 'etc', 'delfin',
                                 'delfin.conf')
    copy_files(conf_file_src, conf_file)

    # install
    install_delfin()

    # create db
    create_delfin_db()

    # start
    start_processes()
Beispiel #6
0
def start_processes():
    # start api process
    proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd', 'api.py')
    command = 'python3 ' + proc_path + ' --config-file ' +\
              conf_file + ' >' + DEVNULL + ' 2>&1 &'
    # >/dev/null 2>&1
    logger.info("Executing command [%s]", command)
    os.system(command)
    logger.info("API process_started")

    # Start task process
    proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd', 'task.py')
    command = 'python3 ' + proc_path + ' --config-file ' +\
              conf_file + ' >' + DEVNULL + ' 2>&1 &'
    logger.info("Executing command [%s]", command)
    os.system(command)

    logger.info("TASK process_started")

    # Start alert process
    proc_path = os.path.join(delfin_source_path, 'delfin', 'cmd', 'alert.py')
    command = 'python3 ' + proc_path + ' --config-file ' +\
              conf_file + ' >' + DEVNULL + ' 2>&1 &'
    logger.info("Executing command [%s]", command)
    os.system(command)
    logger.info("ALERT process_started")

    # Start exporter server process
    proc_path = os.path.join(delfin_source_path, 'delfin', 'exporter',
                             'prometheus', 'exporter_server.py')
    command = 'python3 ' + proc_path + ' --config-file ' +\
              conf_file + ' >' + DEVNULL + ' 2>&1 &'
    logger.info("Executing command [%s]", command)
    os.system(command)
    logger.info("Exporter process_started")