diff --git a/data/src/main/resources/bin/start.sh b/data/src/main/resources/bin/start.sh index c0777950..aee77ae7 100644 --- a/data/src/main/resources/bin/start.sh +++ b/data/src/main/resources/bin/start.sh @@ -42,4 +42,4 @@ fi # 启动项目 echo "正在启动项目..." -nohup java ${JVM_OPTS} -Dspring.profiles.active=dev -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 & \ No newline at end of file +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 & \ No newline at end of file diff --git a/gateway2/src/main/resources/application.yml b/gateway2/src/main/resources/application.yml index b09ec360..83ccd4b8 100644 --- a/gateway2/src/main/resources/application.yml +++ b/gateway2/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: profiles: - active: dev + active: local main: web-application-type: reactive cloud: diff --git a/gateway2/src/main/resources/bin/restart.sh b/gateway2/src/main/resources/bin/restart.sh index cc9ef821..d02388c5 100644 --- a/gateway2/src/main/resources/bin/restart.sh +++ b/gateway2/src/main/resources/bin/restart.sh @@ -1,7 +1,25 @@ #!/bin/bash -# Spring Boot 网关项目重启脚本 +# Spring Boot 项目重启脚本 + +# 定义基础路径(公共参数) +BASE_DIR="/home/app/gateway2" 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 "=== 重启操作完成 ===" \ No newline at end of file diff --git a/gateway2/src/main/resources/bin/start.sh b/gateway2/src/main/resources/bin/start.sh index eae498b4..b5f9ce8b 100644 --- a/gateway2/src/main/resources/bin/start.sh +++ b/gateway2/src/main/resources/bin/start.sh @@ -41,10 +41,8 @@ if [ ! -d "${LOG_HOME}" ]; then echo "日志目录不存在,已自动创建:${LOG_HOME}" fi -echo "正在启动项目... " -echo "======================================================================" - -# 启动项目,保留控制台输出 -nohup java ${JVM_OPTS} -jar "${FULL_JAR_PATH}" --spring.profiles.active=dev > "${LOG_FILE}" 2>&1 & +# 启动项目 +echo "正在启动项目..." +nohup java ${JVM_OPTS} -Dspring.profiles.active=dev -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 & diff --git a/gateway2/src/main/resources/bin/stop.sh b/gateway2/src/main/resources/bin/stop.sh index 724f7c8b..66924f09 100644 --- a/gateway2/src/main/resources/bin/stop.sh +++ b/gateway2/src/main/resources/bin/stop.sh @@ -2,29 +2,37 @@ # Spring Boot 项目强制停止脚本 JAR_NAME="gateway2-0.0.1-SNAPSHOT.jar" -# 函数定义:获取运行中的进程ID +# 函数定义 get_running_pid() { ps -ef | grep "${JAR_NAME}" | grep -v "grep" | awk '{print $2}' } -# 获取进程ID +# 停止服务 PID=$(get_running_pid) - -# 检查进程是否存在 if [ -z "${PID}" ]; then echo "项目未在运行中,无需停止" exit 0 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}" -# 检查是否成功停止 -sleep 5 +sleep 2 if [ -z "$(get_running_pid)" ]; then - echo "项目已强制停止成功" - exit 0 + echo "项目已强制停止" else echo "ERROR: 进程终止失败!请手动检查:ps -ef | grep ${JAR_NAME}" exit 1