stop.sh
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
cd "$(dirname "$0")/.."
SYNC_PID="sync.pid"
BRAND_SYNC_PID="brand_sync.pid"
API_PID="api.pid"
echo "=== 门店管理服务停止脚本 ==="
stop_process() {
local pid_file=$1
local name=$2
if [ ! -f "$pid_file" ]; then
echo "跳过: $name (未发现 PID 文件)"
return
fi
PID=$(cat "$pid_file")
if ps -p $PID > /dev/null 2>&1; then
echo "正在停止 $name (PID: $PID)..."
if ! kill $PID 2>/dev/null; then
echo "错误: 无法停止 $name (PID: $PID)。"
echo "原因: 权限不足。请尝试使用 sudo 运行: sudo ./scripts/stop.sh"
return 1
fi
sleep 1
if ps -p $PID > /dev/null 2>&1; then
kill -9 $PID 2>/dev/null
fi
echo "$name 已停止。"
else
echo "警告: $name 进程已不存在,正在清理 PID 文件。"
fi
rm "$pid_file"
}
stop_process "$SYNC_PID" "门店同步服务"
stop_process "$BRAND_SYNC_PID" "品牌同步服务"
stop_process "$API_PID" "API 服务"
echo "清理完成。"