jar包启动脚本

run.sh


if  [ -z "$1" ]  ||  [ -z  "$2" ] 
then
      echo "需按规范传参,实例: "
      echo "./run.sh xx.jar status"
      exit
fi



OJECT_DATE=$(date +%Y%m%d%H%M%S)
#
#当前文件目录
BASE_HOME=$(cd $(dirname $0); pwd)
#
PROJECT_NAME=$1
#
#PROJECT_OPTS="-Dbuildv=${PROJECT_DATE} -Xmx512m -Djava.compiler=NONE -Dspring.profiles.active=prod"
PROJECT_OPTS=""
#
PIDS=`ps -ef | grep "${PROJECT_NAME}" | grep java |awk '{print $2}'`
count=$(ps -ef | grep "${PROJECT_NAME}" | grep "java" | wc -l)
status(){
   echo "==========status======="
   ps -ef | grep "${PROJECT_NAME}" | grep java

   if [ $count -le 0 ]; then
        echo ${PROJECT_NAME}" is not runing"
   else
        echo ${PROJECT_NAME}" is runing"
   fi
}

start() {
    echo "==========start===========";
    ps -ef | grep "${PROJECT_NAME}" | grep java
    count=$(ps -ef | grep "${PROJECT_NAME}" | grep "java" | wc -l)
    if [ $count -le 0 ]; then
        echo ${PROJECT_NAME}" is starting"

        cd $BASE_HOME

        nohup java $PROJECT_OPTS -jar ${PROJECT_NAME} >/dev/null 2>&1 &
    else
    
        echo ${PROJECT_NAME}" is runing"
    fi
}

stop() {
    echo "===========stop============";

    ps -ef | grep "${PROJECT_NAME}" | grep java
    
    if [ -z "$PIDS" ]; then
    echo "警告: ${PROJECT_NAME} 未启动!"
    exit 1
    fi
    echo -e "正在停止 ${PROJECT_NAME} 进程[PIDS] ...\c"
    for PID in $PIDS ; do
    kill $PID > /dev/null 2>&1
    done
    COUNT=0
    while [ $COUNT -lt 1 ]; do
    echo -e "......\c"
    sleep 2
    COUNT=1
    for PID in $PIDS ; do
        PID_EXIST=`ps -f -p $PID | grep java`
        if [ -n "$PID_EXIST" ]; then
        COUNT=0
        break
        fi
    done
    done
    echo "${PROJECT_NAME} 进程[PIDS], 已停止!"
}

restart() {
    stop;
    echo "sleeping.........";
    sleep 3;
    start;

}
case "$2" in
    'start')
        start
        ;;
    'stop')
        stop
        ;;
    'status')
        status
        ;;
    'restart')
        restart
        ;;
    *)
    echo "usage: $0 {start|stop|restart|status}"
    exit 1
        ;;
    esac

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值