31 lines
1.5 KiB
Bash
31 lines
1.5 KiB
Bash
#!/bin/bash
|
|
# 生产环境启动(8010,生产数据 data/)——dev_start 的对照脚本,生产平时由 launchd/guard 守护,此脚本用于手动收敛
|
|
set -e
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
export YAWAN_ENV=prod
|
|
# Fail fast when the external data disk is disconnected or nearly full. This
|
|
# prevents accidentally starting against an empty local ``server/data`` path.
|
|
bash "$ROOT/scripts/check_storage.sh"
|
|
# 可选生产配置(不提交密钥):复制 .env.production.example 为 .env.production 后填写。
|
|
if [ -f "$ROOT/.env.production" ]; then
|
|
set -a
|
|
. "$ROOT/.env.production"
|
|
set +a
|
|
fi
|
|
bash /tmp/restart_one.sh 2>/dev/null || {
|
|
# Older detached launches used ``python -c ... uvicorn.run(...port=8010)``
|
|
# and therefore escaped the old uvicorn-only pattern. Stop every process
|
|
# serving this port, then reap matching detached command lines as well.
|
|
pids="$(lsof -tiTCP:8010 -sTCP:LISTEN 2>/dev/null || true)"
|
|
if [ -n "$pids" ]; then kill $pids 2>/dev/null || true; fi
|
|
pkill -f "(uvicorn.*8010|port=8010).*app\.main" 2>/dev/null || true
|
|
sleep 1
|
|
pids="$(lsof -tiTCP:8010 -sTCP:LISTEN 2>/dev/null || true)"
|
|
if [ -n "$pids" ]; then kill -9 $pids 2>/dev/null || true; fi
|
|
cd "$ROOT/server"
|
|
PY=.venv/bin/python
|
|
nohup env YAWAN_ENV=prod "$PY" -m uvicorn app.main:app --host 127.0.0.1 --port 8010 >> /tmp/yawan-uvicorn.log 2>&1 &
|
|
sleep 3
|
|
}
|
|
curl -s -m 5 --noproxy '*' -o /dev/null -w "prod health: %{http_code}\n" "http://127.0.0.1:8010/api/health"
|