jar包启动脚本

#!/bin/bash
export <strong>JAVA_HOME</strong>=/u01/java_home/jdk1.8.0_181
export <strong>APP_HOME</strong>=/u01/test
export <strong>APP_NAME</strong>=mzyzsjz-server-0.0.1-SNAPSHO.jar
export <strong>PROG</strong>=test<br></br>
function getPid {
PID=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'|awk 'NR==1'`
}

getPid
case $1 in
    start)
        if [  ! $PID  ];then
        nohup $JAVA_HOME/bin/java -jar $APP_HOME/$APP_NAME >> $APP_HOME/logs/catalina.`date +%Y-%m-%d`.out 2>&1 &
        echo "starting"
        sleep 1
        getPid
        echo -e "$PROG is \033[32mActive\033[0m, PID = $PID"
        else
        echo "$PROG is exist, PID = $PID"
        fi
        ;;
    stop)
        if [  $PID ];then
        kill -15 $PID
        echo "stoping..."
        sleep 1
        getPid
        echo -e "$PROG is \033[31mDead\033[0m"
        else
        echo "$PROG is not exist"
        fi
        ;;
    restart)
        echo "restarting..."
        if [  $PID ];then
        kill -15 $PID
        sleep 1
        nohup $JAVA_HOME/bin/java -jar $APP_HOME/$APP_NAME >> $APP_HOME/logs/catalina.`date +%Y-%m-%d`.out 2>&1 &
        getPid
        echo -e "$PROG is \033[32mRestart\033[0m, PID = $PID"
        else
        nohup $JAVA_HOME/bin/java -jar $APP_HOME/$APP_NAME >> $APP_HOME/logs/catalina.`date +%Y-%m-%d`.out 2>&1 &
        sleep 1
        getPid
        echo -e "$PROG is \033[32mRestart\033[0m, PID = $PID"
        fi
        ;;
    *)
    echo "Usage:{$0 start|stop|restart}"
    ;;
esac
exit 0

标签: shell, echo, jar, HOME, PID, APP, PROG, 包启停

相关文章推荐

添加新评论,含*的栏目为必填