You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.6 KiB
Bash

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# 配置参数
JAR_NAME="ruoyi-admin.jar"
JAR_PATH="/home/xuao/program/course/backend"
LOG_FILE="nohup.out"
# 进入工作目录
cd $JAR_PATH
# 查找并停止正在运行的进程
PID=$(ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
echo "找到正在运行的进程PID: $PID"
echo "正在停止进程..."
kill $PID
sleep 3
# 检查是否成功停止
if ps -p $PID > /dev/null 2>&1; then
echo "进程仍在运行,强制终止..."
kill -9 $PID
sleep 2
fi
if ps -p $PID > /dev/null 2>&1; then
echo "无法停止进程 $PID,请手动检查"
exit 1
else
echo "进程 $PID 已成功停止"
fi
else
echo "未找到正在运行的进程"
fi
# 检查JAR文件是否存在
if [ ! -f "$JAR_NAME" ]; then
echo "错误: JAR文件 $JAR_NAME 不存在"
exit 1
fi
# 启动应用程序
echo "正在启动应用程序..."
nohup java -jar "$JAR_NAME" > $LOG_FILE 2>&1 &
# 检查启动是否成功
if [ $? -eq 0 ]; then
echo "应用程序启动成功"
# 获取新进程ID
NEW_PID=$(ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}')
echo "新进程PID: $NEW_PID"
# 显示日志文件内容
echo "=== 显示最后50行日志 ==="
if [ -f $LOG_FILE ]; then
tail -50 $LOG_FILE
echo "========================="
echo "使用以下命令查看实时日志: tail -f $LOG_FILE"
else
echo "日志文件 $LOG_FILE 不存在"
fi
else
echo "应用程序启动失败"
exit 1
fi