63 lines
1.4 KiB
Bash
63 lines
1.4 KiB
Bash
#!/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
|