项目jar部署启停shell脚本

发布时间 2023-11-02 17:58:00作者: 我的心儿
#!/bin/bash
APP_NAME=bixi-admin.jar

APP_DIR=`pwd`

usage() {
 echo "Usage: sh startup.sh [start|stop|restart|status]"
 exit 1
}

is_exist(){
 pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
 echo "aaaa:${pid}"
 if [ -z "${pid}" ]; then
 return 1
 else
 echo "ps number is: ${pid}"
 return 0
 fi
}

start(){
 is_exist
 if [ $? -eq "0" ]; then
 echo "${APP_NAME} is already running. pid=${pid} ."
 else
 echo "start----------------"
 nohup java -jar $APP_NAME > $APP_DIR/log.out 2>&1 &
 #nohup java -jar $APP_DIR/$APP_NAME
 echo "${APP_NAME} start success"
 fi
}

stop(){
 is_exist
 if [ $? -eq "0" ]; then
 kill -9 $pid
 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
}

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




备注:仅供参考