Files
roll-room/ry.sh
T
2026-06-25 14:05:19 +08:00

63 lines
1.4 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
# ============================================================
# 服务管理脚本
# 用法:./ry.sh start|stop|restart|status
# ============================================================
# ========== 配置项 ==========
export JAVA_HOME=/root/jdk-21.0.10
export PATH=$JAVA_HOME/bin:$PATH
APP_NAME=ruoyi-admin.jar
JVM_OPTS="-Xms128m -Xmx512m"
SPRING_PROFILE="pro"
LOG_FILE="nohup.out"
# ===========================
# 获取进程 PID
get_pid() {
echo $(ps -ef | grep "$APP_NAME" | grep -v grep | awk '{print $2}')
}
# 启动
start() {
local pid=$(get_pid)
if [ -n "$pid" ]; then
echo "⚠️ 服务已在运行,pid=$pid"
else
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
}
# 停止
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