Exemple #1
0
async def stop_remote_archive_task(v_tag):
    cfg = await get_db_archive_config(v_tag)
    if cfg['code'] != 200:
        return cfg

    cmd1 = "ps -ef | grep $$TAG$$ |grep -v grep | awk '{print $2}'  | wc -l".replace(
        '$$TAG$$', v_tag)
    cmd2 = "ps -ef | grep $$TAG$$ |grep -v grep | awk '{print $2}'  | xargs kill -9".replace(
        '$$TAG$$', v_tag)

    ssh = ssh_helper(cfg)
    res = ssh.exec(cmd1)
    if res['status']:
        if int(res['stdout']) == 0:
            res = {'code': -2, 'msg': 'task not running!'}
        else:
            res = ssh.exec(cmd2)
            if res['status']:
                res = {'code': 200, 'msg': 'success'}
            else:
                res = {'code': -1, 'msg': 'failure!'}
    else:
        res = {'code': -1, 'msg': 'failure!'}

    ssh.close()
    return res
Exemple #2
0
async def push(tag):
    cfg = await get_db_sync_config(tag)
    print('cfg=', cfg)
    if cfg['code'] != 200:
        return cfg

    ssh = ssh_helper(cfg)
    ftp = ftp_helper(cfg)

    res = transfer_remote_file_sync(cfg, ssh, ftp)
    if res['code'] != 200:
        raise Exception('transfer_remote_file error!')

    res = run_remote_cmd_sync(cfg, ssh)
    if res['code'] != 200:
        raise Exception('run_remote_cmd error!')

    res = write_remote_crontab_sync(cfg, ssh)
    if res['code'] != 200:
        traceback.print_exc()
        raise Exception('write_remote_crontab error!')

    ssh.close()
    ftp.close()
    return res
Exemple #3
0
async def push(tag):
    cfg = await get_slow_config(tag)
    if cfg['code'] != 200:
        return cfg

    ssh = ssh_helper(cfg)
    ftp = ftp_helper(cfg)

    res = await transfer_remote_file_slow(cfg,ssh,ftp)
    if res['code'] != 200:
        return {'code': -1, 'msg': 'ransfer_remote_file error!'}

    if cfg['msg']['server_os'] != 'Windows':
        res = await run_remote_cmd_slow(cfg,ssh)
        if res['code'] != 200:
            return {'code': -1, 'msg': 'run_remote_cmd error!'}

    if cfg['msg']['server_os'] != 'Windows':
       res = await write_remote_crontab_slow(cfg,ssh)
       if res['code'] != 200:
            return {'code': -1, 'msg': 'write_remote_crontab error!'}

    ssh.close()
    ftp.close()
    return res
Exemple #4
0
async def stop_remote_backup_task(v_tag):
    cfg = await get_db_config(v_tag)
    if cfg['code'] != 200:
        return cfg

    if (await update_backup_status(v_tag, '0'))['code'] == -1:
        return {'code': -1, 'msg': 'update_backup_status failure!'}

    cmd1 = "ps -ef | grep $$TAG$$ |grep -v grep | wc -l".replace(
        '$$TAG$$', v_tag)
    cmd2 = "ps -ef | grep $$TAG$$ |grep -v grep | awk '{print $2}'  | xargs kill -9".replace(
        '$$TAG$$', v_tag)

    ssh = ssh_helper(cfg)
    res = ssh.exec(cmd1)
    if res['status']:
        if int(res['stdout'][0].replace('\n', '')) == 0:
            res = {'code': -2, 'msg': 'task not running!'}
        else:
            res = ssh.exec(cmd2)
            if res['status']:
                res = {'code': 200, 'msg': 'success'}
            else:
                res = {'code': -1, 'msg': 'failure!'}

    else:
        res = {'code': -1, 'msg': 'failure!'}
    ssh.close()
    return res
