stop.sh 1.06 KB
#!/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 "清理完成。"