This commit is contained in:
2026-06-25 14:05:19 +08:00
parent 22d98b089f
commit 09883eacdb
4 changed files with 133 additions and 81 deletions
+51 -75
View File
@@ -1,86 +1,62 @@
#!/bin/sh
# ./ry.sh start 启动 stop 停止 restart 重启 status 状态
AppName=ruoyi-admin.jar
#!/bin/bash
# ============================================================
# 服务管理脚本
# 用法:./ry.sh start|stop|restart|status
# ============================================================
# JVM参数
JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:+UseAdaptiveSizePolicy -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2"
APP_HOME=`pwd`
LOG_PATH=$APP_HOME/logs/$AppName.log
# ========== 配置项 ==========
export JAVA_HOME=/root/jdk-21.0.10
export PATH=$JAVA_HOME/bin:$PATH
if [ "$1" = "" ];
then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi
APP_NAME=ruoyi-admin.jar
JVM_OPTS="-Xms128m -Xmx512m"
SPRING_PROFILE="pro"
LOG_FILE="nohup.out"
# ===========================
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
nohup java $JVM_OPTS -jar $AppName > /dev/null 2>&1 &
echo "Start $AppName success..."
fi
# 获取进程 PID
get_pid() {
echo $(ps -ef | grep "$APP_NAME" | grep -v grep | awk '{print $2}')
}
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..."
# 启动
start() {
local pid=$(get_pid)
if [ -n "$pid" ]; then
echo "⚠️ 服务已在运行,pid=$pid"
else
echo "$AppName is not running..."
nohup java $JVM_OPTS -Dspring.profiles.active=$SPRING_PROFILE -jar $APP_NAME > $LOG_FILE 2>&1 &
sleep 1
local new_pid=$(get_pid)
echo "✅ 服务已启动,pid=$new_pid"
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
# 停止
stop() {
local pid=$(get_pid)
if [ -n "$pid" ]; then
kill -9 $pid
echo "✅ 服务已停止(pid=$pid"
else
echo "⚠️ 服务未在运行"
fi
}
# 状态
status() {
local pid=$(get_pid)
if [ -n "$pid" ]; then
echo "✅ 服务运行中,pid=$pid"
else
echo "❌ 服务未运行"
fi
}
case "$1" in
start) start ;;
stop) stop ;;
restart) stop; sleep 2; start ;;
status) status ;;
*) echo "用法:$0 {start|stop|restart|status}" ;;
esac