Exemple #5
0
async def destroy_remote_cmd_inst(v_inst_id):
    cfg = await get_db_inst_config(v_inst_id)
    if cfg['code'] != 200:
        return cfg

    cmd1 = 'chmod +x  {0}/{1}'.format(cfg['msg']['script_path'],
                                      cfg['msg']['script_file'])
    cmd2 = 'chmod +x  {0}/{1}'.format(cfg['msg']['script_path'],
                                      'db_creator.sh')
    cmd3 = 'nohup {0}/db_creator.sh destroy &>/tmp/db_create.log &'.format(
        cfg['msg']['script_path'])

    ssh = ssh_helper(cfg)
    res = ssh.exec(cmd1)
    if not res['status']:
        return {'code': -1, 'msg': 'failure!'}

    res = ssh.exec(cfg, cmd2)
    if not res['status']:
        return {'code': -1, 'msg': 'failure!'}

    res = ssh.exec(cfg, cmd3)
    if not res['status']:
        return {'code': -1, 'msg': 'failure!'}

    ssh.close()
    return {'code': 200, 'msg': 'success!'}
Exemple #6
0
async def mgr_remote_cmd_inst(v_inst_id, v_flag):
    cfg = await get_db_inst_config(v_inst_id)
    if cfg['code'] != 200:
        return cfg
    cmd = 'nohup {0}/db_creator.sh {1} &>/tmp/db_manager.log &'.format(
        cfg['msg']['script_path'], v_flag)
    ssh = ssh_helper(cfg)
    res = ssh.exec(cmd)
    if not res['status']:
        return {'code': -1, 'msg': 'failure!'}
    ssh.close()
    return {'code': 200, 'msg': 'success!'}
Exemple #7
0
async def run_remote_archive_task(p_tag):
    cfg = await get_db_archive_config(p_tag)
    if cfg['code'] != 200:
        return cfg

    cmd = 'nohup {0}/db_archive.sh {1} {2} &>/dev/null &'.format(
        cfg['msg']['script_path'], cfg['msg']['script_file'], p_tag)
    ssh = ssh_helper(cfg)
    res = ssh.exec(cmd)
    if res['status']:
        res = {'code': 200, 'msg': res['stdout']}
    else:
        res = {'code': -1, 'msg': 'failure!'}
    ssh.close()
    return res
Exemple #8
0
async def push(tag):
    cfg = await get_db_transfer_config(tag)
    if cfg['code'] != 200:
        return cfg

    ssh = ssh_helper(cfg)
    ftp = ftp_helper(cfg)

    res = await transfer_remote_file_transfer(cfg, ssh, ftp)
    if res['code'] != 200:
        raise Exception('transfer_remote_file error!')

    res = await run_remote_cmd_transfer(cfg, ssh)
    if res['code'] != 200:
        raise Exception('run_remote_cmd error!')

    ssh.close()
    ftp.close()
    return res
Exemple #9
0
async def run_remote_datax_task(v_tag):
    cfg = await get_datax_sync_config(v_tag)
    if cfg['msg']['sync_type'] == '7':
        cmd = '{0}/datax_sync.sh {1} {2}'.format(cfg['msg']['script_path'],
                                                 'datax_sync_doris.py', v_tag)
    else:
        cmd = 'nohup {0}/datax_sync.sh {1} {2} &>/dev/null &'.format(
            cfg['msg']['script_path'], 'datax_sync.py', v_tag)
    print('cmd=', cmd)
    if cfg['code'] != 200:
        return cfg
    ssh = ssh_helper(cfg)
    res = ssh.exec(cmd)
    if res['status']:
        res = {'code': 200, 'msg': res['stdout']}
    else:
        res = {'code': -1, 'msg': 'failure!'}
    ssh.close()
    return res
