diff --git a/hw_service_go/Dockerfile b/hw_service_go/Dockerfile index 1c31239..64e63ae 100644 --- a/hw_service_go/Dockerfile +++ b/hw_service_go/Dockerfile @@ -28,7 +28,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ FROM alpine:3.20 RUN sed -i 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories && \ - apk add --no-cache opus ffmpeg ca-certificates && \ + apk add --no-cache opus opusfile ffmpeg ca-certificates && \ addgroup -S hwws && adduser -S hwws -G hwws COPY --from=builder /app/hw-ws-service /hw-ws-service diff --git a/hw_service_go/internal/server/server.go b/hw_service_go/internal/server/server.go index 6f4fcaf..8cef562 100644 --- a/hw_service_go/internal/server/server.go +++ b/hw_service_go/internal/server/server.go @@ -98,6 +98,11 @@ func (s *Server) Shutdown(ctx context.Context) { // handleConn 处理单个 WebSocket 连接的完整生命周期。 // URL 格式:/xiaozhi/v1/?device-id=&client-id= func (s *Server) handleConn(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/xiaozhi/v1/healthz" { + s.handleStatus(w, r) + return + } + deviceID := r.URL.Query().Get("device-id") clientID := r.URL.Query().Get("client-id") diff --git a/run.sh b/run.sh index 8ceebde..74a47d5 100755 --- a/run.sh +++ b/run.sh @@ -44,21 +44,25 @@ echo "[✓] 虚拟环境就绪" free_port() { local port=$1 local name=$2 - local pid - pid=$(lsof -ti :"$port" 2>/dev/null) - if [ -n "$pid" ]; then - echo "[!] 端口 $port ($name) 被占用,PID: $pid,正在终止..." - kill -9 "$pid" 2>/dev/null - sleep 1 - pid=$(lsof -ti :"$port" 2>/dev/null) - if [ -n "$pid" ]; then - echo "[x] 端口 $port 释放失败,请手动处理" - exit 1 - fi - echo "[✓] 端口 $port 已释放" - else + local pids + pids=$(lsof -ti :"$port" 2>/dev/null) + if [ -z "$pids" ]; then echo "[✓] 端口 $port 空闲" + return fi + echo "[!] 端口 $port ($name) 被占用,PID: $pids,正在终止..." + echo "$pids" | xargs kill -9 2>/dev/null + for i in 1 2 3; do + sleep 1 + pids=$(lsof -ti :"$port" 2>/dev/null) + [ -z "$pids" ] && break + echo "$pids" | xargs kill -9 2>/dev/null + done + if [ -n "$(lsof -ti :"$port" 2>/dev/null)" ]; then + echo "[x] 端口 $port 释放失败,请手动处理" + exit 1 + fi + echo "[✓] 端口 $port 已释放" } free_port "$DJANGO_PORT" "Django"