主頁 > 作業系統 > linux平臺上人機互動專案發布工具

linux平臺上人機互動專案發布工具

2020-09-12 02:44:43 作業系統

1、需求描述

對于上線步驟較為繁瑣且注意的細節很多的專案,盡可能減少人為現場操作命令,讓機器自動化實作上線功能尤為重要,


2、工具概述

    工具啟動后,會提示用戶選擇按系統指引執行(a)或輸入指定指令執行(b

       每一步都會進行簡單的用戶互動(Y/N)后系統自動執行確認后的命令

       工具包含的功能有:執行sql檔案、發布應用程式、啟動(重啟)應用程式


3、工具結構

    專案名稱

       etc/

           sh/

               help.sh

               step.sh

               top.sh

               wrapper.sh

           const.lst

           dbinfo.cfg

           file.cfg

           func.cfg

           step.lst

           step_run.log

       log/

       source/

       tool/

             execSqlFile.sh

       run.sh

   目錄或檔案說明:

   etc/        組態檔存放目錄

   etc/sh    可執行的shell腳本,如help.sh,輸出工具幫助資訊;step.sh,輸出專案部署步驟資訊;top.sh,輸出專案部署標題;wrapper.sh,自定義shell腳本的包裝類,可實作shell腳本執行前后動作,如日志列印

   etc/const.lst    工具常量檔案

   etc/dbinfo.cfg  資料庫連接資訊

   etc/file.cfg       所有檔案或目錄常量檔案

   etc/func.cfg     公共函式

   step.lst           專案部署步驟清單

   step_run.log    步驟執行日志,日志內容包含步驟名稱、執行狀態(0成功 1失敗)、開始時間、結束時間、耗時(秒)

   log/                日志目錄

  source/            資料檔案存放目錄

  tool/                工具腳本存放目錄,如execSqlFile.sh,傳入可執行sql檔案路徑引數,用于 執行sql檔案

  run.sh              工具啟動腳本



4、代碼展示

run.sh

#!/bin/sh

cd `dirname $0`

#加載靜態資源
. ./etc/const.lst
. ./etc/dbinfo.cfg
. ./etc/file.cfg
. ./etc/func.cfg

function init {
    clear
    #列印標題
    ./etc/sh/top.sh
    checkstatus $? "輸出標題"
    #列印操作步驟
    ./etc/sh/step.sh
    checkstatus $? "輸出操作步驟"
}

init

if [ ! -f ${hkbaps_step_log} ]; then
    touch ${hkbaps_step_log}
fi

#加載操作步驟
declare -a array
declare -a code
declare -a cmd
cnt=0
while read line
do
if [[ -n `echo ${line}|grep -v "^\s*$"` ]] && [[ "${line:0:1}" != "#" ]]; then
    let cnt=cnt+1
    code[$cnt]="`lpad ${cnt} 3`"
    array[$cnt]="${code[$cnt]}-`echo ${line}|awk '{print $1}'`"
    cmd[$cnt]="`echo ${line}|awk '{print $2}'`"
fi
done < ${hkbaps_step}

valid=0
match=""
flag=1
index=1
#用戶指令互動

while true
do
read -r -p "您是否選擇按照操作步驟清單指引執行(a)或手工輸入指定任務代碼指令執行(b)?  " inp
case $inp in
    [aA])
