stop.sh 803 Bytes
#!/bin/bash

# 切换到脚本所在目录
cd "$(dirname "$0")"

SYNC_PID="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)..."
        kill $PID
        sleep 1
        if ps -p $PID > /dev/null 2>&1; then
            kill -9 $PID
        fi
        echo "$name 已停止。"
    else
        echo "警告: $name 进程已不存在。"
    fi
    rm "$pid_file"
}

# 停止两个服务
stop_process "$SYNC_PID" "同步服务"
stop_process "$API_PID" "API 服务"

echo "清理完成。"