Exemplo n.º 1
0
def stop_nmon(service_name):
    # get connfig based on service_name
    items = sections_map[service_name]

    # init ssh client
    logger.info("connect via ssh:" + items['host'] + "," + items['user'])
    client = SSHClient(items['host'], items['user'], items['password'], 22)

    # stop nmon first
    cmd = r'ps -ef|grep /home/see/workspace/nmon/nmon|grep -v grep|cut -c 9-15|xargs kill -9'
    logger.debug("exec kill nmon cmd:" + cmd)
    client.exec_cmd(cmd)
Exemplo n.º 2
0
def stop(service_name):
    # get connfig based on service_name
    items = sections_map[service_name]

    # init ssh client
    logger.info("connect via ssh:" + items['host'] + "," + items['user'])
    client = SSHClient(items['host'], items['user'], items['password'], 22)

    # run stop.sh
    logger.info("run stop shell...")
    # cmd = r'sh ' + items['deploy_path'] + r'/' + items.get('stop_shell', 'stop.sh')
    cmd1 = 'cd ' + items['deploy_path']
    cmd2 = r'sh ' + items.get('stop_shell', 'stop.sh')
    cmd = cmd1 + " && " + cmd2
    logger.debug("cmd:" + cmd)
    client.exec_cmd(cmd)
Exemplo n.º 3
0
def start(service_name):
    # get connfig based on service_name
    items = sections_map[service_name]

    # init ssh client
    logger.info("connect via ssh:" + items['host'] + "," + items['user'])
    client = SSHClient(items['host'], items['user'], items['password'], 22)

    # run start.sh
    # 这种写法,如果没有取到 start_shell,就会报错
    # cmd = r'sh ' + items['deploy_path'] + r'/' + items['start_shell']

    # 这种写法,如果没有取到 start_shell,会用默认值,不会报错
    # cmd = r'sh ' + items['deploy_path'] + r'/' + items.get('start_shell', 'start.sh')
    # nohup sh startFSDPL_BOOT.sh>./logs/nohup-s0203-r0204-$(date "+%H%M%S").log 2>&1 &
    log_name = items[
        'log_path'] + r'/' + step + sys_date + run_datetime + '.log'
    cmd1 = 'cd ' + items['deploy_path']
    cmd2 = r'nohup sh ' + items.get('start_shell',
                                    'start.sh') + r'>' + log_name + r' 2>&1 &'
    cmd = cmd1 + " && " + cmd2
    logger.debug("cmd:" + cmd)
    client.exec_cmd_nb(cmd)

    # insert exec log into db
    logger.info('insert exec log into db:' + db_url + ',' + db_name)
    cursor = conn.cursor()
    try:
        cursor.execute(sql, [
            batch_no, cmd, items['host'],
            r'tail -f ' + items['deploy_path'] + r'/' + log_name, '',
            datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
            step + lcs_amount + desc
        ])
        conn.commit()
        logger.debug("sql:" + sql)
    except Exception as e:
        conn.rollback()
        logger.error("insert db error")
Exemplo n.º 4
0
def upload_nmon(service_name):
    # get connfig based on service_name
    items = sections_map[service_name]

    # init ssh client
    logger.info("connect via ssh:" + items['host'] + "," + items['user'])
    client = SSHClient(items['host'], items['user'], items['password'], 22)
    client.sftp_put_dir(LOCAL_NMON_DIR, REMOTE_NMON_DIR)

    # change mode
    client.exec_cmd('chmod -R 775 ' + REMOTE_NMON_DIR)
Exemplo n.º 5
0
def restart_nmon(service_name):
    # get config based on service_name
    items = sections_map[service_name]

    # init ssh client
    logger.info("connect via ssh:" + items['host'] + "," + items['user'])
    client = SSHClient(items['host'], items['user'], items['password'], 22)

    # stop nmon first
    cmd = r'ps -ef|grep /home/see/workspace/nmon/nmon|grep -v grep|cut -c 9-15|xargs kill -9'
    logger.debug("exec kill nmon cmd:" + cmd)
    client.exec_cmd(cmd)

    # start nmon
    # e.g.  /home/see/workspace/nmon/nmon -s 3 -c 2400 -F /var/log/ExportData-s0205-r0206-1731.nmon &
    # TODO:判断服务器上是否已经部署了nmon服务,如果没有就通过sftp从本地上传上去
    nmon_file_path = r'/var/log/' + items[
        'host'] + '-' + intf_name + sys_date + RUN_DATETIME + '.nmon'
    cmd = r'/home/see/workspace/nmon/nmon -s 3 -c ' + nmon_cnt + ' -F ' + nmon_file_path + '&'
    logger.debug("start nmon cmd:" + cmd)
    client.exec_cmd_nb(cmd)

    # insert exec log into db
    logger.info('insert exec log into db:' + db_url + ',' + db_name)
    cursor = conn.cursor()
    try:
        cursor.execute(sql, [
            TENANT, BATCH_NO, cmd, items['host'],
            items['deploy_path'] + r'/' + '', nmon_file_path,
            datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), '',
            PKG_VERSION
        ])
        conn.commit()
        logger.debug("sql:" + sql)
    except Exception as e:
        conn.rollback()
        logger.error("insert log into db error")
Exemplo n.º 6
0
def deploy(service_name):
    # get connfig based on service_name
    items = sections_map[service_name]
    local_path = items['local_dir']
    start_shell = items['start_shell']
    # init ssh client
    logger.info("connect via ssh:" + items['host'] + "," + items['user'])
    client = SSHClient(items['host'], items['user'], items['password'], 22)

    # upload local file to remote
    logger.info("STEP:begin to upload jar/war file")
    deploy_path = items['deploy_path'] + r'/springboot/application'
    client.sftp_put_dir(local_path, deploy_path)

    # get the name of jar file
    jar_name = os.path.split(get_all_files_in_local_dir(local_path)[0])[-1]
    logger.info("jar name:" + jar_name)

    # edit the start shell script in remote
    logger.info("STEP:begin to edit boot shell")
    cmd = r'sed -i "s/application\/fintcs-query-service.*\.jar$/application\/' + jar_name + '/g" ' + items[
        'deploy_path'] + r'/springboot/' + start_shell
    logger.debug("cmd:" + cmd)
    client.exec_cmd(cmd)