QAUP_Management/qaup.sh
2025-10-17 11:49:35 +08:00

114 lines
2.3 KiB
Bash
Executable File
Raw Permalink 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/sh
# 应用名称
APP_NAME=qaup-admin/target/qaup-admin.jar
# JVM参数
JVM_OPTS="-Dname=$APP_NAME -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m"
# 获取当前目录
APP_HOME=`pwd`
# 环境变量配置文件路径
ENV_FILE=$APP_HOME/.env
# 检查参数
if [ "$1" = "" ]; then
echo "用法: $0 {start|stop|restart|status}"
exit 1
fi
# 加载环境变量
load_env() {
if [ -f "$ENV_FILE" ]; then
echo "加载环境变量配置: $ENV_FILE"
# 使用更兼容的方式加载环境变量
grep -v '^#' "$ENV_FILE" | grep -v '^$' | while IFS= read -r line; do
export "$line"
done
echo "环境变量加载完成"
else
echo "警告: 未找到环境配置文件 $ENV_FILE,使用默认配置"
fi
}
# 启动应用
start() {
# 检查进程是否已运行
if pgrep -f "$APP_NAME" > /dev/null; then
echo "$APP_NAME 已在运行"
return 0
fi
# 加载环境变量
load_env
echo "正在启动 $APP_NAME..."
# 启动应用Spring Boot有自己的日志管理机制
nohup java $JVM_OPTS -jar "$APP_NAME" > /dev/null 2>&1 &
# 等待一会儿检查是否启动成功
sleep 2
if pgrep -f "$APP_NAME" > /dev/null; then
echo "$APP_NAME 启动成功"
else
echo "$APP_NAME 启动失败,请检查日志"
fi
}
# 停止应用
stop() {
echo "正在停止 $APP_NAME..."
# 查找进程ID
PID=$(pgrep -f "$APP_NAME")
if [ -n "$PID" ]; then
kill "$PID"
sleep 3
# 如果进程仍未停止,强制杀死
if pgrep -f "$APP_NAME" > /dev/null; then
kill -9 "$PID"
fi
echo "$APP_NAME 已停止"
else
echo "$APP_NAME 未运行"
fi
}
# 重启应用
restart() {
stop
sleep 2
start
}
# 检查状态
status() {
if pgrep -f "$APP_NAME" > /dev/null; then
echo "$APP_NAME 正在运行"
else
echo "$APP_NAME 未运行"
fi
}
# 根据参数执行相应操作
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "用法: $0 {start|stop|restart|status}"
exit 1
;;
esac