QAUP_Management/qaup.sh
2025-10-17 10:44:34 +08:00

175 lines
3.9 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/sh
# ./qaup.sh start 启动 stop 停止 restart 重启 status 状态
AppName=qaup-admin.jar
# JVM参数
JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
# 应用目录和日志路径
APP_HOME=`pwd`
LOG_PATH=$APP_HOME/logs/$AppName.log
# 环境变量配置文件路径
ENV_FILE=$APP_HOME/.env
# Spring Profile配置生产环境使用prod开发环境使用dev
# 可通过环境变量 SPRING_PROFILES_ACTIVE 覆盖,默认为 prod,druid
SPRING_PROFILES=${SPRING_PROFILES_ACTIVE:-prod,druid}
if [ "$1" = "" ];
then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi
if [ "$AppName" = "" ];
then
echo -e "\033[0;31m 未输入应用名 \033[0m"
exit 1
fi
function start()
{
PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
if [ x"$PID" != x"" ]; then
echo "$AppName is running..."
else
# ========== 加载环境变量配置 ==========
if [ -f "$ENV_FILE" ]; then
echo "Loading environment variables from $ENV_FILE"
# 导出环境变量,忽略注释行和空行
export $(grep -v '^#' $ENV_FILE | grep -v '^
echo "Starting $AppName with profile: $SPRING_PROFILES"
# 启动应用指定Spring Profile
nohup java $JVM_OPTS -jar $AppName --spring.profiles.active=$SPRING_PROFILES > /dev/null 2>&1 &
echo "Start $AppName success..."
fi
}
function stop()
{
echo "Stop $AppName"
PID=""
query(){
PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
}
query
if [ x"$PID" != x"" ]; then
kill -TERM $PID
echo "$AppName (pid:$PID) exiting..."
while [ x"$PID" != x"" ]
do
sleep 1
query
done
echo "$AppName exited."
else
echo "$AppName already stopped."
fi
}
function restart()
{
stop
sleep 2
start
}
function status()
{
PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l`
if [ $PID != 0 ];then
echo "$AppName is running..."
else
echo "$AppName is not running..."
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
echo -e "\033[0;31m 未知操作 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
esac
| xargs)
echo "Environment variables loaded successfully"
else
echo "Warning: $ENV_FILE not found, using default configuration"
fi
# ========================================
echo "Starting $AppName with profile: $SPRING_PROFILES"
# 启动应用指定Spring Profile
nohup java $JVM_OPTS -jar $AppName --spring.profiles.active=$SPRING_PROFILES > /dev/null 2>&1 &
echo "Start $AppName success..."
fi
}
function stop()
{
echo "Stop $AppName"
PID=""
query(){
PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
}
query
if [ x"$PID" != x"" ]; then
kill -TERM $PID
echo "$AppName (pid:$PID) exiting..."
while [ x"$PID" != x"" ]
do
sleep 1
query
done
echo "$AppName exited."
else
echo "$AppName already stopped."
fi
}
function restart()
{
stop
sleep 2
start
}
function status()
{
PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l`
if [ $PID != 0 ];then
echo "$AppName is running..."
else
echo "$AppName is not running..."
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
echo -e "\033[0;31m 未知操作 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
esac