while true
do
    if [ ${valid} -eq 0 ]; then
        #判斷最近是否存在未完成的任務
        slog=`cat ${hkbaps_step_log}|grep -v "^\s*$"|tail -n 1`
        if [ -n "${slog}" ]; then
            step=`echo ${slog}|awk '{print $1}'`
            status=`echo ${slog}|awk '{print $2}'`
            if [ "${status}" == "1" ]; then
                match=${step}
                
                for((i=1;i<${#array[*]};i++));
                do   
                    if [ "${array[$i]}" == "${step}" ]; then
                        index=$i
                        flag=0
                        break
                    fi
                done
                
                if [ ${flag} -eq 1 ]; then
                    match=${step}
                fi
            else
                flag=0
            fi
        else
            flag=0    
        fi
    fi
    
    if [ ${flag} -eq 1 ]; then
        read -r -p "檢測到未完成的任務:${match}不存在當前的操作步驟清單中,請輸入指定任務代碼指令或重新執行所有指令?  " input
        case $input in
            [nN][oO]|[nN])
                output "已取消操作"
                exit 1
            ;;
            [uU][nN][dD][oO]|[uU])
                read -r -p "確定要重新執行所有任務?  [Y/N] " input2
                case $input2 in
                    [yY][eE][sS]|[yY])
                        match=""
                        flag=0
                        index=1
                        valid=1
                        echo "" > ${hkbaps_step_log}
                    ;;
                    [nN][oO]|[nN])
                        output "已取消操作"
                        valid=1
                    ;;
                    [cC][lL][eE][aA][rR]|[cC])
                        init
                        valid=1
                    ;;
                    *)
                        valid=1
                        echo -e "不合法的輸入指令${input},請重新輸入!"
                    ;;
                esac
            ;;
            [sS][tT][eE][pP]|[sS])
                ./etc/sh/step.sh
            ;;
            [hH][eE][lL][pP]|[hH])
                ./etc/sh/help.sh
            ;;
            *)
                exists=0
                for((i=1;i<${#code[*]};i++));
                do   
                    tmp=`upper ${input}`
                    if [ "${tmp}" == "${code[${i}]}" ]; then
                        index=${i}
                        exists=1
                        break
                    fi
                done
                if [ ${exists} -eq 1 ]; then
                    ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]}
                    valid=0
                    match=""
                    flag=0
                    let index=index+1
                else
                    valid=1
                echo -e "不合法的輸入指令${input},請重新輸入!"
                fi
            ;;
        esac
    else
        if [[ -n ${match} ]] && [[ ${index} -gt 1 ]]; then
            read -r -p "檢測到未完成的任務:${match},是否直接執行?  [Y/N] " input
            case $input in
                [yY][eE][sS]|[yY])
                    ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]}
                    valid=0
                    let index=index+1
                    match=""
                ;;
                [nN][oO]|[nN])
                    output "已取消操作"
                    exit 1
                ;;
                [uU][nN][dD][oO]|[uU])
                    read -r -p "確定要重新執行所有任務?  [Y/N] " input2
                    case $input2 in
                        [yY][eE][sS]|[yY])
                            match=""
                            flag=0
                            index=1
                            valid=1
                            echo "" > ${hkbaps_step_log}
                        ;;
                        [nN][oO]|[nN])
                            valid=1
                            output "已取消操作"
                        ;;
                        *)
                            valid=1
                            echo -e "不合法的輸入指令${input},請重新輸入!"
                        ;;
                    esac
                ;;
                [sS][tT][eE][pP]|[sS])
                    valid=1
                    ./etc/sh/step.sh
                ;;
                [hH][eE][lL][pP]|[hH])
                    valid=1
                    ./etc/sh/help.sh
                ;;
                [cC][lL][eE][aA][rR]|[cC])
                    valid=1
                    init
                ;; 
                *)
                    valid=1
                    echo -e "不合法的輸入指令${input},請重新輸入!"
                ;;
            esac
        else
            while [ ${index} -lt ${#array[*]} ];
            do
                msg=${array[${index}]}
                slog=`cat ${hkbaps_step_log}|grep ${msg}|grep -v "^\s*$"|tail -n 1`
                if [ -n "${slog}" ]; then
                    status=`echo ${slog}|awk '{print $2}'`
                    if [ "${status}" == "0" ]; then
                        read -r -p "步驟:${msg}已成功執行過,確認是否可以跳過該步驟? [Y/N] " input
                        case $input in
                            [yY][eE][sS]|[yY])
                                let index=index+1
                            ;;
                            [nN][oO]|[nN])
                                break
                            ;;
                            [uU][nN][dD][oO]|[uU])
                                read -r -p "確定要重新執行所有任務?  [Y/N] " input2
                                case $input2 in
                                    [yY][eE][sS]|[yY])
                                        match=""
                                        flag=0
                                        index=1
                                        valid=1
                                        echo "" > ${hkbaps_step_log}
                                    ;;
                                    [nN][oO]|[nN])
                                        output "已取消操作"
                                        valid=1
                                    ;;
                                    *)
                                        valid=1
                                        echo -e "不合法的輸入指令${input},請重新輸入!"
                                    ;;
                                esac
                            ;;
                            [sS][tT][eE][pP]|[sS])
                                valid=1
                                ./etc/sh/step.sh
                            ;;
                            [hH][eE][lL][pP]|[hH])
                                valid=1
                                ./etc/sh/help.sh
                            ;;
                            [cC][lL][eE][aA][rR]|[cC])
                                valid=1
                                init
                            ;; 
                            *)
                                valid=1
                                echo -e "不合法的輸入指令${input},請重新輸入!"
                            ;;
                        esac
                    fi
                else
                    break
                fi
            done
            
            let t=index-1
            if [[ ${t} -gt 0 ]] && [[ ${index} -lt ${#array[*]} ]]; then
                msg=${array[${t}]}
                read -r -p "步驟:${msg}已執行完畢,確認是否可以執行下一步驟:${array[${index}]}? [Y/N] " input
                case $input in
                    [yY][eE][sS]|[yY])
                    ;;
                    [nN][oO]|[nN])
                        output "已取消操作"
                        exit 1
                    ;;
                    [uU][nN][dD][oO]|[uU])
                        read -r -p "確定要重新執行所有任務?  [Y/N] " input2
                        case $input2 in
                            [yY][eE][sS]|[yY])
                                match=""
                                flag=0
                                index=1
                                valid=1
                                echo "" > ${hkbaps_step_log}
                            ;;
                            [nN][oO]|[nN])
                                output "已取消操作"
                                valid=1
                            ;;
                            *)
                                valid=1
                                echo -e "不合法的輸入指令${input},請重新輸入!"
                            ;;
                        esac
                    ;;
                    [sS][tT][eE][pP]|[sS])
                        valid=1
                        ./etc/sh/step.sh
                    ;;
                    [hH][eE][lL][pP]|[hH])
                        valid=1
                        ./etc/sh/help.sh
                    ;;
                    [cC][lL][eE][aA][rR]|[cC])
                        valid=1
                        init
                    ;; 
                    *)
                        valid=1
                        echo -e "不合法的輸入指令${input},請重新輸入!"
                    ;;
                esac
            fi
            if [ ${index} -lt ${#array[*]} ]; then
                if [ ${index} -eq 1 ]; then
                    msg=${array[${t}]}
                    read -r -p "步驟:${array[${index}]},確認是否開始執行? [Y/N] " input
                    case $input in
                        [yY][eE][sS]|[yY])
                        ;;
                        [nN][oO]|[nN])
                            output "已取消操作"
                            exit 1
                        ;;
                        [sS][tT][eE][pP]|[sS])
                            valid=2
                            ./etc/sh/step.sh
                        ;;
                        [hH][eE][lL][pP]|[hH])
                            valid=2
                            ./etc/sh/help.sh
                        ;;
                        [cC][lL][eE][aA][rR]|[cC])
                            valid=2
                            init
                        ;; 
                        *)
                            valid=2
                            echo -e "不合法的輸入指令${input},請重新輸入!"
                        ;;
                    esac
                fi
                if [ ${valid} -ne 2 ]; then
                    ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]}
                    valid=0
                    let index=index+1
                    match=""
                fi
            else
                output "任務執行完畢!"
                exit 1
            fi
        fi
    fi

