`
pouyang
  • 浏览: 313897 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

有关linux启动脚本的浅析

 
阅读更多

 

 

有关linux启动脚本的浅析: 

 

1、参数脚本。

      #应用id,应用的唯一标识。

        APP_NAME=APP_01  

        APP_DIR=../

        APP_BIN=${APP_DIR}/bin

        APP_LIB=${APP_DIR}/lib

        APP_LOG=${APP_DIR}/log

        APP_SCRIPT=${APP_DIR}/script

 

2、路径脚本。

        . para

       CLASSPATH=

       CLASSPATH=$CLASSPATH:${APP_BIN}

       for jarfile in `ls -1 ../lib/*.jar`

       do

           CLASSPATH="$CLASSPATH:$jarfile"

       done

       #export CLASSPATH

 

3、启动脚本。

        #! /bin/bash

        clear

        . para

        . class_path

        #编码方式

        export LANG=zh_CN.GB18030

        echo $LANG

        cd ${APP_BIN}

        echo "${APP_NAME} starting ..."

        sleep 1

        nohup java -Xms256m -Xmx512m -Xss256k -Dflag=${PLATFORM2_NAME} -XX:PermSize=128m -XX:MaxPermSize=256m -Djava.security.policy="policy.txt" -Djava.rmi.server.codebase=file://${PLATFORM2_BIN}/ -cp ${CLASSPATH} com.umpay.app.Start >${APP_LOG}/console.out &

        cd ${APP_SCRIPT}

        #sleep 1

        tail -50f ${APP_LOG}/console.out

 

4、停止脚本。

        4.1)、方式一

        #! /bin/bash

        sleep 1

        ps -ef|grep Dflag=${APP_NAME}|grep -v grep|grep -v tail|awk 'BEGIN{printf "kill "}{printf "%s ", $2}'|bash

        echo "${APP_NAME} stopped!

 

        4.2)、方式二

        #! /bin/bash

        . para

        c=0

        while [ $c -eq 0 ]

        do

         echo "do" 

          result=`ps -ef|grep "Dflag=${APP_NAME}"|grep -v grep`

          if [ -n "${result}" ]

                then

                 echo $result

                 ps -ef|grep Dflag=${APP_NAME}|grep -v grep|grep -v tail|awk 'BEGIN{printf "kill "}{printf "%s ", $2}'|bash

                 result=`ps -ef|grep "Dflag=${APP_NAME}"|grep -v grep`

                 sleep 2

                else

                 c=1

                 echo "else"

         fi

        done 

        echo "结束"

 

 

4.3)、方式三
#! /bin/bash
. para
c=0
while [ $c -eq 0 ]
do
 echo "do" 
  result=`ps -ef|grep "Dflag=${PLATFORM2_NAME}"|grep -v grep`
  if [ -n "${result}" ]
        then
         echo $result
         ps -ef|grep Dflag=${PLATFORM2_NAME}|grep -v grep|grep -v tail|awk 'BEGIN{printf "kill "}{printf("%s", $2)}' | bash
         result=`ps -ef|grep "Dflag=${PLATFORM2_NAME}"|grep -v grep`
         if [ -n "${result}" ]
         then 
          ps -ef|grep Dflag=${PLATFORM2_NAME}|grep -v grep|grep -v tail|awk 'BEGIN{printf "kill -9 "}{printf("%s", $2)}' | bash
         fi
         sleep 2
        else
         c=1
         echo "else"
 fi
done 
echo "结束

 

 

5、重启脚本。

        #! /bin/bash

        ./unserv.sh

        sleep 5

        ./start.sh

 

6、状态脚本。

        . para

        result=`ps -ef|grep "Dflag=${APP_NAME}"|grep -v grep`

        if [ -n "${result}" ]

        then

            echo "${APP_NAME} is running."

        else

            echo "${APP_NAME} not found..."

        fi

 

7、日志脚本。

        #! /bin/bash

        clear

        . para

        sleep 1

        tail -30f ${APP_NAME}/console.out

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics