pkg-cache: host package cache opt-in (default OFF) + origin fallback health check #68

Merged
jknapp merged 3 commits from feat/pkgcache-host-optin into trunk 2026-11-29 15:32:32 +00:00
Owner

Host-side package cache: opt-in (default OFF) with health-checked fallback to the origin.

Where: the host tool lives in this repo (scripts/host/), not in the WHP repo, so the PR is here. WHP will need to ship these scripts and write /etc/pkgcache-host.conf from its server setting, which is outside this PR.

  • Setting /etc/pkgcache-host.conf: PKGCACHE_ENABLED (default 0), PKGCACHE_URL, PKGCACHE_CA. No cache host name is built in.
  • pkgcache-host-repos.sh sync|apply [URL]|revert|status. OFF = stock repos, no timer. ON = cache-first (origin as 2nd baseurl) + pkgcache-host-health.timer (5 min). status shows mode: cache-first | origin-only | off.
  • pkgcache-host-health.sh: probes repomd.xml and .asc through the cache (5 s / 10 s). 2 failures in a row: origin-only; 3 successes: cache-first. Cache+origin both failing is not counted. Origin-only is reversible (marker line #pkgcache-cachefirst ...), touches only managed lines, atomic rename under flock, so dnf is safe.
  • Tests: scripts/tests/pkgcache-host.test.sh (21 cases: default OFF, ON/OFF sync, byte-identical revert from origin-only, thresholds, bad .asc resets streak, unmanaged repos untouched, both-down).

Existing configured hosts (.148, whp01, whp02, TrueSelfCA): nothing changes until this is deployed. They keep working cache-first with origin as 2nd URL, with no health timer and no conf file. Once deployed, sync without a conf file treats them as OFF and reverts them; to keep one on the cache, write the conf with PKGCACHE_ENABLED=1 first. Reverting them is a separate step.

Not installed on any production host. Do not merge: review pending.

🤖 Generated with Claude Code

https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6

Host-side package cache: opt-in (default OFF) with health-checked fallback to the origin. Where: the host tool lives in this repo (`scripts/host/`), not in the WHP repo, so the PR is here. WHP will need to ship these scripts and write `/etc/pkgcache-host.conf` from its server setting, which is outside this PR. - Setting `/etc/pkgcache-host.conf`: `PKGCACHE_ENABLED` (default 0), `PKGCACHE_URL`, `PKGCACHE_CA`. No cache host name is built in. - `pkgcache-host-repos.sh sync|apply [URL]|revert|status`. OFF = stock repos, no timer. ON = cache-first (origin as 2nd baseurl) + `pkgcache-host-health.timer` (5 min). `status` shows `mode: cache-first | origin-only | off`. - `pkgcache-host-health.sh`: probes `repomd.xml` and `.asc` through the cache (5 s / 10 s). 2 failures in a row: origin-only; 3 successes: cache-first. Cache+origin both failing is not counted. Origin-only is reversible (marker line `#pkgcache-cachefirst ...`), touches only managed lines, atomic rename under flock, so dnf is safe. - Tests: `scripts/tests/pkgcache-host.test.sh` (21 cases: default OFF, ON/OFF sync, byte-identical revert from origin-only, thresholds, bad .asc resets streak, unmanaged repos untouched, both-down). Existing configured hosts (.148, whp01, whp02, TrueSelfCA): nothing changes until this is deployed. They keep working cache-first with origin as 2nd URL, with no health timer and no conf file. Once deployed, `sync` without a conf file treats them as OFF and reverts them; to keep one on the cache, write the conf with `PKGCACHE_ENABLED=1` first. Reverting them is a separate step. Not installed on any production host. Do not merge: review pending. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-29 15:24:15 +00:00
- /etc/pkgcache-host.conf setting (PKGCACHE_ENABLED, PKGCACHE_URL, PKGCACHE_CA); no cache
  host is built into the tool. sync/apply/revert/status; status shows mode.
- pkgcache-host-health.sh + 5 min timer (installed only while ON): probes repomd.xml and
  .asc through the cache, 2 failures -> origin-only (reversible marker lines, atomic
  rename under flock), 3 successes -> cache-first. Both-down is not counted.
- scripts/tests/pkgcache-host.test.sh

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-29 15:31:58 +00:00
- health 'mode' took the 30 s flock and mkdir'd the state dir; a held lock gave an empty
  answer, which sync (OFF) read as 'not off' and reverted from the newest backup. mode is
  now read-only and lock-free.
- apply's rewrite() truncated repo files in place and revert used cp -a over the file;
  both now write a temp file and rename(2), so a concurrent dnf never sees half a file.
- apply/revert take the same lock as the health timer so a health run cannot rewrite
  repo files while they edit them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
jknapp added 1 commit 2026-11-29 15:32:19 +00:00
Author
Owner

Independent review: no HIGH/MEDIUM left after fixes. Tests (22 cases, 0 fail) and shellcheck -S warning clean.

Checked:

  • OFF = no cache anywhere: no cache host in code or defaults (only comments name 192.168.1.40 for the CA name constraint); conf is parsed, not sourced, and anything other than exactly PKGCACHE_ENABLED=1 (spaces, trailing comment, CRLF) is OFF. apply with no URL refuses while OFF; sync OFF reverts and removes the timer.
  • Revert byte-identical (restores the newest backup over any changed file; verified from origin-only in the test). Only exactly-managed lines are touched by health; unmanaged repos untouched (test).
  • Flapping: 2 consecutive failures to go origin-only, 3 consecutive successes (incl. a valid .asc) to return; cache+origin both failing is not counted.

Fixed (ebe6355, 1b-docs commit after):

  1. MEDIUM: pkgcache-host-health.sh mode took the 30 s flock and mkdir-ed the state dir. During a health run it printed nothing, sync (OFF) read that as "not off" and reverted the host from the newest backup (stale repo files on a host that was already off). mode is now lock-free and read-only; test added.
  2. MEDIUM: apply wrote repo files in place (truncate+write) and revert used cp -a over them, so a concurrent dnf could read a half file. Both now write a temp file in the same dir and rename(2).
  3. apply/revert now take the same lock as the health timer so a health run cannot rewrite files while they edit.
  4. Docs: added the explicit canary instruction. The canary 192.168.1.148 has no conf; BEFORE the first sync there the operator must write /etc/pkgcache-host.conf with PKGCACHE_ENABLED=1, PKGCACHE_URL=https://192.168.1.40, PKGCACHE_CA=<ca.crt>, otherwise sync reverts it to stock repos. I did not touch the canary.

Notes, unchanged: the EPEL source pattern download.example is pre-existing in trunk; revert restores whole files from the backup (so later manual edits to those repo files are lost, as before).

Independent review: no HIGH/MEDIUM left after fixes. Tests (22 cases, 0 fail) and shellcheck -S warning clean. Checked: - OFF = no cache anywhere: no cache host in code or defaults (only comments name 192.168.1.40 for the CA name constraint); conf is parsed, not sourced, and anything other than exactly `PKGCACHE_ENABLED=1` (spaces, trailing comment, CRLF) is OFF. `apply` with no URL refuses while OFF; sync OFF reverts and removes the timer. - Revert byte-identical (restores the newest backup over any changed file; verified from origin-only in the test). Only exactly-managed lines are touched by health; unmanaged repos untouched (test). - Flapping: 2 consecutive failures to go origin-only, 3 consecutive successes (incl. a valid .asc) to return; cache+origin both failing is not counted. Fixed (ebe6355, 1b-docs commit after): 1. MEDIUM: `pkgcache-host-health.sh mode` took the 30 s flock and mkdir-ed the state dir. During a health run it printed nothing, `sync` (OFF) read that as "not off" and reverted the host from the newest backup (stale repo files on a host that was already off). `mode` is now lock-free and read-only; test added. 2. MEDIUM: apply wrote repo files in place (truncate+write) and revert used `cp -a` over them, so a concurrent dnf could read a half file. Both now write a temp file in the same dir and rename(2). 3. apply/revert now take the same lock as the health timer so a health run cannot rewrite files while they edit. 4. Docs: added the explicit canary instruction. The canary 192.168.1.148 has no conf; BEFORE the first `sync` there the operator must write /etc/pkgcache-host.conf with PKGCACHE_ENABLED=1, PKGCACHE_URL=https://192.168.1.40, PKGCACHE_CA=<ca.crt>, otherwise sync reverts it to stock repos. I did not touch the canary. Notes, unchanged: the EPEL source pattern `download.example` is pre-existing in trunk; revert restores whole files from the backup (so later manual edits to those repo files are lost, as before).
jknapp merged commit 4c988758cc into trunk 2026-11-29 15:32:32 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cloud-hosting-platform/cloud-apache-container#68