Add VPS migration plan for Hermes environment (verified 2026-10-24)

This commit is contained in:
Nikki (wiki profile)
2026-10-24 07:55:58 +01:00
parent 2f3155e7e7
commit b241018464
+132
View File
@@ -0,0 +1,132 @@
# Hermes Environment Migration Plan — VPS → New VPS (Debian 13)
Prepared by Suzi (main agent, verified 2026-10-24). Target: Nikki / personal wiki.
Source evidence: /proc/*/mountinfo, /proc/*/environ, /opt/hermes/docker-compose.yml, /opt/hermes/docker/s6-rc.d/*, /proc/165/env, /opt/data/state/*, /opt/data/config.yaml.
---
## 1. Ground Truth (What Exists Now)
- **Runtime model**: Hermes Agent v0.21.4 (sha 439eb039), installed method = docker.
- **Supervision**: s6-overlay v3 inside container (PID1 = /package/admin/s6/command/s6-svscan /run/service). Container init: /init → /opt/hermes/docker/main-wrapper.sh → s6-setuidgid hermes ....
- **Data volume**: /opt/hermes/data (host ext4 /dev/sda1) bind-mounted → /opt/data (rw). /proc/165 mountinfo line: `8:1 /opt/hermes/data /opt/data rw,relatime - ext4 /dev/sda1 rw,discard`.
- **Image source**: /opt/hermes (image layer) holds Dockerfile, .venv, node_modules, /opt/hermes/docker scripts (main-wrapper.sh, s6-rc.d/, cont-init.d/, stage2-hook.sh, entrypoint-dispatch.sh, docker-compose.yml). Not a bind mount — changes to it inside the container don't survive recreation unless rebuilt/re-committed.
- **Profiles**: MAIN profile = /opt/data (this session). Wiki profile /opt/data/profiles/wiki (isolated state.db, skills/, memories/, bin/, runtime/, backups/).
- **Database files** (verified): state.db (34MB, WAL: .db-shm + .db-wal), kanban.db, shared-state.db, response_store.db, runs_idempotency.db, verification_evidence.db, projects.db. database.journal_mode=wal in config.yaml.
- **Secrets**: /opt/data/.env (mode 600, 26830 bytes), /opt/data/.secrets/ (pve_token, gitea_hermes_token, gitea_admin_token), auth.json, channel_directory.json, .models_dev_cache.etag.
- **Env (PID 165)**: HERMES_HOME=/opt/data, TZ=Europe/London, API_SERVER_KEY (redacted), TELEGRAM_BOT_TOKEN, TELEGRAM_HOME_CHANNEL=8898381145, TELEGRAM_ALLOWED_USERS=8898381145, HERMES_DASHBOARD=1, HERMES_DASHBOARD_HOST=100.91.52.121, HERMES_DASHBOARD_PORT=9119, HERMES_WRITE_SAFE_ROOT=/opt/data, OPENROUTER_API_KEY=sk-or-... .
- **Gateway services** (s6-rc): main-hermes (sleep infinity — placeholder), dashboard (longrun, activates when HERMES_DASHBOARD=1), user bundle empty but per-profile gateways (gateway-default, gateway-wiki) registered at runtime via 02-reconcile-profiles.
- **Dashboard**: binds --host 100.91.52.121 (tailscale IP) --port 9119 --no-open; basic auth (admin + hash + secret); requires auth provider; non-loopback = gate enforced.
- **Telegram bot**: verified working (state: connected, writer_pid 165, updated_at 2026-10-24T01:13:27).
- **MCP servers** (config.yaml): gitea (stdio, binary /opt/data/gitea-mcp, token from .secrets/gitea_hermes_token); proxmox (streamable-http, 127.0.0.1:8765/mcp); homelab (https://port-1.tailc9d943.ts.net/mcp).
- **Tailscale / firewall**: only inbound SSH over tailscale (100.87.191.47 → 192.168.0.0/24 subnet router). tailscale binary not in container PATH; host-level.
- **Proxmox**: host 192.168.0.233 (:8006 API); node prox; PAM token /opt/data/.secrets/pve_token; MCP process PID 186 (/opt/data/proxmox_mcp.py).
- **TUI session** (current chat): PID 23957 (node ui-tui), PID 23967 (python -m tui_gateway.entry), env HERMES_INTERACTIVE=1, HERMES_PTY_HOST=dashboard, HERMES_SCRATCH_DIR=/opt/data/cache/scratch, HERMES_MAX_ITERATIONS=500, HERMES_CWD=/opt/data.
- **Python environment**: /opt/hermes/.venv/bin/python3 (3.13.5); uv installed (system-level, used for lazy-packages); /opt/data/home/ holds .cache/uv/archive-v0/ browser drivers.
- **Lazy packages**: /opt/data/lazy-packages/ (drwxrwxrwx); .python-abi, .lock. Disabled by env HERMES_DISABLE_LAZY_INSTALLS=1.
- **Playwright browsers**: /opt/hermes/.playwright/ (chromium_headless_shell-1243). AGENT_BROWSER_EXECUTABLE_PATH points inside .playwright.
- **Backups**: /opt/data/backups/config/ (.env.pre-docker-migrate.*, config.yaml.good.*). updates.backup_keep=5.
- **Memory**: /opt/data/memories/ (MEMORY.md, USER.md, hermes_notes.md, homelab_notes.md, proxmox_notes.md). Memory char limits: memory 2200, user 1375.
- **Cron**: /opt/data/cron/ (jobs.json, executions.db, notepad.db, usage_audit.jsonl, tickers). Not system cron (/etc/cron.d absent inside container; host-level unknown).
- **Profiles / skills**: /opt/data/profiles/wiki/ (isolated profile: state.db, skills/ (apple, autonomous-ai-agents, creative, devops, ...), memories/, cache/, runtime/). /opt/data/skills/ (main agent skills).
- **Wiki**: /opt/data/wiki/ (git repo, README.md, SCHEMA.md, index.md, entities/, references/, raw/). Profile wiki (isolates writes).
- **Logs**: /opt/data/logs/ (agent.log, gateway.log, errors.log, dashboard-auth.log, gui.log, gateway-exit-diag.log, container-boot.log, process-results/, gateways/default, gateways/wiki, gates/...). Log rotation active.
- **Scratch / workspace**: /opt/data/cache/scratch/ (TMPDIR), /opt/data/workspace/ (persistent workspace files if used).
- **Home / profiles**: /opt/data/home/ (extra user home dir used by uv/browser harness: .cache/uv/archive-v0/, .config/, .npm/, .local/, skills/. Note: /opt/data/home/ and /opt/data/profiles/wiki/ are separate dirs.
- **Firewall**: only inbound SSH over tailscale allowed. Tailscale subnet router 100.87.191.47 forwards 192.168.0.0/24.
---
## 2. Migration Strategy (Resilience-first, not speed)
### 2.1 Design Principles (confirmed with user)
- Both VPS run Debian 13 (same OS version).
- The migration is a data-volume migration + container image recreation/rebuild, not an in-place upgrade (user: "I can't upgrade the VPS").
- No secrets invented. All secrets must be moved by copying /opt/data/.env + .secrets/ + auth.json; never reconstructed by guess.
- Certainty before cutover: verify new environment runs (gateway status, dashboard auth, telegram connected, wiki profile loads, TUI starts) before shutting down old.
- Memory preservation: journal_mode=WAL → when copying, stop container first (or at least pause writes), then copy .db + .db-shm + .db-wal together; open DB handles must not have active writes.
### 2.2 Order of Operations
1. **Prepare new VPS** (host-level): install Docker + containerd, Tailscale, firewall rules (only inbound SSH over tailscale), same network (192.168.0.0/24 reachable via subnet router); create host data dir /opt/hermes/data (empty, same ownership hermes:hermes UID 10000, GID 10000).
2. **Copy persistent volume** /opt/hermes/data (from current host — the bind-mounted source) to new host /opt/hermes/data. Include hidden files (.env, .secrets/, .config/, .local/, .models_dev_cache.etag). Preserve permissions (chmod -R --reference).
3. **Rebuild/re-pull container image**.
- Option A: docker commit current running container (hermes image → hermes-agent:migrated) and docker save → docker load on new host. This preserves .venv, node_modules, /opt/hermes source state exactly.
- Option B: rebuild from /opt/hermes source (Dockerfile, .dockerignore, .npmrc). Risk: .venv may not rebuild identically; node_modules may differ; build takes time.
- Recommendation: Option A (commit/save/load) for certainty, since image-local /opt/hermes includes .venv, .playwright, lazy-packages state references, and stage2 hooks.
4. **Re-run container on new host** using the same docker-compose.yml (from /opt/hermes/docker-compose.yml in image, or extracted from source). Set HERMES_UID / HERMES_GID to match new host user (10000 if hermes user created; else use id -u / id -g of host data owner).
5. **Reconcile profiles** (s6 boot): 02-reconcile-profiles will recreate gateway-default and gateway-wiki services based on last recorded state in /opt/data/profiles/*/ (persistent volume). Verify with hermes gateway status after container starts.
6. **Restart TUI / dashboard / gateway** on new host. Verify:
- gateway status (PID, connected state for telegram + api_server)
- dashboard responds on tailnet IP (new host will have new tailscale IP; config uses HERMES_DASHBOARD_HOST=100.91.52.121 — this must be updated to the new host's tailscale IP or left as 127.0.0.1 for localhost-only access)
- hermes chat / TUI starts (current session verifies this)
- Telegram bot responds (TELEGRAM_HOME_CHANNEL unchanged).
7. **Update firewall / tailscale**:
- New host joins same tailscale tailnet; subnet router (100.87.191.47) must either stay on old host (until migration complete) or be moved to new host. Since user says "I can't upgrade the VPS" — new host should assume subnet router role or user updates router config separately.
- Firewall on new host: allow only inbound SSH over tailscale (same rule); deny other inbound.
8. **Update references / secrets** if needed:
- HERMES_DASHBOARD_HOST → new tailscale IP (or 127.0.0.1 if tunneling via SSH).
- API_SERVER_KEY, TELEGRAM_BOT_TOKEN, OPENROUTER_API_KEY — copy unchanged.
- config.yaml — verify base_url, mcp_servers URLs (proxmox 127.0.0.1:8765 remains valid on new host; homelab URL unchanged; gitea remote unchanged).
9. **Post-cutover cleanup**: once verified for 24+ hours, decommission old VPS. Keep /opt/hermes/data backup snapshot (tar/rsync) for rollback.
---
## 3. Detailed Checklists
### 3.1 Before Migration (Old Host)
- [ ] Confirm old container running: hermes gateway status, hermes dashboard responding, TUI active.
- [ ] Stop writes temporarily: avoid active terminal sessions, stop cron executions (/opt/data/cron/ tick locks present? Check ticker_heartbeat), avoid database mutations.
- [ ] Capture current process state: ps aux, /proc/*/environ for gateway/dashboard, /proc/165/mountinfo.
- [ ] Check database integrity: open .db files? Check .db-shm and .db-wal exist and are non-empty.
- [ ] Verify secrets readable: .env, .secrets/*, .env.pre-docker-migrate.* (backups exist).
- [ ] Create full volume backup: tar -czpf hermes-data-$(date +%F).tar.gz -C /opt/hermes/data . (or rsync -aHAX). Preserve extended attributes, ACLs, hidden files.
- [ ] Note image details: docker inspect hermes (image name, created, container config, env list); docker-compose -f /opt/hermes/docker-compose.yml config. Save to /opt/data/backups/config/.
- [ ] Record profile gateways: check /run/service/ (inside container) or hermes gateway status to confirm gateway-default and gateway-wiki running; verify profiles in /opt/data/profiles/.
### 3.2 During Migration (Data Copy)
- [ ] Verify destination hermes user (UID/GID) exists on new host. If new host UID differs, either remap or recreate /opt/hermes/data with new UID after copy (but this changes .env file ownership — acceptable as long as hermes user in container has read access; container remaps UID via HERMES_UID env at boot via stage2-hook).
- [ ] Copy using rsync -aHAX --progress --stats /opt/hermes/data/ newhost:/opt/hermes/data/ (or scp + tar if rsync unavailable). Preserve timestamps for WAL consistency.
- [ ] Verify hidden files copied: .env, .secrets/, .models_dev_cache.etag, .local/, .npm/, .cache/.
- [ ] After copy: verify files count matches (find . -type f | wc -l), total size (du -sh .), permissions (ls -la on .env and .secrets).
- [ ] Do NOT start new container before verifying data copy integrity.
### 3.3 After Migration (New Host)
- [ ] Pull/load image: docker pull hermes-agent (if image available in registry) or docker load < hermes-agent.tar. Verify image digest (docker images --digests).
- [ ] Rebuild/restart container: docker-compose -f /opt/hermes/docker-compose.yml up -d (after copying docker-compose.yml and Dockerfile context from image or host source). Verify container starts: docker ps, docker logs hermes.
- [ ] Verify s6 services inside container: check /run/service/ contents; verify gateway-default and gateway-wiki registered (after 02-reconcile-profiles completes — may take a few seconds after boot).
- [ ] Verify hermes gateway status: PID running, gateway_state=running, telegram state=connected, api_server state=connected.
- [ ] Verify dashboard: curl -u admin:... or browser access to new host tailnet IP (updated HERMES_DASHBOARD_HOST). Verify auth gate active.
- [ ] Verify TUI: hermes chat (if interactive access available) or check /opt/data/logs/ for TUI gateway entries; verify gateway.pid, gateway_state.json.
- [ ] Verify wiki profile: hermes in profile wiki should load /opt/data/profiles/wiki/; verify /opt/data/profiles/wiki/state.db readable; skills/ intact.
- [ ] Verify Telegram bot: send message to @hermes_scot_bot or check TELEGRAM_HOME_CHANNEL delivery; check /opt/data/logs/gateway.log for updated_at timestamp.
- [ ] Verify MCP connections: gitea-mcp binary runs; proxmox_mcp.py connects to 127.0.0.1:8765 (local to new container); homelab URL reachable via tailscale.
- [ ] Verify database WAL consistency: sqlite3 /opt/data/state.db ".dbinfo" (journal mode); check no .db-shm/.db-wal left orphaned.
- [ ] Verify backups accessible: /opt/data/backups/config/ read; config.yaml.good.* readable; .env.pre-docker-migrate.* preserved.
- [ ] Verify firewall: ufw status / iptables -L (only SSH over tailscale allowed); verify tailscale installed and subnet router configured on new host (if router moved).
- [ ] Verify tailscale: tailscale status shows vps-... (new hostname) connected; tailscale ping to .191 (old router) works (if router stays); tailscale ping to .22 (NAS) and .233 (Proxmox) reaches.
---
## 4. Key Risks / Failure Modes
- **Image recreation failure**: if rebuilt from source instead of committed image, .venv may differ; hermes binary may differ; stage2 hooks may behave differently; recommendation: commit image first.
- **Data copy inconsistency**: WAL files (.db-shm, .db-wal) not copied with .db → DB corruption. Fix: stop container before copying; or verify .db-shm and .db-wal copied and .db not open by another process.
- **Profile reconciliation failure**: gateway-default / gateway-wiki may not register on new container boot if /run/service/ not writable by hermes user (stage2 hook 015-supervise-perms handles this — must run before 02-reconcile-profiles). Verify after boot.
- **Dashboard host mismatch**: HERMES_DASHBOARD_HOST set to old tailscale IP (100.91.52.121). If new host has different IP, dashboard will bind to old (non-existent) address. Fix: update .env or docker-compose env override before start; or bind to 127.0.0.1 and tunnel.
- **Secret exposure during copy**: .env and .secrets/ must be copied over secure channel (SSH tunnel, scp, encrypted tar). Do not use unencrypted cloud storage.
- **Tailscale / firewall**: new host needs tailscale auth before any remote access; confirm tailscale auth, tailscale up, firewall rules applied before cutting over.
- **Profile wiki isolation**: /opt/data/profiles/wiki/ must be copied intact; verify .git/ (repo); verify no .git conflicts; verify WIKI_PATH=/opt/data/wiki reference intact.
- **Lazy packages / node_modules**: /opt/data/home/.cache/uv/archive-v0/ contains browser harness binaries; verify these binaries work on new Debian 13 host (glibc compatibility) or rebuild if needed.
- **Memory pressure (user's reason for move)**: new VPS should have more RAM. Monitor free -m on new host after boot; check container memory usage (docker stats hermes); adjust container_memory=5120 in config if needed.
---
## 5. References to Existing Docs / Evidence
- /opt/hermes/docker-compose.yml (container definition, services gateway + dashboard, network_mode=host, volume ~/.hermes:/opt/data — note: host path is /opt/hermes/data in this environment).
- /opt/hermes/docker/s6-rc.d/ (service definitions: main-hermes, dashboard, user contents, dependencies).
- /opt/hermes/docker/cont-init.d/ (01-hermes-setup, 02-reconcile-profiles, 015-supervise-perms — explains profile reconciliation and s6 ownership).
- /proc/165/environ (gateway env: HERMES_HOME, TELEGRAM_*, OPENROUTER_API_KEY, HERMES_DASHBOARD_HOST).
- /proc/165/mountinfo (bind mount /opt/hermes/data → /opt/data).
- /opt/data/config.yaml (model aliases, database WAL, runtime limits, mcp_servers, telegram config, dashboard config, memory/cron/backups settings).
- /opt/data/logs/gateway-state.json (current gateway PID 165, argv, phase running, telegram state connected, api_server connected).
- /opt/data/state.db + siblings (database files).
- /opt/data/backups/config/ (previous .env and config.yaml backups — backup before migration).
- /opt/hermes/docker/stage2-hook.sh (container boot logic; references user remapping, profile reconciliation, with-contenv, s6-setuidgid).
- Memory notes: /opt/data/memories/, memory profiles (/opt/data/profiles/wiki/memories/ or /opt/data/profiles/wiki/state.db).
- Wiki profile: /opt/data/profiles/wiki/.
---
## 6. Actions After Writing This Plan
- Deliver this file (/opt/data/migration-plan.md) to Nikki (wiki profile: /opt/data/profiles/wiki/) for ingestion into /opt/data/wiki/hermes/personal-wiki/ or /opt/data/wiki/entities/.
- Confirm with Nikki that the plan has been saved; verify WIKI_PATH=/opt/data/wiki is intact; check index.md or SCHEMA.md for ingestion rules.
- Once Nikki confirms ingestion, proceed with Step 1 (Prepare new VPS) at user's direction. Do NOT start new container before user confirms.