Exemple #10
0
async def run_remote_sync_task(v_tag):
    cfg = await get_db_sync_config(v_tag)
    if cfg['code'] != 200:
        return cfg

    ssh = ssh_helper(cfg)
    cmd1 = 'nohup {0}/db_sync.sh {1} {2} &>/dev/null &'.format(
        cfg['msg']['script_path'], cfg['msg']['script_file'], v_tag)
    cmd2 = 'nohup {0}/db_agent.sh &>/dev/null &'.format(
        cfg['msg']['script_path'])
    res = ssh.exec(cmd1)
    if res['status']:
        res = ssh.exec(cmd2)
        if res['status']:
            res = {'code': 200, 'msg': res['stdout']}
        else:
            res = {'code': -1, 'msg': 'failure!'}
    else:
        res = {'code': -1, 'msg': 'failure!'}
    ssh.close()
    return res
Exemple #11
0
async def stop_remote_sync_task(v_tag):
    cfg = await get_db_sync_config(v_tag)
    if cfg['code'] != 200:
        return cfg
    cmd1 = "ps -ef | grep {0} |grep -v grep | wc -l".format(v_tag)
    cmd2 = "ps -ef | grep $$SYNC_TAG$$ |grep -v grep | awk '{print $2}'  | xargs kill -9".replace(
        '$$SYNC_TAG$$', v_tag)

    if (await update_sync_status(v_tag, '0'))['code'] == -1:
        return {'code': -1, 'msg': 'update_sync_status failure!'}

    ssh = ssh_helper(cfg)
    res = ssh.exec(cmd1)
    if res['status']:
        res = ssh.exec(cmd2)
        if res['status']:
            res = {'code': 200, 'msg': res['stdout']}
        else:
            res = {'code': -1, 'msg': 'failure!'}
    else:
        res = {'code': -1, 'msg': 'failure!'}
    return res
Exemple #12
0
async def push(tag):
    cfg = await get_datax_sync_config(tag)
    if cfg['code'] != 200:
        return cfg

    ssh = ssh_helper(cfg)
    ftp = ftp_helper(cfg)

    res = await transfer_datax_remote_file_sync(cfg, ssh, ftp)
    if res['code'] != 200:
        raise Exception('transfer_datax_remote_file_sync error!')

    res = await run_datax_remote_cmd_sync(cfg, ssh)
    if res['code'] != 200:
        raise Exception('run_datax_remote_cmd_sync error!')

    res = await write_datax_remote_crontab_sync(cfg, ssh)
    if res['code'] != 200:
        raise Exception('write_datax_remote_crontab_sync error!')

    ssh.close()
    ftp.close()
    return res
Exemple #13
0
async def push(tag):
    cfg = await get_db_archive_config(tag)
    if cfg['code'] != 200:
        return cfg

    ssh = ssh_helper(cfg)
    ftp = ftp_helper(cfg)

    res = await transfer_remote_file_archive(cfg, ssh, ftp)
    if res['code'] != 200:
        raise Exception('transfer_remote_file error!')

    res = await run_remote_cmd_archive(cfg, ssh)
    if res['code'] != 200:
        print(res['msg'])
        raise Exception('run_remote_cmd error!')

    res = await write_remote_crontab_archive(cfg, ssh)
    if res['code'] != 200:
        raise Exception('write_remote_crontab error!')

    ssh.close()
    ftp.close()
    return res
Exemple #14
0
async def transfer_remote_file_inst(v_inst_id):
    cfg = await get_db_inst_config(v_inst_id)
    if cfg['code'] != 200:
        return cfg

    ssh = ssh_helper(cfg)
    ftp = ftp_helper(cfg)
    cmd = 'mkdir -p {0}'.format(cfg['msg']['script_path'])
    res = ssh.exec(cmd)
    if not res['status']:
        return {'code': -1, 'msg': 'failure!'}

    f_local, f_remote = gen_transfer_file(cfg, 'instance',
                                          cfg['msg']['script_file'])
    if not ftp.transfer(f_local, f_remote):
        return {'code': -1, 'msg': 'failure!'}

    f_local, f_remote = gen_transfer_file(cfg, 'instance', 'db_creator.sh')
    if not ftp.transfer(f_local, f_remote):
        return {'code': -1, 'msg': 'failure!'}

    ssh.close()
    ftp.close()
    return {'code': 200, 'msg': 'success!'}