fix(deploy): 上帝菜单巡检第二轮 — 全新安装卷冲突与验收修正

FRESH 清除 nexus-state 旧锁;PENDING=1 时 entrypoint 不恢复旧 env;验收脚本已安装期望 404。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Deploy
2026-06-06 21:53:03 +08:00
parent baacdb0252
commit 687e059a86
5 changed files with 104 additions and 5 deletions
+32 -2
View File
@@ -437,7 +437,10 @@ rollback_compose_upgrade() {
warn "健康检查失败,回滚至上一镜像..."
docker tag nexus-prod-nexus:rollback nexus-prod-nexus:latest 2>/dev/null || true
compose_cmd "$root" up -d --no-build --remove-orphans
verify_nexus_1panel_network "$root" || true
if ! verify_nexus_1panel_network "$root"; then
error "回滚后仍未接入 1panel-network"
return 1
fi
return 0
fi
warn "无回滚镜像 nexus-prod-nexus:rollback,跳过自动回滚"
@@ -884,11 +887,34 @@ purge_legacy_bundled_services() {
done
}
reset_nexus_state_volume_for_fresh() {
local vol
vol="$(docker volume ls -q --filter name=nexus-state 2>/dev/null | head -1 || true)"
[[ -n "$vol" ]] || return 0
warn "全新安装:清除 nexus-state 卷内旧 .env / .install_locked"
docker run --rm -v "${vol}:/data" alpine:3.19 \
sh -c 'rm -f /data/.env /data/.install_locked' 2>/dev/null || true
}
restore_install_wizard_html_in_container() {
local cname="$1"
[[ -n "$cname" ]] || return 0
docker exec "$cname" sh -c '
rm -f /app/.install_locked
if [ -f /app/web/app/install.html.bak ] && [ ! -f /app/web/app/install.html ]; then
mv /app/web/app/install.html.bak /app/web/app/install.html
fi
' 2>/dev/null || true
}
compose_up() {
local root="$1"
local root="$1" cname
save_host_profile "$root"
purge_legacy_bundled_services "$root"
sync_1panel_service_hosts "$root"
if [[ "$FRESH_INSTALL" == true ]]; then
reset_nexus_state_volume_for_fresh
fi
if has_1panel_network; then
info "已接入 1panel-networkMySQL/Redis 使用 1Panel 容器名互联)"
fi
@@ -896,6 +922,10 @@ compose_up() {
info "构建并启动(首次约 1020 分钟)..."
compose_cmd "$root" up -d --build --remove-orphans
verify_nexus_1panel_network "$root" || return 1
if [[ "$FRESH_INSTALL" == true ]]; then
cname="$(nexus_container_name)"
restore_install_wizard_html_in_container "$cname"
fi
}
archive_install_wizard_in_container() {
+16 -1
View File
@@ -201,8 +201,18 @@ ops_status() {
port="$(nexus_publish_port "$NEXUS_ROOT")"
h=$(curl -sf "http://127.0.0.1:${port}/health" 2>/dev/null || echo "fail")
info "/health → ${h}"
local cname
cname="$(nexus_container_name 2>/dev/null || true)"
code=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:${port}/app/install.html" 2>/dev/null || echo "000")
info "/app/install.html → HTTP ${code}"
if [[ -n "$cname" ]] && nexus_container_has_install_lock "$cname"; then
if [[ "$code" == "404" ]]; then
info "/app/install.html → 已归档 (HTTP 404)"
else
warn "/app/install.html → 应已归档但 HTTP ${code}"
fi
else
info "/app/install.html → HTTP ${code}"
fi
}
ops_backup_now() {
@@ -269,6 +279,11 @@ EOF
1) menu_install ;;
2)
require_root
if is_stack_installed; then
warn "将执行全新安装(清除 nexus-state 卷内旧配置并重建容器)"
read -r -p "确认继续? [y/N]: " fresh_ok
[[ "$fresh_ok" == "y" || "$fresh_ok" == "Y" ]] || continue
fi
exec bash "${NX_DIR}/install-nexus-fresh.sh" --profile "${NEXUS_PROFILE:-2c8g}"
;;
3)
+15 -2
View File
@@ -19,6 +19,7 @@ warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
info() { echo -e " $*"; }
FAILURES=0
INSTALL_WIZARD_ARCHIVED=false
require_root() {
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
@@ -176,8 +177,11 @@ check_install_mode() {
else
pass "/app/.env 不存在(安装模式 OK"
fi
if docker exec "$NEXUS_CONTAINER" test -f /app/.install_locked 2>/dev/null; then
fail "已锁定安装向导 — 应访问 /app/ 登录"
if docker exec "$NEXUS_CONTAINER" test -f /app/.install_locked 2>/dev/null \
|| docker exec "$NEXUS_CONTAINER" test -f /var/lib/nexus/.install_locked 2>/dev/null \
|| docker exec "$NEXUS_CONTAINER" test -f /app/web/app/install.html.bak 2>/dev/null; then
pass "安装向导已锁定/已归档 — 应访问 /app/ 登录"
INSTALL_WIZARD_ARCHIVED=true
fi
local hosts_json
hosts_json="$(docker exec "$NEXUS_CONTAINER" cat /app/web/data/1panel-hosts.json 2>/dev/null || true)"
@@ -199,6 +203,15 @@ check_http_local() {
return 1
fi
code="$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8600/app/install.html 2>/dev/null || echo 000)"
if [[ "${INSTALL_WIZARD_ARCHIVED:-false}" == true ]]; then
if [[ "$code" == "404" ]]; then
pass "/app/install.html 已归档 → HTTP 404"
else
fail "/app/install.html 应已归档但 HTTP $code"
info "修复: nx update(会执行 archive_install_wizard_in_container"
fi
return 0
fi
if [[ "$code" == "200" ]]; then
pass "/app/install.html → HTTP 200"
else
+14
View File
@@ -46,6 +46,9 @@ s.close()
}
restore_persisted_install_lock() {
if [ "${NEXUS_INSTALL_WIZARD_PENDING:-0}" = "1" ]; then
return 0
fi
PERSIST_LOCK="${PERSIST_DIR}/.install_locked"
if [ -f "${PERSIST_LOCK}" ] && [ ! -f /app/.install_locked ]; then
cp "${PERSIST_LOCK}" /app/.install_locked
@@ -55,6 +58,14 @@ restore_persisted_install_lock() {
}
archive_install_wizard_if_locked() {
if [ "${NEXUS_INSTALL_WIZARD_PENDING:-0}" = "1" ]; then
rm -f /app/.install_locked "${PERSIST_DIR}/.install_locked" 2>/dev/null || true
if [ -f /app/web/app/install.html.bak ] && [ ! -f /app/web/app/install.html ]; then
mv /app/web/app/install.html.bak /app/web/app/install.html
echo "entrypoint: restored install.html from .bak (wizard pending)"
fi
return 0
fi
if [ ! -f /app/.install_locked ] && [ ! -f "${PERSIST_DIR}/.install_locked" ]; then
return 0
fi
@@ -72,6 +83,9 @@ archive_install_wizard_if_locked() {
}
restore_persisted_env() {
if [ "${NEXUS_INSTALL_WIZARD_PENDING:-0}" = "1" ]; then
return 0
fi
if [ ! -f "${PERSIST_ENV}" ]; then
return 0
fi
@@ -0,0 +1,27 @@
# nx 上帝菜单巡检第二轮修补
| 项 | 内容 |
|----|------|
| 日期 | 2026-06-06 |
| 动机 | 继续巡检 deploy/nx 链路:全新安装与持久化卷冲突、验收脚本误判、回滚网络 |
## 变更摘要
1. **全新安装 vs nexus-state 卷**`FRESH_INSTALL` 时清除卷内旧 `.env`/`.install_locked``NEXUS_INSTALL_WIZARD_PENDING=1` 时 entrypoint 不恢复旧配置、从 `.bak` 恢复 `install.html`
2. **回滚**`rollback_compose_upgrade` 在仍未接入 `1panel-network` 时返回失败。
3. **验收脚本**`verify-1panel-install-wizard.sh` 已安装时期望 `install.html` → 404。
4. **nx 菜单**`ops_status` 区分已归档;菜单 `[2]` 全新安装对已安装栈二次确认。
## 涉及文件
- `docker/entrypoint.sh`
- `deploy/nexus-1panel.sh`
- `deploy/nx`
- `deploy/verify-1panel-install-wizard.sh`
## 验证
```bash
bash -n deploy/nx && bash -n deploy/nexus-1panel.sh && bash -n docker/entrypoint.sh
bash deploy/verify-1panel-install-wizard.sh # 已安装应 PASS install.html 404
```