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
标签:shell,jar,APP,PID,echo,033,PROG,HOME,包启停 来源: https://www.cnblogs.com/wxp100/p/15095245.html