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

 

上一篇:linux系统每日巡检脚本


下一篇:shell脚本之一键部署yum本地源兼yum阿里源,再也不用为程序的下载安装烦扰!