linux启动jar文件Shell脚本

linux启动jar文件execJar.sh


APP_NAME=${1##*/}
ALL_PATH=$1

usage() {
 echo "Usage: sh execJar.sh [path/procedure_name] [start|stop|restart|status]"
 exit 1
}
is_exist(){
 #echo "APP_NAME=" ${APP_NAME}
 pid=$(ps -ef|grep $APP_NAME |grep -v execJar | grep -v grep |awk '{print $2}')
 #echo "ps -ef|grep " ${APP_NAME} "|grep -v grep" 
 #echo "pid="${pid}
 if [ -z "${pid}" ]; then
 return 1
 else
 return 0
 fi
}
start(){
 is_exist
 if [ $? -eq "0" ]; then
 echo "${APP_NAME} is already running. pid=${pid} ."
 else
 nohup java -jar ${ALL_PATH} > /dev/null 2>&1 &
 echo "nohup java -jar ${ALL_PATH}.log /dev/null &"
 echo "${APP_NAME} start success"
 fi
}
stop(){
 is_exist
 if [ $? -eq "0" ]; then
 kill -9 $pid
 echo "${APP_NAME} ${pid} stoped "
 else
 echo "${APP_NAME} is not running"
 fi
}
status(){
 is_exist
 if [ $? -eq "0" ]; then
 echo "${APP_NAME} is running. Pid is ${pid}"
 else
 echo "${APP_NAME} is NOT running."
 fi
}

restart(){
 stop
 start
}

if [ $# -lt 2 ]
then
  usage
  exit 1
fi

case "$2" in
 "start")
 start
 ;;
 "stop")
 stop
 ;;
 "status")
 status
 ;;
 "restart")
 restart
 ;;
 *)
 usage
 ;;
esac

hs-server 目录下面放jar包,将sh文件放在hs-server同目录
linux启动jar文件Shell脚本_第1张图片

你可能感兴趣的:(linux,shell,linux,shell,jar)