openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Decommission ol-home

Open cdrini opened this issue 5 years ago • 8 comments

Our old ol-home server has an nginx running that proxies to ol-home0. We likely don't need this anymore? But if I recall correctly, when we tried to update all our docker containers to point to ol-home0, something didn't work. Investigation needed.

To close:

  • [ ] 1) check all occurrences of ol-home in olsystem and openlibrary. Change any occurrence of ol-home:7000 to ol-home0:7000.
    • [x] git grep ol-home --> All instances are ol-home0 except file docker/ol-home-start.sh which looks OK.
    • [x] #4426
    • [x] #7816 (pull request)
    • [x] internetarchive/olsystem#122
    • [x] internetarchive/olsystem#178
    • [x] internetarchive/olsystem#180 Done in the cron-jobs Docker container.
    • [x] #7817
    • [ ] internetarchive/olsystem#174
  • [x] 2) Patch Deploy this to our servers as a test and restart docker containers one by one (See deployment guide). If everything works, woohoo! Test borrowing/editing works.
  • [ ] 3) Try removing the proxy in olsystem/etc/nginx/sites-available/infobase.conf on the old server ol-home (see git diff in that server/repo) and restarting nginx on that server. If everything works, woohoo! We're done.
    • [x] Did
    • [x] Undid because of #7920

Stakeholders

@mekarpeles

cdrini avatar May 05 '21 22:05 cdrini

Why is macOS Control Center listening on ports 5000 and 7000? https://developer.apple.com/forums/thread/682332

I expect Apple to switch to less controversial ports in the future but if other macOS users bump into this, they can disable AirPlay Receiver to get access to port 7000.

cclauss avatar Dec 05 '21 02:12 cclauss

To re-iterate the problem, if ol-web[0-2] or ol-covers0 need infogami (i.e. ol-home) and they make a request currently to ol-home which routes to ol-home0 to get around an issue where... currently containers on ol-home0 also need to hit ol-home in order to then get into ol-home0 infobase.

In this setup, ol-web[0-2] and ol-covers0 don't actually need ol-home, it's ol-home0 that do.

So the solution is to have everything use ol-home but for any containers on ol-home0 to overwrite (via an ENV variable or logic in ol config script) the infobase_server from e.g. ol-home:7000 (i.e. the server) to infobase:7000 (i.e. the docker container).

Once we do this, we can decomission ol-home (which just exists for ol-home0 to get around the host / docker contention).

mekarpeles avatar Dec 05 '24 20:12 mekarpeles

