jar包启停shell脚本

2021/8/4 7:08:50

本文主要是介绍jar包启停shell脚本,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

jar包启动脚本

#!/bin/bash
export JAVA_HOME=/u01/java_home/jdk1.8.0_181
export APP_HOME=/u01/test
export APP_NAME=mzyzsjz-server-0.0.1-SNAPSHO.jar
export PROG=test

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

 



这篇关于jar包启停shell脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程