#!/bin/bash

cd "$(dirname "$0")"

if [ -f server.pid ]; then
    PID=$(cat server.pid)
    if ps -p $PID > /dev/null 2>&1; then
        echo "停止服务器 (PID: $PID)..."
        kill $PID
        rm -f server.pid
        echo "服务器已停止"
    else
        echo "服务器未运行"
        rm -f server.pid
    fi
else
    echo "未找到 PID 文件，尝试查找 node 进程..."
    pkill -f "node server.js" 2>/dev/null
    echo "已停止"
fi
