1、通用的springboot web jar包执行脚本,释放端口并执行jar包:
#!/bin/bash
set -e DATE = $( date +%Y%m%d%H%M)
BASE_PATH = /data/yitu-projects/yitu-xzhq/sftp
SERVER_NAME = yitu-server
PROFILES_ACTIVE = dev
HEAP_ERROR_PATH = $BASE_PATH /heapError
JAVA_OPS = "-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$HEAP_ERROR_PATH "
function stop ( ) { echo "[stop] 开始停止 $BASE_PATH /$SERVER_NAME " PID = $( ps -ef | grep $BASE_PATH/$SERVER_NAME | grep -v "grep" | awk '{print $2}' ) if [ -n "$PID " ] ; then echo "[stop] $BASE_PATH /$SERVER_NAME 运行中,开始 kill [$PID ]" kill -15 $PID for (( i = 0 ; i < 120 ; i++ )) do sleep 1 PID = $( ps -ef | grep $BASE_PATH/$SERVER_NAME | grep -v "grep" | awk '{print $2}' ) if [ -n "$PID " ] ; then echo -e ".\c " else echo '[stop] 停止 $BASE_PATH/$SERVER_NAME 成功' break fi done if [ -n "$PID " ] ; then echo "[stop] $BASE_PATH /$SERVER_NAME 失败,强制 kill -9 $PID " kill -9 $PID fi else echo "[stop] $BASE_PATH /$SERVER_NAME 未启动,无需停止" fi
}
function start ( ) { echo "[start] 开始启动 $BASE_PATH /$SERVER_NAME " echo "[start] JAVA_OPS: $JAVA_OPS " echo "[start] JAVA_AGENT: $JAVA_AGENT " echo "[start] PROFILES: $PROFILES_ACTIVE " nohup java -server $JAVA_OPS $JAVA_AGENT -jar $BASE_PATH /$SERVER_NAME .jar --spring.profiles.active = $PROFILES_ACTIVE > nohup.out 2 >&1 & echo "[start] 启动 $BASE_PATH /$SERVER_NAME 完成"
}
function deploy ( ) { cd $BASE_PATH stopstart
} deploy
2、使用时只需要修改以下参数: