chore: 优化 AI-Core 启动脚本

- 更新 start.bat 和 start.sh 启动脚本
- 优化 gRPC 服务器配置

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 12:50:33 +08:00
parent dc1c825d2e
commit 16b6aa0004
3 changed files with 77 additions and 30 deletions

View File

@@ -58,29 +58,53 @@ if [ ! -f "proto/document_parser_pb2.py" ]; then
fi
fi
# 检查端口占用并释放
echo "Checking port $PORT..."
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
# Windows
NETSTAT_OUTPUT=$(netstat -ano 2>/dev/null | grep ":$PORT" | grep LISTENING)
if [ -n "$NETSTAT_OUTPUT" ]; then
echo "Port $PORT is in use, killing process..."
PID=$(echo "$NETSTAT_OUTPUT" | awk '{print $NF}' | head -1)
if [ -n "$PID" ]; then
taskkill //F //PID $PID 2>/dev/null
sleep 1
fi
fi
else
# Linux/Mac
PID=$(lsof -ti:$PORT 2>/dev/null)
if [ -n "$PID" ]; then
echo "Port $PORT is in use, killing process $PID..."
kill $PID 2>/dev/null
sleep 1
fi
# 用 Python 来检测和杀死占用端口的进程(跨平台更可靠)
echo "Checking and cleaning up port $PORT..."
# 先尝试直接用 Windows 命令杀死(更可靠)
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" || "$(uname)" == "MINGW"* ]]; then
# 直接用 cmd /c 执行
cmd //c "for /f \"tokens=5\" %a in ('netstat -ano ^| findstr :$PORT ^| findstr LISTENING') do taskkill /F /PID %a"
sleep 1
fi
# 再用 Python 检测
$PYTHON_CMD -c "
import socket
import subprocess
import sys
import time
import os
port = $PORT
print(f'Checking port {port}...')
# 检查端口是否被占用
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
result = s.connect_ex(('127.0.0.1', port))
s.close()
if result != 0:
print(f'Port {port} is free (not listening)')
else:
print(f'Port {port} is still in use!')
# 尝试杀死
try:
result = subprocess.run(['netstat', '-ano'], capture_output=True, text=True, shell=True)
for line in result.stdout.split('\n'):
if f':{port}' in line and 'LISTENING' in line:
parts = line.split()
pid = parts[-1]
print(f'Found process {pid}, killing...')
os.system(f'taskkill /F /PID {pid}')
time.sleep(2)
except Exception as e:
print(f'Error: {e}')
except Exception as e:
print(f'Check error: {e}')
"
# Start the server
echo "Starting server on port $PORT..."
$PYTHON_CMD main.py --port $PORT --max-workers 10 --log-level INFO