3588AdminBackend/scripts/deploy/stop.sh
2026-02-25 11:00:55 +08:00

70 lines
1.7 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
# 3588AdminBackend 停止脚本
APP_NAME="managerd"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PID_FILE="$APP_DIR/$APP_NAME.pid"
echo "========== 停止 3588AdminBackend =========="
if [ ! -f "$PID_FILE" ]; then
echo " $APP_NAME 未在运行 (PID 文件不存在)"
# 尝试查找进程
PID=$(pgrep -f "^$APP_DIR/bin/$APP_NAME" | head -1)
if [ -n "$PID" ]; then
echo "发现运行中的进程 (PID: $PID),尝试停止..."
kill "$PID" 2>/dev/null || true
for i in {1..10}; do
if ! ps -p "$PID" > /dev/null 2>&1; then
echo "✅ 已停止"
exit 0
fi
sleep 1
done
echo "强制结束进程..."
kill -9 "$PID" 2>/dev/null || true
echo "✅ 已停止"
fi
exit 0
fi
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo "正在停止 $APP_NAME (PID: $PID)..."
kill "$PID"
# 等待进程结束
echo -n "等待进程结束"
for i in {1..10}; do
if ! ps -p "$PID" > /dev/null 2>&1; then
echo ""
echo "✅ 已停止"
rm -f "$PID_FILE"
exit 0
fi
echo -n "."
sleep 1
done
echo ""
# 强制结束
echo "进程未响应,强制结束..."
kill -9 "$PID" 2>/dev/null || true
sleep 1
if ! ps -p "$PID" > /dev/null 2>&1; then
echo "✅ 已强制停止"
else
echo "❌ 无法停止进程,请手动检查"
exit 1
fi
else
echo " 进程不存在 (PID: $PID),清理 PID 文件"
fi
rm -f "$PID_FILE"