ol-home prompt for Claude; docker container on ol-home0 tries to make a request to ol-home0.us.archive.org (creates a network circle). Desired end-state is for ol-web* and ol-www0 to use ol-home0 w/o ol-home as a proxy. Web heads are fine. Containers on ol-home0 (e.g. infobase dies because it tries to make requests to ol-home0 – i.e. its own host). Infobase could hit “localhost” or the docker-compose service… But this would break from web-heads. We only have one field in yml (which doesn’t work for both ol-web[0-3] and ol-home0.

We could have an env override for any container that runs on ol-home0 (e.g. solr-updater, import-bot, crons, etc)

mekarpeles avatar Jul 13 '26 19:07 mekarpeles

Discovery Trail (Ada)

  • Correction: internetarchive/olsystem#174 is CLOSED, not open — closed unmerged 2024-02-10. It attempted a blanket ol-home→ol-home0 rename across olsystem, including infobase_server: "ol-home0:7000". @cdrini blocked it: "we can't merge this until we fix those networking issues; otherwise things will break during the next deploy" — i.e. the same self-referential-host problem would just move from ol-home to ol-home0. This is why it stalled: the fix needs to be host-conditional, not a single shared value change.
  • Confirmed: infobase_server is read in exactly one place at the Python layer — infogami.load_config() sets config.infobase_server from a plain yaml.safe_load (no env-var interpolation exists today). Every consumer funnels through openlibrary/config.py:load_config(): the main app (openlibrary/plugins/openlibrary/connection.py), scripts/solr_updater/solr_updater.py, scripts/affiliate_server.py, and scripts/manage-imports.py (import-bot). Single natural chokepoint for a fix.
  • Confirmed existing hook: compose.production.yaml sets hostname: "$HOSTNAME" on every service; scripts/deployment/deploy.sh's ssh_docker_compose() already threads the real per-host $HOSTNAME (e.g. literally ol-home0 when run there) into docker compose at deploy time — zero new olsystem files needed. Since Compose's hostname: sets the container's actual UTS-namespace hostname, socket.gethostname() inside any prod container today already reflects the real host it's running on.
  • ol-home0-profile services in compose.production.yaml: solr_haproxy, cron-jobs, infobase, infobase_nginx, affiliate-server, solr-updater, importbot, monitoring. Of these, cron-jobs, affiliate-server, solr-updater, importbot act as Infobase clients and are the ones affected.
  • olsystem/etc/openlibrary.yml:339 and etc/coverstore.yml:65 (trusted-host allowlists) already list both ol-home:7000 and ol-home0:7000 — no change needed there.

Plan to follow, favoring the existing $HOSTNAME/hostname mechanism over any new per-host olsystem file, per your 2026-07-13 comment.

openlibrary-bot avatar Jul 17 '26 22:07 openlibrary-bot

Validation Plan (Ada) — smallest atomic fix for the "left" part of this issue (host-level infobase_server override; the historical solr/rsync/cron cleanup items are already done).

Approach

Add a single, host-conditional override for infobase_server, applied at config-load time in openlibrary/config.py::load_config() — the one chokepoint every consumer (main app's OLConnection, solr_updater.py, affiliate_server.py, manage-imports.py/import-bot) already goes through.

Rule: if the container's own hostname is ol-home0 (or ol-home0.*), always talk to Infobase via the docker-compose service name infobase:7000 (same-network hop, no external host, no loop) — regardless of what infobase_server says in the shared olsystem/etc/openlibrary.yml. Every other host is unaffected and keeps reading infobase_server as-is (ol-home:7000 today).

This needs zero new env vars, zero olsystem changes, zero compose/deploy.sh changes — it reuses hostname propagation that's already fully working today: compose.production.yaml's existing hostname: "$HOSTNAME" + deploy.sh's existing per-host $HOSTNAME threading. I confirmed empirically (docker run --hostname ol-home0-test ...) that Docker's hostname: directive sets both socket.gethostname() and a HOSTNAME env var inside the container, so this is a pure application-layer change with no new infra plumbing. It satisfies your "no per-host olsystem file" constraint by construction — the shared yaml value never needs to change.

Files to modify

  • openlibrary/config.py — add _is_ol_home0() + apply override right after infogami.load_config(config_file).
  • openlibrary/tests/test_config.py (new) — unit tests below.

Tests to write (input → expected output)

  1. hostname=ol-home0, infobase_server=ol-home:7000 → override applies → infobase:7000
  2. hostname=ol-home0.us.archive.org (FQDN form) → override still applies → infobase:7000
  3. hostname=ol-web1 → no override → stays ol-home:7000
  4. hostname=arbitrary dev/CI container id → no override → unaffected (dev already uses infobase:7000 directly, per conf/openlibrary.yml)
  5. no infobase_server key set at all → no-op, no crash

Success criteria

  • Automated: new unit tests + full existing suite green in Docker.
  • Manual, locally verifiable: run local docker-compose with HOSTNAME=ol-home0 simulated, confirm the resolved infobase_server inside a container is infobase:7000; confirm it's unaffected with HOSTNAME unset/other.
  • NOT locally verifiable — flagging explicitly per your ask: real behavior on the actual ol-home0 box against the real Infobase, actual elimination of the network loop against the real ol-home nginx proxy, and interaction with real solr-updater/import-bot/cron traffic. Per the issue's own step 2, this needs you (or someone with host access) to patch-deploy and restart containers one by one, and test borrowing/editing on real infra. I will not mark this ready assuming that's true — it'll be called out as a required manual step.

Out of scope for this PR

  • Removing ol-home's nginx proxy or decommissioning the box itself (issue checklist item 3) — only after the override is verified on real infra.
  • Any olsystem changes — not needed for this approach.
  • Trimming ol-home:7000 from the trusted-host allowlists (olsystem/etc/openlibrary.yml:339, etc/coverstore.yml:65) — leave until ol-home is actually gone.

Risks

  • If the real ol-home0 box's hostname string differs from what I'm assuming (short name vs FQDN, casing), the override silently no-ops and the loop persists — fails safe, but worth a sanity check in review.
  • This is production request-routing; I don't have host access and won't attempt SSH there — real-host verification remains an open, explicit manual step before this issue can close.

Favors your stated preference for the existing $HOSTNAME deploy-time mechanism over a new per-host olsystem file. Awaiting approval before writing any code.

openlibrary-bot avatar Jul 17 '26 22:07 openlibrary-bot

Note (Ada): AGENTS.md's standard phase-gate label, `Needs: Approval`, doesn't exist in this repo's label set. Impact: None to this issue's progress — used the closest real equivalent, `Needs: Staff Decision` ("Issues that are blocked on a staff member's decision"), instead. Resolution: Applied `Needs: Staff Decision`. Updating `ada/AGENTS.md` to reference the correct label name so future Adas don't hit the same failed edit.

openlibrary-bot avatar Jul 17 '26 22:07 openlibrary-bot

Proceed — I'm fine with this moving forward without a separate formal review cycle, per the same call on pr-12831. The plan posted above (host-conditional infobase_server override, keyed on hostname) looks right to me; go ahead and implement, verify what you can locally, and flag anything that needs real host access before merge.

mekarpeles avatar Jul 20 '26 17:07 mekarpeles

This should be merged, the last step is checking whether the server has any files on it that are necessary to keep around and then turning it off

mekarpeles avatar Jul 29 '26 01:07 mekarpeles