#!/usr/bin/env bash # HEL-910 测试窗口:专属语音 worker(只按 PID 句柄停止;ASR 布防在 etc/asr-arm.env) set -u BASE=/opt/cybergril-hel910 LOG=$BASE/logs/worker.log PIDF=$BASE/logs/worker.pid VENV=/opt/voice-agent/agent/venv stop() { if [ -f "$PIDF" ]; then P=$(cat "$PIDF") if [ "$P" != "$$" ] && kill -0 "$P" 2>/dev/null; then kill "$P"; sleep 3; fi if [ "$P" != "$$" ] && kill -0 "$P" 2>/dev/null; then kill -9 "$P"; fi rm -f "$PIDF" echo "worker stopped (pid $P)" else echo "no pid file; nothing stopped" fi } case "${1:-}" in stop) stop; exit 0 ;; status) if [ -f "$PIDF" ]; then P=$(cat "$PIDF"); kill -0 "$P" 2>/dev/null && echo "running pid $P" || echo "pid $P not alive"; fi curl -s --max-time 3 "http://127.0.0.1:8082/" && echo " <- health" || echo "health port not answering" exit 0 ;; esac cd "$BASE/worker" set -a source "$BASE/worker/.env" source "$BASE/etc/asr-arm.env" set +a PYTHONPATH="$BASE/current/src" nohup "$VENV/bin/python" -m cybergril.voice.worker start > "$LOG" 2>&1 & echo $! > "$PIDF" echo "worker starting (pid $(cat $PIDF)) ASR window=$(grep -o 'hel910-20261029-a' $BASE/etc/asr-arm.env | head -1)" sleep 18 grep -m1 "registered worker" "$LOG" >/dev/null && echo "OK: worker registered" \ || { echo "FAIL:"; tail -8 "$LOG"; exit 1; }