#!/bin/bash # 获取配置的端口,默认为4000 PORT=$(grep "PORT=" .env | cut -d= -f2 || echo "4000") echo "Service configured to use port $PORT" # 查找并停止使用该端口的进程 PID=$(lsof -ti :$PORT) if [ ! -z "$PID" ]; then echo "Stopping process $PID using port $PORT..." kill -9 $PID sleep 1 fi # 停止可能正在运行的服务器 echo "Stopping any running server..." pkill -f "node dist/index.js" || true pkill -f "tsx watch src/index.ts" || true # 构建项目 echo "Building project..." npm run build # 启动服务器 echo "Starting server..." npm start