done
        
    ;;
    [bB])
    while true
    do
        read -r -p "請輸入步驟指令代碼: " input
        case $input in
            [nN][oO]|[nN])
                output "已取消操作"
                exit 1
            ;;
            [sS][tT][eE][pP]|[sS])
                ./etc/sh/step.sh
            ;;
            [hH][eE][lL][pP]|[hH])
                ./etc/sh/help.sh
            ;;
            [cC][lL][eE][aA][rR]|[cC])
                init
            ;; 
            *)
                exists=0
                for((i=1;i<${#code[*]};i++));
                do   
                    tmp=`upper ${input}`
                    if [ "${tmp}" == "${code[${i}]}" ]; then
                        index=${i}
                        exists=1
                        break
                    fi
                done
                if [ ${exists} -eq 1 ]; then
                    ${hkbaps_step_wrapper} ${array[${index}]} ${cmd[${index}]}
                else
                    echo -e "不合法的輸入指令${input},請重新輸入!"
                fi
            ;;
        esac
    done
    ;;
    [nN][oO]|[nN])
        output "已取消操作"
        exit 1
    ;;
    [sS][tT][eE][pP]|[sS])
        ./etc/sh/step.sh
    ;;
    [hH][eE][lL][pP]|[hH])
        ./etc/sh/help.sh
    ;;
    [cC][lL][eE][aA][rR]|[cC])
        init
    ;; 
    *)
        echo -e "不合法的輸入指令${input},請重新輸入!"
    ;;
