Files
spdm-backend/data/src/main/resources/bin/65/startprod.sh

45 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Spring Boot 项目启动脚本
JAR_PATH="/home/app/data"
JAR_NAME="data-0.0.1-SNAPSHOT.jar"
FULL_JAR_PATH="${JAR_PATH}/${JAR_NAME}"
# 与logback.xml保持一致的日志路径
LOG_HOME="/home/app/data/logs"
LOG_FILE="${LOG_HOME}/running.log"
# JVM参数
JVM_OPTS="-Xms512m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${LOG_HOME}/heapdump.hprof"
# 函数定义
check_jar_exists() {
if [ ! -f "${FULL_JAR_PATH}" ]; then
echo "ERROR: Jar包不存在路径${FULL_JAR_PATH}"
exit 1
fi
}
get_running_pid() {
ps -ef | grep "${JAR_NAME}" | grep -v "grep" | awk '{print $2}'
}
# 检查是否已运行
PID=$(get_running_pid)
if [ -n "${PID}" ]; then
echo "项目已在运行中PID: ${PID}"
exit 0
fi
# 检查Jar包是否存在
check_jar_exists
# 确保日志目录存在
if [ ! -d "${LOG_HOME}" ]; then
mkdir -p "${LOG_HOME}"
echo "日志目录不存在,已自动创建:${LOG_HOME}"
fi
# 启动项目
echo "正在启动项目..."
nohup java ${JVM_OPTS} -Dspring.profiles.active=prod -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5002 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &