🔧 改进清理逻辑:使用 lsof 强制清理端口

This commit is contained in:
2026-04-05 07:39:54 +08:00
parent 7bf62612b7
commit 49047b37e4

View File

@@ -5,8 +5,21 @@ echo "🏛️ 启动龙虾议事厅开发环境..."
# 检查并停止旧服务
echo "🧹 清理旧服务..."
pkill -f "meeting-room.*runserver" 2>/dev/null
pkill -f "frontend.*npm start" 2>/dev/null
# 方法 1: 使用 lsof 查找并杀死占用端口的进程
for port in 8000 3000; do
pid=$(lsof -t -i:$port 2>/dev/null)
if [ -n "$pid" ]; then
echo " 杀死占用端口 $port 的进程 (PID: $pid)..."
kill -9 $pid 2>/dev/null
fi
done
# 方法 2: 使用 pkill 清理
pkill -9 -f "manage.py runserver" 2>/dev/null
pkill -9 -f "npm start" 2>/dev/null
pkill -9 -f "node.*react-scripts" 2>/dev/null
sleep 2
# 启动后端