esac

done


etc/const.lst

sys_name=XXX系統
sys_code=XXX
sys_task=上線操作
sys_author=XXX
sys_user=XXX
sys_skin=[44\;37
LANG="zh_CN.GBK"
NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"


etc/dbinfo.cfg

db_dump_username=XXX
db_dump_uo_username=XXX

db_username=XXX
db_password=XXX
db_instance=XXX
db_link=${db_username}/${db_password}@${db_instance}


etc/file.cfg

#步驟清單
step=etc/step.lst

#步驟執行日志
step_log=etc/step_run.log

#步驟執行包裝器
step_wrapper=./etc/sh/wrapper.sh

#資料庫資訊檢查陳述句
db_check_sql=source/env_db.sql

#資料庫資訊檢查腳本
db_check=./etc/sh/env_db.sh

#校驗01
check_01=source/check_01.sql
#校驗02
check_02=source/check_02.sql
#校驗03
check_03=source/check_03.sql


etc/func.cfg

#!/bin/sh

#日志檔案
export logfile=log/`date +%Y%m%d`.log

#info級別控制臺日志
function output {
    msg=$1
    skin=$2
    if [ -f "${msg}" ]; then
        echo `date` >> ${logfile}
        cat ${msg} >> ${logfile}
        cat ${msg}
    else
        if [ -n "${skin}" ]; then
            echo -e "\033${skin}${msg}\033[0m"
           else
               echo -e ${msg}
        fi
        echo -e "`date` ${msg}" >> ${logfile}
    fi
}

function title {
    msg=$1
    skin=$2
    if [ -n "${skin}" ]; then
        echo -e "\n\033${skin}\;1m${msg}\033[0m\n"
       else
           echo -e "\n\033[1m${msg}\033[0m\n"
    fi
    echo -e "`date` \n${msg}\n" >> ${logfile}
}

function success {
    msg=$1
    if [ ! -n "${msg}" ]; then
        msg=執行成功
    fi
    output ${msg}
}

function error {
    msg=$1
    if [ ! -n "${msg}" ]; then
        msg=執行失敗
    fi
    output ${msg}
    exit 1
}

function checkstatus {
    code=$1
    msg=$2
    if [ ${code} -ne 0 ]; then
         output ${msg}例外:${code}
         exit 1
    fi
}


function printchar {
    n=$1
    c=$2
    s=""
    if [ ! -n "${n}" ]; then
        n=20
    fi
    if [ ! -n "${c}" ]; then
        c="_"
    fi
    for((i=1;i<=${n};i++));
    do   
        s="${s}${c}"
    done
    echo -e ${s}
}

function seperate {
    echo ""
    echo `printchar "-" 300`
    echo ""
}

function lpad {
    char=$1
    len=$2
    fill=$3
    if [ -n "${char}" ]; then
        if [ ! -n "${len}" ]; then
            len=8
        fi
        if [ ! -n "${fill}" ]; then
            fill="0"
        fi
        
        size=${#char}
        let m=len-size
        s=""
        for((i=1;i<=${m};i++));
        do   
            s="${s}${fill}"
        done
        echo ${s}${char}
    fi
}

function lower {
    msg=$1
    if [ -n "${msg}" ]; then
        if [ -f "${msg}" ]; then
            cat ${msg}|tr A-Z a-z
        else
            echo ${msg}|tr A-Z a-z
        fi
    fi
}

function upper {
    msg=$1
    if [ -n "${msg}" ]; then
        if [ -f "${msg}" ]; then
            cat ${msg}|tr a-z A-Z
        else
            echo ${msg}|tr a-z A-Z
        fi
    fi
}

#日志檔案錯誤資訊檢查
function checklog {
    reg=$1
    log=$2
    msg=""
    if [ ! -f "${log}" ]; then
        log=${logfile}
        msg=`cat ${log}|grep -i ${reg}`
    else
        msg=`cat ${logfile}|grep -i ${reg}`
    fi
    
    if [ ${#msg} -gt 0 ]; then
        echo "日志檔案${log},發現報錯資訊:${msg}"
        exit 1
    fi
}

function execSqlFile {
    dbconn=$1
    dbfile=$2
    err=$3
    if [ ! -n "${dbconn}" ]; then
        error "資料庫連接資訊缺失,請檢查"
    fi
    
    if [ ! -f "${dbfile}" ]; then
        error "sql檔案${dbfile}不存在,請檢查"
    fi
    
    if [ ! -n "${err}" ]; then
        err=ORA-
    fi
    
    read -r -p "即將在資料庫環境${dbconn}中執行sql檔案${dbfile}? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
sqlplus -S /nolog<<EOF

conn ${dbconn}
spool ${logfile} append
@${dbfile}
spool off
quit

EOF

    checklog ${err}
            ;;
    
        [nN][oO]|[nN])
            echo "已取消操作"
               ;;
    
        *)
            echo "Invalid input..."
            exit 1
            ;;
    esac
}

function execDSqlFile {
    dbconn=$1
    dbfile=$2
    err=$3
    if [ ! -n "${dbconn}" ]; then
        error "資料庫連接資訊缺失,請檢查"
    fi
    
    if [ ! -f "${dbfile}" ]; then
        error "sql檔案${dbfile}不存在,請檢查"
    fi
    
    if [ ! -n "${err}" ]; then
        err=ORA-
    fi
    
sqlplus -S /nolog<<EOF

conn ${dbconn}
spool ${logfile} append
@${dbfile}
spool off
quit

EOF
    
}

function executeSql(){
    dbconn=$1
    sql=$2
    err=$3
    if [ ! -n "${dbconn}" ]; then
        error "資料庫連接資訊缺失,請檢查"
    fi
    
    if [ ! -n "${sql}" ]; then
        error "sql腳本${sql}缺失,請檢查"
    fi
    
    if [ -f "${sql}" ]; then
        sql=`cat ${sql}`
    fi
    
    lst=${sql: -1}
    if [ "${lst}" != ";" ]; then
        sql="${sql};"
    fi
    
    if [ ! -n "${err}" ]; then
        err=ORA-
    fi
    
    read -r -p "即將在資料庫環境${dbconn}中執行sql陳述句:${sql}? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
sqlplus -S /nolog<<EOF

conn ${dbconn}
spool ${logfile} append
${sql}
spool off
quit

EOF

    checklog ${err}
            ;;
    
        [nN][oO]|[nN])
            echo "已取消操作"
               ;;
    
        *)
            echo "Invalid input..."
            exit 1
            ;;
    esac
}

