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

64 lines
2.7 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 统一体验运行包 · 统一实例 API 启停(单进程 HTTP+HTTPS 双入口)
#
# 与 HEL-910 的 api_ctl.sh 同构,去掉一次性路径硬编码:实例根、端口、证书、
# 解释器全部可用环境变量覆盖。启动器 deploy/voice/serve_dual_8360_8361.py
# 保证 HTTP 与 HTTPS 共用同一 API 进程/同一份状态(lifespan 只进一次)。
#
# 用法: [ENV=..] bash deploy/hel913-unified/api_ctl.sh start|stop|status
# 环境变量(默认值按部署说明的实例布局):
# HEL913_BASE 实例根目录(含 current/ etc/ data/ logs/)
# HEL913_HTTP HTTP 端口(默认 8360)
# HEL913_HTTPS HTTPS 端口(默认 8361;语音页需要 secure context)
# HEL913_VENV 产品 3.11 venv python(默认 /opt/cybergril-hel879/current/.venv311/bin/python)
# HEL913_CERT / HEL913_KEY 证书路径(默认 /opt/cybergril-voice-certs/ 下既有证书)
set -u
BASE=${HEL913_BASE:-/opt/cybergril-hel913}
CODE=${HEL913_CODE:-$BASE/current}
HTTP=${HEL913_HTTP:-8360}
HTTPS=${HEL913_HTTPS:-8361}
VENV=${HEL913_VENV:-/opt/cybergril-hel879/current/.venv311/bin/python}
CERT=${HEL913_CERT:-/opt/cybergril-voice-certs/cybergril-voice.pem}
KEY=${HEL913_KEY:-/opt/cybergril-voice-certs/cybergril-voice.key}
LOG=$BASE/logs/api.log
PIDF=$BASE/logs/api.pid
PAT="cybergril.*serve_dual"
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"
fi
echo "api stopped"
}
case "${1:-}" in
stop) stop; exit 0 ;;
status)
[ -f "$PIDF" ] && { P=$(cat "$PIDF"); kill -0 "$P" 2>/dev/null && echo "running pid $P" || echo "pid $P not alive"; }
curl -s --max-time 3 "http://127.0.0.1:$HTTP/api/health" && echo " <- health" || echo "health not answering"
exit 0 ;;
esac
stop
cd "$CODE"
set -a
export CYBERGRIL_DB=$BASE/data/companion.db
export CYBERGRIL_SEMANTIC=${HEL913_SEMANTIC:-stub}
export CYBERGRIL_R2_ENABLED=${HEL913_R2:-1}
export CYBERGRIL_MODELS=$BASE/etc/models.yaml
export CYBERGRIL_VOICE_CONFIG=$BASE/etc/voice.yaml
export CYBERGRIL_WEB=$CODE/web/dist
export PYTHONPATH=$CODE/src
set +a
nohup "$VENV" deploy/voice/serve_dual_8360_8361.py \
--http-port "$HTTP" --https-port "$HTTPS" --cert "$CERT" --key "$KEY" \
> "$LOG" 2>&1 &
echo $! > "$PIDF"
echo "api starting (pid $(cat "$PIDF")) http=$HTTP https=$HTTPS"
sleep 6
curl -s --max-time 3 "http://127.0.0.1:$HTTP/api/health" >/dev/null && echo "OK: $HTTP healthy" || { echo "FAIL:"; tail -20 "$LOG"; exit 1; }
curl -sk --max-time 3 "https://127.0.0.1:$HTTPS/api/health" >/dev/null && echo "OK: $HTTPS healthy" || { echo "FAIL $HTTPS:"; tail -20 "$LOG"; exit 1; }