SHELL指令碼控制服務啟動

來源:互聯網
上載者:User

/*========================= startacct.sh =========================*/

#!/usr/bin/ksh./vbsvr_boot_boss.sh -s ./boss_server.lst > vbsvr_boot_boss.log &

/*===================== vbsvr_boot_boss.sh =====================*/

#!/usr/bin/kshUSER_NAME=`whoami`PROGRAM_NAME=`basename $0`CHECK_INTERVAL=15SERVER_LIST=SHUTDOWN_ALL_ON_EXIT=falseSERVER_RETRY_NUM=4SERVER_START_INTERVAL=3SERVER_SHUTDOWN_INTERVAL=1DEBUG_LEVEL=0INFO_LEVEL=1ERROR_LEVEL=2SYSTEM_LEVEL=3LOG_LEVEL=$INFO_LEVELCHECK_OSAGENT=0DRY_RUN=0TOTAL_SERVER_NUM=0PROCESSED_SERVER_NUM=0#export LD_LIBRARY_PATH=/yzapp/opcrm/lib_rollback:$LD_LIBRARY_PATH# parameters: messagelog_debugMsg(){        if [ "$LOG_LEVEL" -le "$DEBUG_LEVEL" ]        then                echo "[ debug:" `date '+%y-%m-%d %H:%M:%S'` "] $1"        fi}log_infoMsg(){        if [ "$LOG_LEVEL" -le "$INFO_LEVEL" ]        then                echo "[  info:" `date '+%y-%m-%d %H:%M:%S'` "] $1"        fi}log_errorMsg(){        if [ "$LOG_LEVEL" -le "$ERROR_LEVEL" ]        then                echo "[ error:" `date '+%y-%m-%d %H:%M:%S'` "] $1"        fi}log_sysMsg(){        if [ "$LOG_LEVEL" -le "$SYSTEM_LEVEL" ]        then                echo "[system:" `date '+%y-%m-%d %H:%M:%S'` "] $1"        fi}# parameters: server_name, instance_num, server_parameterscheck_format(){        if [ ! -s $1 ]        then                log_errorMsg "server $1 not found, in server list file $SERVER_LIST"                exit 1        fi        TMP=`expr $2 + 1 - 1 2>/dev/null`        if [ "$TMP" != "$2" ]        then                log_errorMsg "invalid instance_num($2), need a integer, in server list file $SERVER_LIST"                exit 1        fi}# parameters: server_name, instance_num, server_parameterscheck_server(){        _SERVER_NAME=`basename $1`        log_debugMsg "checking for server: $_SERVER_NAME [instance_num=$2, param=\"$3\"]"        _INST_NUM=0        _TRY_NUM=0        while [ "$_TRY_NUM" -lt "$SERVER_RETRY_NUM" ]        do                if [ "$DRY_RUN" -eq "0" ]                then                        _INST_NUM=`ps -fu $USER_NAME | grep "/$_SERVER_NAME" | grep -v grep | wc -l | xargs expr 0 +`                else                        _INST_NUM=$2                fi#echo "server $_SERVER_NAME require $2 try $_TRY_NUM current $_INST_NUM"                if [ "$_INST_NUM" -lt "$2" ]                then                        log_debugMsg "Starting server: $1 $3"                        _LOG_FILE_BASE="$OB_REL/log/$_SERVER_NAME."`date +%H%M%S`                        _COMMAND_LINE="$1 $3 1>/dev/null 2>/dev/null &"                        #_COMMAND_LINE="$1 $3 1>$_LOG_FILE_BASE.stdout 2>$_LOG_FILE_BASE.stderr &"                        log_infoMsg "Starting server with command line -- $_COMMAND_LINE"                        eval $_COMMAND_LINE                        sleep $SERVER_START_INTERVAL                else                        log_infoMsg "server $1 is OK, $_INST_NUM instance(s)"                        PROCESSED_SERVER_NUM=`expr $PROCESSED_SERVER_NUM + $_INST_NUM`                        export PROCESSED_SERVER_NUM                        return                fi                _TRY_NUM=`expr $_TRY_NUM + 1`        done        log_errorMsg "server $1 failed $_TRY_NUM times, will start it later"        PROCESSED_SERVER_NUM=`expr $PROCESSED_SERVER_NUM + $_INST_NUM`        export PROCESSED_SERVER_NUM}# parameters: server_nameshutdown_server(){        _SERVER_NAME=`basename $1`echo "shutdown _SERVER_NAME : $_SERVER_NAME"        log_infoMsg "shutdowning server: $_SERVER_NAME"        _TRY_NUM=0        _INST_NUM=0        while [ "$_TRY_NUM" -lt "$SERVER_RETRY_NUM" ]        do                _INST_NUM=`ps -fu $USER_NAME | grep "/$_SERVER_NAME" | grep -v grep | wc -l | xargs expr 0 +`echo "shutdown _INST_NUM=$_INST_NUM _TRY_NUM=$_TRY_NUM"                if [ "$_INST_NUM" -ge "1" ]                then                        if [ "$DRY_RUN" -eq "0" ]                        then                                ps -fu $USER_NAME | grep "/$_SERVER_NAME" | grep -v grep | awk '{ printf "kill %s\n", $2 }' | sh                        else                                _INST_NUM=0                        fi                        sleep $SERVER_SHUTDOWN_INTERVAL                fi                _TRY_NUM=`expr $_TRY_NUM + 1`        doneecho "shutdown while done INST_NUM=$INST_NUM _TRY_NUM=$_TRY_NUM"        if [ "$_INST_NUM" -ge "1" ]        then                log_errorMsg "shutdown server failed: $_SERVER_NAME, $_INST_NUM left alive"                PROCESSED_SERVER_NUM=`expr $PROCESSED_SERVER_NUM + $_INST_NUM`                export PROCESSED_SERVER_NUM        else                log_infoMsg "server shutdowned: $_SERVER_NAME"        fi        }# parameters: commandprocess_server(){         _TOTAL_SERVER_NUM=0         #20090718 修改,新增參數_MAX_CONNETION_NUM用於讀取最大串連數的配置        while read _APPLICATION _INSTANCE_NUM _PORT_START _PORT_RANGE _MAX_CONNETION_NUM        do                _IS_COMMENT=`expr $_APPLICATION : '#\(.*\)'`                if [ "$_IS_COMMENT" != "" ]                then                        continue                fi                if [ "$_INSTANCE_NUM" = "" ]                then                        _INSTANCE_NUM=1                fi                _TOTAL_SERVER_NUM=`expr $_TOTAL_SERVER_NUM + $_INSTANCE_NUM 2>/dev/null`                _SERVER_NAME="${OB_REL}/svr/${_APPLICATION}_svr"                #20090718 修改,改為讀取公用配置模式                                _PARAMETER="-m $_APPLICATION -i ${OB_REL}/config/acct_config_2.cfg"                                if [ "$_MAX_CONNETION_NUM" = "2" ]                then                        _PARAMETER="-m $_APPLICATION -i ${OB_REL}/config/acct_config_2.cfg"                fi                                if [ "$_MAX_CONNETION_NUM" = "10" ]                then                        _PARAMETER="-m $_APPLICATION -i ${OB_REL}/config/acct_config_10.cfg"                fi                                if [ "$_MAX_CONNETION_NUM" = "20" ]                then                        _PARAMETER="-m $_APPLICATION -i ${OB_REL}/config/acct_config_20.cfg"                fi                                if [ "$_MAX_CONNETION_NUM" = "30" ]                then                        _PARAMETER="-m $_APPLICATION -i ${OB_REL}/config/acct_config_30.cfg"                fi                                if [ "$_MAX_CONNETION_NUM" = "0" ]                then                        _PARAMETER="-m $_APPLICATION -i ${OB_REL}/config/acct_config_30_DQ.cfg"                fi                      #增加boss動態服務載入                if [ "$_MAX_CONNETION_NUM" = "acct" ]                then                        _PARAMETER="-m Dysvr_acct -i ${OB_REL}/config/acct_dysvr.cfg"                fi                                export VBPORT=$_PORT_START                export VBRANGE=$_PORT_RANGE                export OB_ORB_INIT="dummy -Dvbroker.orb.propStorage=${OB_REL}/config/visibroker.prop -Dvbroker.se.iiop_tp.scm.iiop_tp.listener.port=${VBPORT} -Dvbroker.se.iiop_tp.scm.iiop_tp.listener.portRange=${VBRANGE}"                if [ $1 = "check" ]                then                        check_server $_SERVER_NAME $_INSTANCE_NUM $_PARAMETER $_APPLICATION                elif [ $1 = "shutdown" ]                then                        shutdown_server $_SERVER_NAME                elif [ $1 = "check_format" ]                then                        check_format $_SERVER_NAME $_INSTANCE_NUM $_PARAMETER                else                        log_errorMsg "invalid option for process_server(): $1"                        exit 1                fi        done < $SERVER_LIST        TOTAL_SERVER_NUM=$_TOTAL_SERVER_NUM}# parameters:on_exit(){        if $SHUTDOWN_ALL_ON_EXIT        then                log_sysMsg "shutdowning all servers..."                PROCESSED_SERVER_NUM=0                process_server "shutdown"                if [ "$PROCESSED_SERVER_NUM" -eq "0" ]                then                        log_sysMsg "all servers shutdowned!"                else                        log_errorMsg "$PROCESSED_SERVER_NUM shutdowning down failed!"                fi        fi        log_sysMsg "$PROGRAM_NAME terminated!"        exit 1}# parameters:show_usage(){        echo "$PROGRAM_NAME is a tool to boot and monitor OpenBroker server for VisiBroker"        echo "Usage: $PROGRAM_NAME [-h] [-d] [-c interval] -s server_list"        echo "  -c interval        check interval for monitoring, default is $CHECK_INTERVAL seconds"        echo "  -s server_list     server_list file contains server information"        echo "                     file format: server_path,instance_num,parameter"        echo "  -d                 shutdown all servers when exit"        echo "  -h                 show this help message"}# parameters:check_env(){        ps -u $USER_NAME -f | grep "\<$PROGRAM_NAME\>" | grep -v grep         INSTANCE_NUM=`ps -u $USER_NAME -f | grep "\<$PROGRAM_NAME\>" | grep -v grep | wc -l | xargs expr 0 +`        if [ "$INSTANCE_NUM" -ge "2" ]        then                log_errorMsg "there's $PROGRAM_NAME running already"                exit 1        fi        if [ "$OB_REL" = "" ]        then                log_errorMsg "environment variable OB_REL not set, exit"                exit 1        else                log_sysMsg "OB_REL=$OB_REL"        fi        if [ ! -d $OB_REL/log ]        then                log_errorMsg "log directory($OB_REL/log) not exists, exit"                exit 1        fi        if [ $CHECK_OSAGENT -eq 1 ]        then                _OSAGENT_NUM=`ps -fu bes | grep osagent | grep $OSAGENT_PORT | grep -v grep | wc -l | xargs expr 0 +`                if [ "$_OSAGENT_NUM" -eq "0" ]                then                        log_errorMsg "there's no osagent running on port $OSAGENT_PORT, exit"                        exit 1                else                        log_sysMsg "$_OSAGENT_NUM osagent(s) running on port $OSAGENT_PORT"                fi        fi        _TMP=`expr $CHECK_INTERVAL + 1 - 1 2>/dev/null`        if [ "$_TMP" != "$CHECK_INTERVAL" ]        then                log_errorMsg "invalid check interval($CHECK_INTERVAL), need a integer"                exit 1        fi        if [ "$SERVER_LIST" = "" ]        then                log_errorMsg "no server_list file, use -h to get help"                exit 1        fi        if [ ! -s $SERVER_LIST ]        then                log_errorMsg "server_list file $SERVER_LIST not found"                exit -2        fi        process_server "check_format"}# main part of scriptwhile getopts :hdc:s: OPTIONdo        case $OPTION in        h)      show_usage                exit 0        ;;        d)      SHUTDOWN_ALL_ON_EXIT=true        ;;        c)      CHECK_INTERVAL=$OPTARG        ;;        s)      SERVER_LIST=$OPTARG        ;;        *)      log_errorMsg "invalid command option: $OPTARG"                log_errorMsg "Use -h to get help"                exit 1        ;;        esacdoneIFS=,check_envmkdir -p $OB_REL/svr/cores#coreadm -p $OB_REL/svr/cores/core.%f.%p#export LD_PRELOAD_32=$OB_REL/lib/libObPreload.sotrap "on_exit" 2 3 15 1>/dev/null 2>/dev/nulllog_sysMsg "monitoring servers..."while truedo        PROCESSED_SERVER_NUM=0        process_server "check"        log_sysMsg "$TOTAL_SERVER_NUM server(s), $PROCESSED_SERVER_NUM active."#20090718 修改 NG已經不需要再使用obtester服務echo "sleep $CHECK_INTERVAL seconds..."        sleep $CHECK_INTERVALdone

/*========================= boss_server.lst =========================*/

#------------------------------------------------------------------------#--通訊連接埠請嚴格按照下面的原則進行分配,各個產品線在內部調整 #------------------------------------------------------------------------#修改,新增連接埠定義#服務配置,連接埠 36001--38999AccAuxMgnt,10,36021,10,0AccBankReg,2,36041,10,2AccCoinMgnt,3,36081,10,20AccCreditMgnt,2,36091,10,10AccDoubBack,2,36111,10,10AccPayFee,6,36181,20,30AccPrtInv,6,36211,10,30AccQryFee,6,36221,10,30AccQryFreeRes,2,36231,10,20AccQuery,2,36241,10,30AccQuickQryFee,3,36261,10,10AccRefund,2,36271,10,10AccTranBil,3,36331,10,2AccUnpay,2,36351,10,10AccVarsMgnt,2,36361,10,20Config,3,36411,10,10DetailQuery,3,36421,10,0OweMgnt,2,36471,10,10ServRefundCheck,2,36491,10,10StopOpenMgnt,2,36511,10,10Dysvr_acct,2,36521,10,acctInfoMgnt,3,36481,10,10AccOtherMgnt,2,36531,10,10

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.