修改启动脚本

This commit is contained in:
2025-11-25 09:51:15 +08:00
parent 1c0f03e4cf
commit 2ca489cc87
5 changed files with 45 additions and 21 deletions

View File

@@ -42,4 +42,4 @@ fi
# 启动项目 # 启动项目
echo "正在启动项目..." echo "正在启动项目..."
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 & nohup java ${JVM_OPTS} -Dspring.profiles.active=dev -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &

View File

@@ -1,6 +1,6 @@
spring: spring:
profiles: profiles:
active: dev active: local
main: main:
web-application-type: reactive web-application-type: reactive
cloud: cloud:

View File

@@ -1,7 +1,25 @@
#!/bin/bash #!/bin/bash
# Spring Boot 网关项目重启脚本 # Spring Boot 项目重启脚本
# 定义基础路径(公共参数)
BASE_DIR="/home/app/gateway2"
echo "=== 开始重启项目 ===" echo "=== 开始重启项目 ==="
./stop.sh
./start.sh # 先停止服务
echo "=== 重启操作完成 ===" if [ -f "${BASE_DIR}/stop.sh" ]; then
"${BASE_DIR}/stop.sh"
else
echo "错误:未找到停止脚本 ${BASE_DIR}/stop.sh"
exit 1
fi
# 再启动服务
if [ -f "${BASE_DIR}/start.sh" ]; then
"${BASE_DIR}/start.sh"
else
echo "错误:未找到启动脚本 ${BASE_DIR}/start.sh"
exit 1
fi
echo "=== 重启操作完成 ==="

View File

@@ -41,10 +41,8 @@ if [ ! -d "${LOG_HOME}" ]; then
echo "日志目录不存在,已自动创建:${LOG_HOME}" echo "日志目录不存在,已自动创建:${LOG_HOME}"
fi fi
echo "正在启动项目... " # 启动项目
echo "======================================================================" echo "正在启动项目..."
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
# 启动项目,保留控制台输出
nohup java ${JVM_OPTS} -jar "${FULL_JAR_PATH}" --spring.profiles.active=dev > "${LOG_FILE}" 2>&1 &

View File

@@ -2,29 +2,37 @@
# Spring Boot 项目强制停止脚本 # Spring Boot 项目强制停止脚本
JAR_NAME="gateway2-0.0.1-SNAPSHOT.jar" JAR_NAME="gateway2-0.0.1-SNAPSHOT.jar"
# 函数定义获取运行中的进程ID # 函数定义
get_running_pid() { get_running_pid() {
ps -ef | grep "${JAR_NAME}" | grep -v "grep" | awk '{print $2}' ps -ef | grep "${JAR_NAME}" | grep -v "grep" | awk '{print $2}'
} }
# 获取进程ID # 停止服务
PID=$(get_running_pid) PID=$(get_running_pid)
# 检查进程是否存在
if [ -z "${PID}" ]; then if [ -z "${PID}" ]; then
echo "项目未在运行中,无需停止" echo "项目未在运行中,无需停止"
exit 0 exit 0
fi fi
# 强制停止进程 echo "正在停止项目... PID: ${PID}"
echo "正在强制停止项目... PID: ${PID}" kill -15 "${PID}"
WAIT=0
while [ ${WAIT} -lt 10 ]; do
if [ -z "$(get_running_pid)" ]; then
echo "项目已优雅停止"
exit 0
fi
sleep 1
WAIT=$((WAIT + 1))
done
echo "优雅停止超时,强制终止进程... PID: ${PID}"
kill -9 "${PID}" kill -9 "${PID}"
# 检查是否成功停止 sleep 2
sleep 5
if [ -z "$(get_running_pid)" ]; then if [ -z "$(get_running_pid)" ]; then
echo "项目已强制停止成功" echo "项目已强制停止"
exit 0
else else
echo "ERROR: 进程终止失败请手动检查ps -ef | grep ${JAR_NAME}" echo "ERROR: 进程终止失败请手动检查ps -ef | grep ${JAR_NAME}"
exit 1 exit 1