function querySingle(){
    dbconn=$1
    sql=$2
    err=$3
    if [ ! -n "${dbconn}" ]; then
        error "資料庫連接資訊缺失,請檢查"
    fi
    
    if [ ! -n "${sql}" ]; then
        error "sql腳本${sql}缺失,請檢查"
    fi
    
    if [ -f "${sql}" ]; then
        sql=`cat ${sql}`
    fi
    
    lst=${sql: -1}
    if [ "${lst}" != ";" ]; then
        sql=${sql};
    fi 
    
    if [ ! -n "${err}" ]; then
        err=ORA-
    fi
    read -r -p "即將在資料庫環境${dbconn}中執行sql陳述句:${sql}? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
result=`sqlplus -S /nolog<<EOF

set heading off feedback off pagesize 0 verify off echo off
conn ${dbconn}
spool ${logfile} append
${sql}
spool off
quit

EOF`

    checklog ${err}
    echo ${result}
            ;;
    
        [nN][oO]|[nN])
            echo "已取消操作"
               ;;
    
        *)
            echo "Invalid input..."
            exit 1
            ;;
    esac

}

function impDump(){
    dbconn=$1
    file=$2
    fromuser=$3
    touser=$4
    err=$5
    if [ ! -n "${dbconn}" ]; then
        error "資料庫連接資訊缺失,請檢查"
    fi
    
    if [ ! -f "${file}" ]; then
        error "匯入的dump檔案${file}缺失,請檢查"
    fi
    
    if [ ! -n "${fromuser}" ]; then
        error "匯入時資料庫來源用戶缺失,請檢查"
    fi
    
    if [ ! -n "${touser}" ]; then
        error "匯入時資料庫目標用戶缺失,請檢查"
    fi
    
    if [ ! -n "${err}" ]; then
        err=ORA-
    fi
    read -r -p "即將在資料庫環境${dbconn}中執行dump匯入,匯入檔案:${file},來源用戶:${fromuser},目標用戶:${touser}? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
        tmp="${logfile}.imp.`date +%H%M%S`"
        imp ${dbconn} file=${file} log=${tmp} STATISTICS=NONE data_only=y fromuser=${fromuser} touser=${touser}
        checklog ${err} ${tmp}
            ;;
    
        [nN][oO]|[nN])
            echo "已取消操作"
               ;;
    
        *)
            echo "Invalid input..."
            exit 1
            ;;
    esac
}

