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

- /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
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-29 07:23:46 -08:00
1 parent a971412243
commit b28e561387
5 files changed
+361 -30

No files matched your search

+36 -12
View File
@@ -217,17 +217,44 @@ Applied to every job here (Build-and-Push, FPM, Shared-httpd, Shared-OLS, LiteSp
The script is canonical here (`.gitea/scripts/resolve-base-image.sh`); other repos
carry byte-identical copies.
## WHP hosts (`scripts/host/pkgcache-host-repos.sh`)
## WHP hosts (`scripts/host/pkgcache-host-repos.sh`) — opt-in, default OFF
`pkgcache-host-repos.sh apply https://192.168.1.40` does the following:
- backs up every `/etc/yum.repos.d/*.repo` to `/root/pkgcache-repo-backup-<UTC>/`;
- installs the name-constrained CA as a system anchor;
- rewrites the AlmaLinux, EPEL and Remi sections to `baseurl=<cache>/... <origin>/...`;
- comments out mirrorlist/metalink in those sections;
- sets `gpgcheck=1`, plus `repo_gpgcheck=1` for AlmaLinux and Remi.
The package cache is **not** part of the stock WHP setup. A host uses the
distro repos unless its server setting turns the cache on. The setting is
`/etc/pkgcache-host.conf` (template: `scripts/host/conf.example`):
`revert [DIR]` restores byte-identical files (verified on AL9 and AL10) and
removes the anchor. `status` shows the current state.
```
PKGCACHE_ENABLED=0 # 1 = use the cache; absent file = off
PKGCACHE_URL=https://<cache host>
PKGCACHE_CA=/path/to/ca.crt # default: pkg-cache-ca.crt next to the script
```
No cache host name is built into the tool or the defaults.
- `pkgcache-host-repos.sh sync` makes the host match the setting: ON runs `apply` and installs the health timer, OFF runs `revert` and removes it.
- `apply [URL]` (URL defaults to `PKGCACHE_URL`; without a URL it refuses while the setting is OFF):
- backs up every `/etc/yum.repos.d/*.repo` to `/root/pkgcache-repo-backup-<UTC>/`;
- installs the CA as a system anchor;
- rewrites the AlmaLinux, EPEL and Remi sections to `baseurl=<cache>/... <origin>/...`;
- comments out mirrorlist/metalink in those sections;
- sets `gpgcheck=1`, plus `repo_gpgcheck=1` for AlmaLinux and Remi;
- installs and enables `pkgcache-host-health.timer`.
- `revert [DIR]` restores byte-identical files (verified on AL9 and AL10), removes the anchor and the timer, and works from either mode below.
- `status` shows the setting, the **mode** (`cache-first`, `origin-only`, `off`), the timer and the health counters.
**Health check** (`pkgcache-host-health.sh`, timer every 5 min, only while ON). It fetches
`repodata/repomd.xml` and `repomd.xml.asc` of a managed repo through the cache (5 s connect, 10 s total;
HTTP 200, non-empty, a real PGP signature). The `.asc` is what broke on 2026-11-26.
- 2 failures in a row: the managed lines become origin-only. The cache-first line stays above as `#pkgcache-cachefirst baseurl=...`, so the change is exactly reversible.
- 3 successes in a row: cache-first again.
- If the origin fails the same probe, the host or the internet is down, not the cache: nothing is counted.
- Only lines of the exact managed shape are touched. Each file is rewritten to a temp file in the same directory and `rename(2)`d under a lock, so a running dnf sees the old or the new file, never half of one.
- Transitions are logged to the journal (`journalctl -t pkgcache-host-health`).
**Hosts already configured by the old tool** (before the setting existed) keep working: their
repos are already cache-first with the origin as 2nd URL. They have no health timer and no
`/etc/pkgcache-host.conf`, so `sync` treats them as OFF and would revert them. To keep them
on the cache, write the config with `PKGCACHE_ENABLED=1` first. To take them off, run `revert`.
**Why not "cache first, mirrorlist as fallback":** measured on AL10, with
mirrorlist/metalink left in place dnf **ignores `baseurl` completely** (0 cache
@@ -244,9 +271,6 @@ requests). The origin as second baseurl is the fallback dnf really performs.
| cache **down** (nginx stopped): makecache --refresh / download | rc=0 **16 s** / rc=0 24 s, served by origin |
| cache **silently dropped** (iptables DROP): makecache --refresh / download | rc=0 **225 s** / rc=0 59 s (dnf's 30 s connect timeout per attempt) |
**Datacenter hosts** (whp01, whp02, sdbees, TrueSelfCA) cannot reach
192.168.1.40 and are **not configured**. That needs CT130 on NetBird (see the
report: setup key / route pending).
## Operating the cache (CT130)