Files
CyberGril/deploy/hel913-unified/worker_ctl.sh
T

49 lines
1.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# HEL-913 统一体验运行包 · 专属语音 worker 启停(只按 PID 句柄停止)
#
# 运行解释器是 agent venv(livekit-agents 1.8.8),产品代码经 PYTHONPATH 注入。
# worker 只连接本实例 API 与本机 LiveKit;停止只杀自己写的 PID,不匹配进程名。
#
# 用法: [ENV=..] bash deploy/hel913-unified/worker_ctl.sh start|stop|status
# 环境变量:
# HEL913_BASE 实例根目录(含 current/ worker/ 等)
# HEL913_AGENT_VENV agent venv python(默认 /opt/voice-agent/agent/venv/bin/python)
# HEL913_WORKER_HEALTH 健康端口(默认 8082;与 worker/.env 中一致)
set -u
BASE=${HEL913_BASE:-/opt/cybergril-hel913}
VENV=${HEL913_AGENT_VENV:-/opt/voice-agent/agent/venv/bin/python}
HEALTH=${HEL913_WORKER_HEALTH:-8082}
LOG=$BASE/logs/worker.log
PIDF=$BASE/logs/worker.pid
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:$HEALTH/" >/dev/null && echo "health ok" || echo "health port not answering"
exit 0 ;;
esac
cd "$BASE/worker"
set -a
source "$BASE/worker/.env"
set +a
PYTHONPATH="$BASE/current/src" nohup "$VENV" -m cybergril.voice.worker start > "$LOG" 2>&1 &
echo $! > "$PIDF"
echo "worker starting (pid $(cat "$PIDF"))"
sleep 18
grep -m1 "registered worker" "$LOG" >/dev/null && echo "OK: worker registered" \
|| { echo "FAIL:"; tail -8 "$LOG"; exit 1; }