Linux上java程序的jar包启动通用脚本(稳定用过)

Linux上java程序的jar包启动通用脚本如下:

#! /bin/sh

export LANG="zh_CN.GBK"

SERVICE_NAME=`basename $0 .sh`
SCRIPT_NAME=`basename $0`
EXEC_JAR_NAME=$SVC_PGW_BIN_PATH/job-pbc-bat/job-pbc-bat-test-2.00.00.jar
JAVA_CMD="java  -Djsvc-pgw-name="${SERVICE_NAME}" 
                -Xmx1024m  
        -Xms512m 
        -Xmn128m  
        -XX:MaxPermSize=128m  
        -XX:SurvivorRatio=14  
        -XX:-UseParallelGC  
        -XX:+UseParallelOldGC
                -XX:ParallelGCThreads=8 
                -XX:+DisableExplicitGC
                -Dencoding=gbk
        -classpath ${EXEC_JAR_NAME}:${SVC_PGW_BIN_PATH}/job-eup-wy/config:${SVC_PGW_ENGINE_PATH}/svc-pgw-engine-1.0.jar
        -Djava.ext.dirs="${JAVA_HOME}/jre/lib/ext"
              -Djsvc.pgw.log.path=$SVC_PGW_LOG_PATH 
              cn.com.bestpay.pgw.pbcbat.handler.JobPbcBootStrap"

 

start()
{
      echo starting the $SERVICE_NAME service......
      SERVICE_PID=`ps -ef | grep java | grep $SERVICE_NAME | awk '{print $2}'`
      if [ ! $SERVICE_PID ]; then
    $JAVA_CMD &
         echo $SERVICE_NAME started!
      else
         echo $SERVICE_NAME had been started
      fi 
}

stop()
{
       echo Stopping the $SERVICE_NAME service......
       SERVICE_PID=`ps -ef | grep java | grep $SERVICE_NAME | awk '{print $2}'`
       if [ ! $SERVICE_PID ]; then
          echo $SERVICE_NAME had been stopped!
       else
          kill -9 $SERVICE_PID
          echo $SERVICE_NAME stopped!
       fi 

}

restart()
{
       echo Restarting the $SERVICE_NAME service......
       SERVICE_PID=`ps -ef | grep java | grep $SERVICE_NAME | awk '{print $2}'`
       if [ ! $SERVICE_PID ]; then
               $JAVA_CMD  &
      echo $SERVICE_NAME restarted!
       else
          kill -9 $SERVICE_PID
           $JAVA_CMD &
          echo $SERVICE_NAME stopped!
      echo $SERVICE_NAME restarted!
       fi
}

case "$1" in
 start)
       start
       ;;
 stop)
       stop
       ;;
 restart)
       restart
       ;;
 *)
       echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
       exit 1
       ;;
esac

exit 0

代码仅供参考,使用时有些环境变量需要根据实际情况修改。

 

posted @ 2018-03-08 11:17  alsodzy  阅读(3890)  评论(0编辑  收藏  举报