fix(1panel): 安装锁持久化与升级后 1panel-network 校验

防止 nx update 重建容器后丢失安装锁、未接入 1panel-network 导致 MySQL/Redis 不可达。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Deploy
2026-06-06 20:52:13 +08:00
parent 1f5daebeed
commit 107b089b16
5 changed files with 162 additions and 11 deletions
+27 -2
View File
@@ -578,9 +578,17 @@ def _write_env(req: InitDbRequest, secret_key: str, api_key: str, encryption_key
_sync_env_to_persist_volume()
def _persist_dir() -> Path:
raw = os.environ.get("NEXUS_PERSIST_DIR", "/var/lib/nexus").strip() or "/var/lib/nexus"
return Path(raw)
def _persist_env_path() -> Path:
persist_dir = os.environ.get("NEXUS_PERSIST_DIR", "/var/lib/nexus").strip() or "/var/lib/nexus"
return Path(persist_dir) / ".env"
return _persist_dir() / ".env"
def _persist_lock_path() -> Path:
return _persist_dir() / ".install_locked"
def _sync_env_to_persist_volume() -> None:
@@ -599,6 +607,22 @@ def _sync_env_to_persist_volume() -> None:
logger.warning("Failed to sync .env to persist volume: %s", e)
def _sync_lock_to_persist_volume() -> None:
"""Copy /app/.install_locked to nexus-state volume (survives container recreate)."""
if not INSTALL_LOCK.is_file():
return
dest = _persist_lock_path()
try:
dest.parent.mkdir(parents=True, exist_ok=True)
import shutil
shutil.copy2(INSTALL_LOCK, dest)
dest.chmod(0o600)
logger.info("Synced install lock to persist volume %s", dest)
except OSError as e:
logger.warning("Failed to sync install lock to persist volume: %s", e)
def _write_config_json(req: InitDbRequest, api_key: str, site_url: str) -> None:
"""Write shared configuration as JSON (replaces legacy config.php)."""
import json
@@ -837,6 +861,7 @@ def _finalize_install_lock() -> None:
INSTALL_LOCK,
f"Nexus installation locked at {datetime.now(timezone.utc).isoformat()}\n",
)
_sync_lock_to_persist_volume()
if STATE_FILE.exists():
try:
STATE_FILE.unlink()