fix(deploy): 复核修正——补齐 /downloads/ APK 路由并加固切换脚本 (HEL-552)

- host-nginx/jxd.jinniu.ink.conf:线上 jxd-edge 实际配置里有 /downloads/ 路由
  (HEL-279 验收后现场热修,仓库未同步),新模板漏迁会导致已交付验收链接
  /downloads/jinxunda-android-test-1.0.9.apk 失效。补齐该路由,占位符
  __JXD_DOWNLOADS_DIR__ 由切换脚本替换;另加 proxy_cache off 防止宝塔
  http{} 级全局 proxy_cache 缓存 API/WebSocket 响应;http2 改用独立指令。
- docker-compose.edge-fallback.yaml:补 downloads 只读挂载,保证回滚后下载可用。
- deploy/public/nginx.conf:与线上运行配置逐字节对齐(已 diff 验证一致)。
- switch-to-host-nginx.sh:裸 pgrep -x nginx 会被宿主机上其他 nginx 容器
  (solsum 首页容器)误报,导致对已停止的宝塔 Nginx 执行 reload 必然失败
  且不触发回滚、80/443 无人监听。改为按 pidfile 判定系统 Nginx 本尊,
  start/reload 失败立即自动回滚。
- README.md:修正 APK 下载现状描述(原文称线上无下载路由,与实际不符)。

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
总工
2026-09-14 17:22:42 +08:00
co-authored by multica-agent
parent 354495ec78
commit c9e8e113d0
5 changed files with 63 additions and 14 deletions
+20 -6
View File
@@ -9,6 +9,7 @@
# HOST_NGINX_VHOST_DIR 站点配置目录(宝塔: /www/server/panel/vhost/nginx)
# HOST_NGINX_BIN nginx 可执行文件,用来做 -t 语法检查
# HOST_NGINX_INIT initscript,用来启动/重载(宝塔一般装了 /etc/init.d/nginx)
# HOST_NGINX_PIDFILE 系统 Nginx 的 pid 文件(宝塔: /www/server/nginx/logs/nginx.pid)
set -euo pipefail
cd "$(dirname "$0")/.."
REPO_DIR="$(pwd)"
@@ -16,10 +17,20 @@ REPO_DIR="$(pwd)"
SITE_CONF_SRC="deploy/public/host-nginx/jxd.jinniu.ink.conf"
SITE_CONF_NAME="jxd.jinniu.ink.conf"
ACME_WEBROOT="${REPO_DIR}/deploy/public/acme"
DOWNLOADS_DIR="${REPO_DIR}/deploy/public/downloads"
HOST_NGINX_VHOST_DIR="${HOST_NGINX_VHOST_DIR:-/www/server/panel/vhost/nginx}"
HOST_NGINX_BIN="${HOST_NGINX_BIN:-/www/server/nginx/sbin/nginx}"
HOST_NGINX_INIT="${HOST_NGINX_INIT:-/etc/init.d/nginx}"
HOST_NGINX_PIDFILE="${HOST_NGINX_PIDFILE:-/www/server/nginx/logs/nginx.pid}"
# 判断"系统 Nginx 本尊"是否在跑,只认 pidfile 里的进程。
# 不能用裸 pgrep -x nginx:宿主机上还有别的 nginx 容器(如 solsum 首页容器的
# nginx -g daemon off),它们会让 pgrep 误报"系统 Nginx 已在跑",导致对已停止的
# 系统 Nginx 执行 reload(必然失败),80/443 陷入无人监听。
nginx_running() {
[ -f "$HOST_NGINX_PIDFILE" ] && kill -0 "$(cat "$HOST_NGINX_PIDFILE" 2>/dev/null)" 2>/dev/null
}
BACKUP_DIR="/root/jxd-nginx-switch-backup-$(date +%Y%m%d%H%M%S)"
@@ -41,10 +52,12 @@ if [ -f "/etc/letsencrypt/renewal/jxd.jinniu.ink.conf" ]; then
fi
echo "备份完成: $BACKUP_DIR"
echo "== 2/5 生成站点配置(替换 ACME webroot 占位符)=="
echo "== 2/5 生成站点配置(替换 ACME webroot / downloads 占位符)=="
mkdir -p "$ACME_WEBROOT"
TMP_CONF="$(mktemp)"
sed "s#__JXD_ACME_WEBROOT__#${ACME_WEBROOT}#g" "$SITE_CONF_SRC" > "$TMP_CONF"
sed -e "s#__JXD_ACME_WEBROOT__#${ACME_WEBROOT}#g" \
-e "s#__JXD_DOWNLOADS_DIR__#${DOWNLOADS_DIR}#g" \
"$SITE_CONF_SRC" > "$TMP_CONF"
if [ ! -d "$HOST_NGINX_VHOST_DIR" ]; then
echo "站点目录 $HOST_NGINX_VHOST_DIR 不存在,请先用 HOST_NGINX_VHOST_DIR= 指定正确路径" >&2
@@ -67,13 +80,14 @@ docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yam
docker compose -f docker-compose.yaml -f deploy/public/docker-compose.public.yaml \
-f deploy/public/docker-compose.edge-fallback.yaml rm -f edge 2>/dev/null || true
if pgrep -x nginx >/dev/null 2>&1; then
"$HOST_NGINX_INIT" reload || systemctl reload nginx
if nginx_running; then
"$HOST_NGINX_INIT" reload || systemctl reload nginx || rollback
else
"$HOST_NGINX_INIT" start || systemctl start nginx
"$HOST_NGINX_INIT" start || systemctl start nginx || rollback
fi
if ! pgrep -x nginx >/dev/null 2>&1; then
sleep 1
if ! nginx_running; then
rollback
fi