Files
AIGC/demo/stop.sh
2025-10-21 16:50:33 +08:00

60 lines
1.4 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# AIGC Demo 停止脚本
echo "=== AIGC Demo 停止脚本 ==="
echo ""
# 检查进程ID文件
if [ -f "app.pid" ]; then
APP_PID=$(cat app.pid)
echo "📝 找到进程ID: $APP_PID"
# 检查进程是否存在
if ps -p $APP_PID > /dev/null; then
echo "🛑 正在停止应用..."
kill $APP_PID
# 等待进程结束
for i in {1..10}; do
if ! ps -p $APP_PID > /dev/null; then
echo "✅ 应用已停止"
rm -f app.pid
break
fi
echo -n "."
sleep 1
done
if ps -p $APP_PID > /dev/null; then
echo ""
echo "⚠️ 应用未正常停止,强制终止..."
kill -9 $APP_PID
rm -f app.pid
echo "✅ 应用已强制停止"
fi
else
echo "⚠️ 进程不存在,可能已经停止"
rm -f app.pid
fi
else
echo "⚠️ 未找到进程ID文件 (app.pid)"
echo " 尝试查找Java进程..."
# 查找Java进程
JAVA_PIDS=$(ps aux | grep "demo-0.0.1-SNAPSHOT.jar" | grep -v grep | awk '{print $2}')
if [ -n "$JAVA_PIDS" ]; then
echo "🔍 找到Java进程: $JAVA_PIDS"
echo "$JAVA_PIDS" | xargs kill
echo "✅ Java进程已停止"
else
echo " 未找到运行中的Java进程"
fi
fi
echo ""
echo "🏁 停止脚本执行完成"