function exportDump(){
    dbconn=$1
    file=$2
    lst=$3
    err=$4
    if [ ! -n "${dbconn}" ]; then
        error "資料庫連接資訊缺失,請檢查"
    fi
    
    if [ ! -n "${file}" ]; then
        error "匯出dump檔案名缺失,請檢查"
    fi
    
    if [ ! -f "${lst}" ]; then
        error "匯出的表清單檔案${lst}不存在,請檢查"
    fi
    
    if [ ! -n "${err}" ]; then
        err=ORA-
    fi
    
    read -r -p "即將在資料庫環境${dbconn}中執行dump匯出,匯出檔案:${file},匯出表清單:`cat ${lst}`? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
        tabs=""
        while read line
        do
        tabs="${tabs},`echo ${line}|awk '{print $1}'`"
        done < ${lst}
        
        if [ -n "${tabs}" ]; then
            tabs=${tabs:1}
            tmp="${logfile}.exp.`date +%H%M%S`"
            exp ${dbconn} file=${file} log=${tmp} tables=${tabs}
            checklog ${err} ${tmp} 
        fi
            ;;
    
        [nN][oO]|[nN])
            echo "已取消操作"
               ;;
    
        *)
            echo "Invalid input..."
            exit 1
            ;;
    esac    
}


etc/step.lst

環境資訊檢查            ./etc/sh/env.sh
應用程式啟動(或重啟)    ./etc/sh/app_startup.sh


etc/sh/help.sh

#!/bin/sh

#幫助指南
cd `dirname $0`
cd ../../

. ./etc/const.lst
. ./etc/file.cfg
. ./etc/func.cfg

output 幫助指南 "${sys_skin};1m"
output ""

output "a:按照操作步驟指引執行"
output "b:選擇手工輸入指令執行"
output "c:清空控制臺"
output "h:查看幫助指南"
output "n:取消當前操作"
output "s:查看操作步驟"
output "u:重新執行(注:適合選擇操作指引的方式)"
output "y:確認當前系統提示"

output ""


etc/sh/top.sh

#!/bin/sh

#輸出控制臺頂部資訊
cd `dirname $0`
cd ../../

. ./etc/const.lst
. ./etc/file.cfg
. ./etc/func.cfg

header=`printchar 30`
header="${header}${sys_name}(${sys_code}) - ${sys_task}${header}"
echo -e "\033${sys_skin};1m ${header}\033[0m\033${sys_skin};4m 操作人:${sys_author}\033[0m"
echo ""


etc/sh/step.sh

#!/bin/sh

#輸出執行步驟資訊
cd `dirname $0`
cd ../../

. ./etc/const.lst
. ./etc/file.cfg
. ./etc/func.cfg

output 執行步驟 "${sys_skin};1m"

cnt=0
while read line
do
if [ -n "${line}" ] && [[ "${line:0:1}" != "#" ]]; then
    let cnt=cnt+1
    output ${cnt}、`lpad ${cnt} 3`-`echo ${line}|awk '{print $1}'`
fi
done < ${hkbaps_step}

output "\n"


etc/sh/wrapper.sh

#!/bin/sh

#步驟執行包裝器
cd `dirname $0`
cd ../../

. ./etc/const.lst
. ./etc/file.cfg
. ./etc/func.cfg

step=$1
cmd=$2

if [ ! -n ${step} ]; then
    error "包裝器中執行步驟不能為空,請檢查!"
elif [ ! -n ${cmd} ]; then
    error "執行步驟:${step}未配置對應執行腳本,請檢查"
