#!/bin/bash#这里可替换为你本人的执行程序,其余代码无需更改APP_NAME=asug.jarWAR_LOCATION=../asug/targetBAK_LOCATION=warBak#应用阐明,用来提醒输出参数usage() { echo "Usage: sh 脚本名.sh [start|stop|restart|status|deploy]" exit 1}#检查程序是否在运行is_exist(){ pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' ` #如果不存在返回1,存在返回0 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 ./${APP_NAME} --server.port=8080 --spring.profiles.active=prod > /dev/null 2>&1 & 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}deploy(){ stop cp $APP_NAME $BAK_LOCATION/$APP_NAME.$(date "+%Y%m%d%H%M") rm -rf $APP_NAME rm -rf nohup.out cp $WAR_LOCATION/$APP_NAME $APP_NAME start}#依据输出参数,抉择执行对应办法,不输出则执行应用阐明case "$1" in "start") start ;; "stop") stop ;; "status") status ;; "restart") restart ;; "deploy") deploy ;; *) usage ;;esac