else
    output ""
    output ${step} "${sys_skin};1m"
    output ""
    bdate=`date +%Y%m%d%H%M%S`
    sh ${cmd}
    tmp=$?
    output ""
    edate=`date +%Y%m%d%H%M%S`
    cost=$(( edate-bdate ))
    result=""
    if [[ ${tmp} -ne 0 ]] || [[ ${msg} -ne 0 ]]; then
         result="${step}\t1\t${bdate}\t${edate}\t${cost}(秒)"
     else
       result="${step}\t0\t${bdate}\t${edate}\t${cost}(秒)"
    fi
    echo -e ${result} >> ${hkbaps_step_log}
    
fi


etc/sh/env_db.sh

#!/bin/sh

#資料庫資訊檢查
cd `dirname $0`
cd ../../

. ./etc/const.lst
. ./etc/dbinfo.cfg
. ./etc/file.cfg
. ./etc/func.cfg

execDSqlFile ${db_link} ${hkbaps_db_check_sql}


etc/sh/app_startup.sh

#!/bin/sh

#應用程式啟動(或重啟)
cd `dirname $0`
cd ../../

. ./etc/const.lst
. ./etc/file.cfg
. ./etc/func.cfg

export LANG=en_US.UTF-8
echo "LANG:$LANG"

u=`whoami`

if [ "${u}" != "${sys_user}" ]; then
    output "當前登錄用戶${u}與要求的用戶${sys_user}不符"
    read -r -p "當前登錄用戶${u}與要求的用戶${sys_user}不符,確認是否用該用戶啟動(重啟)應用? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
        ;;
        [nN][oO]|[nN])
            output "已取消操作"
            exit 1
        ;;
        *)
            echo -e "不合法的輸入指令${input},請重新輸入!"
        ;;
    esac
fi

#停服務

#停止web應用服務
web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep`
if [ -n "${web_log}" ]; then
    sh ${app_web}/bin/shutdown.sh
fi

cnt=0
while [ ${cnt} -lt 3 ]
do
    web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep`
    if [ -n "${web_log}" ]; then
        let cnt=cnt+1
        sleep 2
    else
        break
    fi
done

web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep`
if [ -n "${web_log}" ]; then
    output ${web_log}
    progress=`echo ${web_log}|awk '{print $2}'`
    read -r -p "web應用停止服務耗時太久,是否強制停止行程-${progress}? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
            kill -9 ${progress}
        ;;
        [nN][oO]|[nN])
            output "已取消操作"
            exit 1
        ;;
        *)
            echo -e "不合法的輸入指令${input},請重新輸入!"
        ;;
    esac
fi

#停止server應用服務
server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep`
if [ -n "${server_log}" ]; then
    sh ${app_server}/bin/shutdown.sh
fi

cnt=0
while [ ${cnt} -lt 3 ]
do
    server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep`
    if [ -n "${server_log}" ]; then
        let cnt=cnt+1
        sleep 2
    else
        break
    fi
done

server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep`
if [ -n "${server_log}" ]; then
    output ${server_log}
    progress=`echo ${server_log}|awk '{print $2}'`
    read -r -p "server應用停止服務耗時太久,是否強制停止行程-${progress}? [Y/N] " input
    case $input in
        [yY][eE][sS]|[yY])
            kill -9 ${progress}
        ;;
        [nN][oO]|[nN])
            output "已取消操作"
            exit 1
        ;;
        *)
            echo -e "不合法的輸入指令${input},請重新輸入!"
        ;;
    esac
fi

#啟服務
sh ${app_server}/bin/startup.sh && sh ${app_web}/bin/startup.sh

cnt=0
while [ ${cnt} -lt 3 ]
do
    server_log=`ps -ef|grep "Dcatalina.home=${app_server}"|grep -v grep`
    if [ -n "${server_log}" ]; then
        progress=`echo ${server_log}|awk '{print $2}'`
        output "server應用服務啟動成功,行程號:${progress}"
        break
    else
        let cnt=cnt+1
        sleep 2
    fi
done

cnt=0
while [ ${cnt} -lt 3 ]
do
    web_log=`ps -ef|grep "Dcatalina.home=${app_web}"|grep -v grep`
    if [ -n "${web_log}" ]; then
        progress=`echo ${web_log}|awk '{print $2}'`
        output "web應用服務啟動成功,行程號:${progress}"
        break
    else
        let cnt=cnt+1
        sleep 2
    fi
done

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/9756.html

標籤:Linux

上一篇:關于linux下ET非阻塞模式正確關閉連接的問題

下一篇:求教vi批量替換問題

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more