Compare commits

..
Author SHA1 Message Date
shadowdaoandClaude Sonnet 5.5 bd685f72fb pkg-cache selfcheck: re-check nginx started by something else while stopped; fix test fake is-active
The marker branch left a manually/otherwise restarted nginx running unchecked
while the disks were still bad. Now a running nginx with our marker present is
judged like normal operation (stopped again if unhealthy). The test systemctl
fake always returned 0 for is-active, hiding the admin-stopped branch; fixed,
and the tests now pin PKGCACHE_SERVICES and cover the empty-list case.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-29 07:30:52 -08:00
shadowdaoandClaude Sonnet 5.5 8107b29e14 feat(pkg-cache): CT130 self-check timer (stop nginx+registry when the cache is unhealthy)
pkg-cache/pkgcache-selfcheck.{sh,service,timer}: every 60 s check rw mounts, write+fsync+delete
and a fresh fetch through nginx; on failure stop nginx + registry so clients fail over to the
origin instantly (connection refused); restart after 3 healthy runs + nginx -t. Never fsck.
Alert = Uptime Kuma monitors 53/54 going DOWN. Deployed on CT130 2026-11-29.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-29 07:23:46 -08:00
jknapp a971412243 Merge pull request 'mariadb client: ssl-verify-server-cert=0 drop-in (cac, cac-fpm)' (#66) from fix/client-ssl-verify-off into trunk
Cloud Apache Container / plan (push) Successful in 9s
Cloud Apache Container / Shell-Checks (push) Successful in 1m52s
Cloud Apache Container / Build-and-Push (82) (push) Failing after 3m38s
Cloud Apache Container / Build-Shared-httpd (push) Failing after 3m15s
Cloud Apache Container / Build-LiteSpeed-Images (82) (push) Successful in 4m53s
Cloud Apache Container / Build-Shared-OLS (push) Successful in 4m0s
Cloud Apache Container / Build-LSPHP-Images (82) (push) Successful in 5m26s
Cloud Apache Container / Build-LiteSpeed-Images (83) (push) Successful in 3m48s
Cloud Apache Container / Build-LiteSpeed-Images (84) (push) Failing after 3m36s
Cloud Apache Container / Build-LiteSpeed-Images (85) (push) Failing after 3m55s
Cloud Apache Container / Build-LSPHP-Images (83) (push) Failing after 3m53s
Cloud Apache Container / Build-LSPHP-Images (85) (push) Failing after 3m53s
Cloud Apache Container / Build-FPM-Images (82) (push) Successful in 9m34s
Cloud Apache Container / Build-FPM-Images (83) (push) Successful in 9m33s
Cloud Apache Container / Build-and-Push (84) (push) Failing after 3m26s
Cloud Apache Container / Build-and-Push (83) (push) Successful in 16m11s
Cloud Apache Container / Build-and-Push (85) (push) Failing after 3m5s
Cloud Apache Container / Build-FPM-Images (84) (push) Successful in 8m58s
Cloud Apache Container / Build-FPM-Images (85) (push) Successful in 9m22s
Cloud Apache Container / Build-and-Push (86) (push) Failing after 3m16s
Cloud Apache Container / Build-FPM-Images (86) (push) Successful in 10m0s
Cloud Apache Container / Build-LSPHP-Images (84) (push) Failing after 1h14m34s
2026-11-29 05:43:45 +00:00
shadowdaoandClaude Opus 5.5 89547c395f mariadb client: ssl-verify-server-cert=0 drop-in (cac, cac-fpm)
An 11.x client fails against a 10.11 server ("ERROR 2026: SSL is required,
but the server does not support it") and against 11.x with a passwordless
account ("self-signed certificate"). Ship /etc/my.cnf.d/zz-whp-client.cnf with
[client] ssl-verify-server-cert=0 so the client series does not matter; TLS is
still negotiated where the server offers it. Measured: mariadb:11.8 client
with the drop-in vs 10.11.18 and 11.8 servers, 10.11 client vs both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-28 11:03:30 -08:00
jknappandClaude Opus 5.5 89aef8100b Merge pull request 'ci: run amd64 jobs on the ephemeral runners only' (#65) [skip ci]
Workflow-only change; [skip ci] so the merge does not rebuild/publish images.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-26 18:13:31 +00:00
jknappandClaude Opus 5.5 9608427a4c ci: run amd64 jobs on the ephemeral runners only
shared-httpd mod_whp_symlink PR check / Symlink-Module-Probe (pull_request) Successful in 1m20s
runs-on: ubuntu-latest -> runs-on: ephemeral. Only the per-job LXC runners
from gitea-ci-manager carry the `ephemeral` label, so jobs (and the secrets
they use) no longer land on the persistent instance runners shared with
other branches and repos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-26 09:19:46 -08:00
jknapp a2c91c5d85 Merge pull request #64 exec-surface gate pipefail + probe 403 [skip ci]
[skip ci]
2026-11-24 18:50:43 +00:00
shadowdaoandClaude Sonnet 5.5 0e2a066968 fix(shared-httpd): exec-surface gate pipefail scan (CI 6352) + probe test accepts guard 403
- httpd-exec-surface-gate.sh:131: printf|grep -q under pipefail replaced by a
  here-string grep; same match, no second exit status for pipefail to prefer.
- httpd-exec-surface-probes.test.sh: the ajp/ftp/scgi/uwsgi [P] probes now accept
  the proxy guard's 403 (secure, refused before handler lookup) as well as the
  AH01144 log line; any other outcome (502/503/200) still fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-24 10:50:35 -08:00
jknapp 15cd30fa3b Merge pull request 'fix(shared-ols): watcher exec bit (CI 6313), coalesce floor-window edits, harden test' (#63) from fix/ols-watcher-test-2026-11-24 into trunk
[skip ci]
2026-11-24 16:30:23 +00:00
shadowdaoandClaude Sonnet 5.5 432741d6a4 fix(shared-ols): watcher uses monotonic $SECONDS, stamps restart attempts, no fork per drained event
- floor wait was based on wall-clock date: a backward clock step could stretch
  the deferral far past FLOOR; $SECONDS is monotonic and bounds it to FLOOR.
- $(date) forked on every drained event; under unrelated churn that burned CPU
  for up to FLOOR seconds. Builtin $SECONDS needs no fork.
- last_restart is stamped on every attempt so a failing lswsctrl is limited to
  one try per FLOOR instead of retrying on each event.
- IFS= read -r so path names with leading/trailing whitespace are not trimmed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-24 08:29:18 -08:00
shadowdaoandClaude Sonnet 5.5 b395a198b1 fix(shared-ols): watcher executable bit, coalesce floor-window edits, harden test
CI run 6313 Shell-Checks failed "plain site docRoot .htaccess triggers (+0)":
the watcher was tracked as mode 100644 (the image chmods it, a bare CI
checkout does not), so `env ... ols-htaccess-watcher.sh` died with
"Permission denied" and no case ever restarted. Not a watcher logic bug.

- watcher: mode 100755
- watcher: an edit inside the FLOOR window is deferred to the end of the
  window (one coalesced restart, bounded by FLOOR) instead of dropped
- test: assert executable bit, launch via bash, kill children before parent
  (leaked inotifywait/subshell from earlier sections), add floor/coalesce cases

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
2026-11-24 08:17:13 -08:00
jknapp 1eca2566e8 Merge pull request #61: local-dev recipes, DEV mode, DOCROOT_SUBDIR, shared-ols watcher [skip ci]
[skip ci]
2026-11-24 01:44:36 +00:00
16 changed files with 348 additions and 26 deletions

No files matched your search

+1 -1
View File
@@ -37,7 +37,7 @@ jobs:
Attach-arm64:
# Only from trunk: the arm64 is built from the dispatched ref's Dockerfile.
if: github.ref == 'refs/heads/trunk'
runs-on: ubuntu-latest
runs-on: ephemeral
timeout-minutes: 90
steps:
- name: Checkout
+8 -8
View File
@@ -32,7 +32,7 @@ jobs:
# missing — see scripts/tests/lsphp-info-probe.test.sh for what went wrong
# and why it needed a test outside the image build to catch it.
Shell-Checks:
runs-on: ubuntu-latest
runs-on: ephemeral
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
@@ -166,7 +166,7 @@ jobs:
# job below takes its matrix from here and is skipped when its list is empty.
# Push events and an empty `only` input plan the full set, as before.
plan:
runs-on: ubuntu-latest
runs-on: ephemeral
timeout-minutes: 5
outputs:
cac: ${{ steps.plan.outputs.cac }}
@@ -188,7 +188,7 @@ jobs:
Build-and-Push:
needs: plan
if: needs.plan.outputs.cac != '[]'
runs-on: ubuntu-latest
runs-on: ephemeral
timeout-minutes: 130
strategy:
# One PHP version failing (e.g. an EOL stream) must not cancel the
@@ -396,7 +396,7 @@ jobs:
Build-FPM-Images:
needs: plan
if: needs.plan.outputs.cac_fpm != '[]'
runs-on: ubuntu-latest
runs-on: ephemeral
timeout-minutes: 130
strategy:
# One PHP version failing (e.g. an EOL stream) must not cancel the
@@ -607,7 +607,7 @@ jobs:
Build-LiteSpeed-Images:
needs: plan
if: needs.plan.outputs.cac_litespeed != '[]'
runs-on: ubuntu-latest
runs-on: ephemeral
# One place for the OLS base tag: digest lookup and build-args both read it.
# OLS_VERSION pinned to 1.8.4 (see the build step); Dockerfile default differs.
env:
@@ -769,7 +769,7 @@ jobs:
Build-LSPHP-Images:
needs: plan
if: needs.plan.outputs.cac_lsphp != '[]'
runs-on: ubuntu-latest
runs-on: ephemeral
# One place for the OLS base tag: digest lookup and build-args both read it.
# OLS_VERSION pinned to 1.8.4 (see the build step); Dockerfile default differs.
env:
@@ -929,7 +929,7 @@ jobs:
Build-Shared-httpd:
needs: plan
if: needs.plan.outputs.shared_httpd == 'true'
runs-on: ubuntu-latest
runs-on: ephemeral
timeout-minutes: 80
steps:
- name: Checkout
@@ -1115,7 +1115,7 @@ jobs:
Build-Shared-OLS:
needs: plan
if: needs.plan.outputs.shared_ols == 'true'
runs-on: ubuntu-latest
runs-on: ephemeral
# One place for the OLS base tag: digest lookup and build-args both read it.
env:
OLS_VERSION: "1.8.4"
+1 -1
View File
@@ -55,7 +55,7 @@ on:
jobs:
Build-lsphp-from-source:
runs-on: ubuntu-latest
runs-on: ephemeral
strategy:
fail-fast: false
matrix:
@@ -8,8 +8,8 @@ run-name: mod_whp_symlink probe test for ${{ gitea.actor }}
## fails the job. Run the same thing locally: docs/shared-httpd-symlink-module.md.
##
## Untrusted code: this runs PR-supplied Dockerfile/C source. Gitea has only the
## shared `ubuntu-latest` runners (no separate label for untrusted jobs), the same
## ones the publish jobs use, so this job is hardened instead: no secrets and no registry
## `ephemeral` runners (a fresh LXC per job, never reused), the same label as
## the publish jobs, so this job is hardened anyway: no secrets and no registry
## login, `--pull --no-cache`, a per-run image tag, and an `if: always()`
## cleanup. The publish builds (build-push.yaml) use their own fresh buildx
## builder with `pull: true` / `no-cache: true`, so nothing built here can be
@@ -27,7 +27,7 @@ on:
jobs:
Symlink-Module-Probe:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
runs-on: ephemeral
timeout-minutes: 40
steps:
- name: Checkout
+2
View File
@@ -80,6 +80,8 @@ COPY ./configs/prod-php.ini /etc/php.ini
COPY ./configs/zz-php2shell-mitigation.ini /etc/php.d/zz-php2shell-mitigation.ini
COPY ./configs/phpinfo.php /var/www/html/
COPY ./configs/mariadb.repo /etc/yum.repos.d/
# MariaDB client defaults: connect to the WHP mysql container whatever the client/server series.
COPY ./configs/whp-mariadb-client.cnf /etc/my.cnf.d/zz-whp-client.cnf
# mirror.mariadb.org names the arch dir amd64/aarch64 (not $basearch); amd64 result is byte-identical.
RUN sed -i "s/rhel\$releasever-amd64/rhel\$releasever-$(uname -m | sed s/x86_64/amd64/)/" /etc/yum.repos.d/mariadb.repo
COPY ./configs/index.php /var/www/html/
+2
View File
@@ -77,6 +77,8 @@ COPY ./configs/prod-php.ini /etc/php.ini
# all images ship PHP >= 8.2.35 / 8.3.36 / 8.4.27 / 8.5.12.
COPY ./configs/zz-php2shell-mitigation.ini /etc/php.d/zz-php2shell-mitigation.ini
COPY ./configs/mariadb.repo /etc/yum.repos.d/
# MariaDB client defaults: connect to the WHP mysql container whatever the client/server series.
COPY ./configs/whp-mariadb-client.cnf /etc/my.cnf.d/zz-whp-client.cnf
# mirror.mariadb.org names the arch dir amd64/aarch64 (not $basearch); amd64 result is byte-identical.
RUN sed -i "s/rhel\$releasever-amd64/rhel\$releasever-$(uname -m | sed s/x86_64/amd64/)/" /etc/yum.repos.d/mariadb.repo
+19
View File
@@ -0,0 +1,19 @@
# Client defaults for the mariadb/mysql/mariadb-dump CLIs in this image.
#
# The MariaDB server runs in WHP's separate `mysql` container, reached over
# the docker bridge. An 11.x client defaults to "TLS required, verify the
# certificate": against a 10.11 server it fails with
# ERROR 2026: SSL is required, but the server does not support it
# and against an 11.x server with a passwordless account with "self-signed
# certificate". This image ships a 10.11 client today (no effect), but WP-CLI
# `wp db ...`, mysqldump and any client a customer adds would break the day the
# client series differs from the server's.
#
# ssl-verify-server-cert=0 (measured on mariadb:11.8 and 10.11.18 clients vs
# 10.11.18 and 11.8 servers) keeps TLS negotiated when the server offers it and
# stops the verification/"required" failure, so a customer who points the CLI at
# a remote TLS database is not downgraded to plaintext. A customer who wants
# verification passes --ssl-verify-server-cert or sets it in ~/.my.cnf (later
# files and the command line win).
[client]
ssl-verify-server-cert=0
+8
View File
@@ -250,6 +250,14 @@ report: setup key / route pending).
## Operating the cache (CT130)
- **Self-check (`pkg-cache/`).** `pkgcache-selfcheck.timer` runs `/usr/local/sbin/pkgcache-selfcheck` every 60 s. Background: on 2026-11-26 the CT's ext4 images went `emergency_ro` and nginx answered an empty reply for anything uncached, so clients' dnf failed instead of falling back.
- Checks: `/` and `/srv/cache` mounted rw; write+fsync+delete on both; a refresh fetch through nginx of a tiny metadata file (10 s; one retry).
- On failure: stops nginx and `docker-registry`, so clients get connection refused and fall back within a second. It logs at `daemon.err` (`journalctl -t pkgcache-selfcheck`). If the origin is unreachable too it only warns.
- Alert: Uptime Kuma monitors 53 and 54 (https://100.123.207.73/ and :5000/v2/) go DOWN because the services are stopped. No webhook is configured on CT130.
- Recovery: only for services it stopped. 3 consecutive fully healthy runs and a good `nginx -t`, then it starts them and re-checks the fetch.
- It never runs fsck or remounts. After `emergency_ro` an operator still has to fix the disks (see the 2026-11-26 incident) and the self-check restarts the services on its own.
- Install: copy the script to `/usr/local/sbin/pkgcache-selfcheck` (0755) and the two units to `/etc/systemd/system/`, then `systemctl enable --now pkgcache-selfcheck.timer`. State is in `/run/pkgcache-selfcheck/`.
- **nginx config.**
- `/etc/nginx/conf.d/pkgcache-http.conf` holds the cache zone, maps and log format.
- `/etc/nginx/pkgcache/{server-common,meta,pkg}.conf` hold the shared settings.
+10
View File
@@ -0,0 +1,10 @@
[Unit]
Description=pkg-cache self-check (stop nginx+registry when the cache is unhealthy)
Documentation=file:///usr/local/sbin/pkgcache-selfcheck
After=nginx.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/pkgcache-selfcheck
TimeoutStartSec=120
Nice=5
+139
View File
@@ -0,0 +1,139 @@
#!/bin/bash
## pkgcache-selfcheck — run ON CT130 every 60 s by pkgcache-selfcheck.timer.
##
## Why: on 2026-11-26 both ext4 images (rootfs + /srv/cache, raw files on a CIFS
## 'soft' share) went emergency_ro. nginx kept answering cached files but sent an
## EMPTY reply (curl 52) for anything uncached, so clients' dnf failed instead of
## falling back to the origin. A refused connection falls back in <1 s; a half-dead
## cache does not. So when the cache is not healthy this script STOPS nginx and the
## registry (connection refused = fast fallback) and starts them again once healthy.
##
## Checks (all must pass):
## 1. every path in CHECK_PATHS is on a filesystem mounted rw (not ro/emergency_ro)
## 2. write + fsync + delete of a small file on each path succeeds (15 s limit)
## 3. nginx can fetch a fresh object through itself: a localhost refresh request
## (X-Pkgcache-Refresh: 1 bypasses the cached copy and re-stores it) of a tiny
## metadata file must return 200 with the expected body within 10 s. If it
## fails, the origin is fetched directly: origin also unreachable = an internet
## outage, not a cache fault, so nothing is stopped (WARN only).
## On failure: stop SERVICES, drop a marker in STATE_DIR, log at daemon.err.
## Alert path: Uptime Kuma monitors 53 (https://100.123.207.73/) and 54 (:5000/v2/)
## go DOWN because the services are stopped. No webhook/secret is configured on
## CT130, none is invented here.
## Recovery: only if WE stopped them (marker). After OK_NEEDED consecutive fully
## passing runs and a good `nginx -t`, start the services, re-run the fetch check,
## and stop them again if it fails. NEVER runs fsck or remounts anything.
##
## Test knobs (env): PKGCACHE_STATE_DIR, PKGCACHE_CHECK_PATHS, PKGCACHE_SERVICES,
## PKGCACHE_PROBE_URL, PKGCACHE_ORIGIN_URL, PKGCACHE_SYSTEMCTL, PKGCACHE_NGINX_TEST.
set -uo pipefail
STATE_DIR=${PKGCACHE_STATE_DIR:-/run/pkgcache-selfcheck}
CHECK_PATHS=${PKGCACHE_CHECK_PATHS:-"/ /srv/cache"}
SERVICES=${PKGCACHE_SERVICES-"nginx docker-registry"} # empty = manage nothing (tests)
PROBE_URL=${PKGCACHE_PROBE_URL:-http://127.0.0.1/almalinux/RPM-GPG-KEY-AlmaLinux-9}
ORIGIN_URL=${PKGCACHE_ORIGIN_URL:-https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-9}
PROBE_MAGIC='BEGIN PGP PUBLIC KEY BLOCK'
SYSTEMCTL=${PKGCACHE_SYSTEMCTL:-systemctl}
NGINX_TEST=${PKGCACHE_NGINX_TEST:-nginx -t}
OK_NEEDED=3
log() { local p=$1; shift; logger -t pkgcache-selfcheck -p "daemon.$p" -- "$*" 2>/dev/null || true; echo "$p: $*" >&2; }
mkdir -p "$STATE_DIR" 2>/dev/null || { log err "cannot create $STATE_DIR"; exit 1; }
exec 9>"$STATE_DIR/lock"
flock -n 9 || { echo "another run in progress" >&2; exit 0; }
MARKER="$STATE_DIR/stopped"
OKFILE="$STATE_DIR/okcount"
status() { printf '%s %s\n' "$(date -u +%FT%TZ)" "$*" >"$STATE_DIR/status" 2>/dev/null || true; }
# ---- check 1 + 2: mounts and write+fsync+delete ------------------------------
check_disks() {
local p opts f
for p in $CHECK_PATHS; do
opts=$(findmnt -n -o OPTIONS --target "$p" 2>/dev/null) || { echo "$p: findmnt failed"; return 1; }
case ",$opts," in *,rw,*) ;; *) echo "$p: not mounted rw (options: $opts)"; return 1 ;; esac
case ",$opts," in *,ro,*) echo "$p: mounted ro (options: $opts)"; return 1 ;; esac
f="$p/.pkgcache-selfcheck.$$"
if ! timeout -k 2 15 dd if=/dev/zero of="$f" bs=4096 count=1 conv=fsync status=none 2>/dev/null; then
rm -f -- "$f" 2>/dev/null; echo "$p: write+fsync failed"; return 1
fi
timeout -k 2 15 rm -f -- "$f" || { echo "$p: delete failed"; return 1; }
[ -e "$f" ] && { echo "$p: test file still present after delete"; return 1; }
done
return 0
}
# ---- check 3: nginx fetches a fresh object through itself ---------------------
probe_once() {
local body
body=$(curl -sS --max-time 10 -H 'X-Pkgcache-Refresh: 1' -w '\n%{http_code}' "$PROBE_URL" 2>&1) || { echo "curl: ${body##*$'\n'}"; return 1; }
local code=${body##*$'\n'}; body=${body%$'\n'*}
[ "$code" = 200 ] || { echo "HTTP $code"; return 1; }
case "$body" in *"$PROBE_MAGIC"*) return 0 ;; *) echo "200 but unexpected body (${#body} bytes)"; return 1 ;; esac
}
# prints a reason on failure; return 2 = cache fault is NOT proven (origin unreachable too)
check_fetch() {
local why
why=$(probe_once) && return 0
sleep 3 # one retry: don't act on a single blip
why=$(probe_once) && return 0
if curl -sS -o /dev/null --max-time 10 -f "$ORIGIN_URL" 2>/dev/null; then
echo "fetch through nginx failed ($why) but the origin is reachable"; return 1
fi
echo "fetch through nginx failed ($why); origin unreachable too (upstream outage, not a cache fault)"; return 2
}
stop_services() {
local s
for s in $SERVICES; do $SYSTEMCTL stop "$s" 2>&1 | sed 's/^/stop: /' >&2; done
printf '%s %s\n' "$(date -u +%FT%TZ)" "$1" >"$MARKER" 2>/dev/null || true
echo 0 >"$OKFILE" 2>/dev/null || true
}
# ---- main ---------------------------------------------------------------------
# Something else (an admin, a package script) started nginx while our stop marker exists:
# do not "recover" on our own schedule or leave it running unchecked. Drop the marker and
# judge it like normal operation below, which stops it again if the cache is unhealthy.
if [ -e "$MARKER" ] && $SYSTEMCTL is-active --quiet nginx; then
log warning "nginx was started by something else while stopped by this script; re-checking it now"
rm -f "$MARKER" "$OKFILE"
fi
if [ -e "$MARKER" ]; then
# we stopped the services earlier: look for recovery
if why=$(check_disks); then
n=$(( $(cat "$OKFILE" 2>/dev/null || echo 0) + 1 )); echo "$n" >"$OKFILE"
if [ "$n" -lt "$OK_NEEDED" ]; then
log notice "recovering: disks healthy ($n/$OK_NEEDED), services stay stopped"; status "stopped; recovering $n/$OK_NEEDED"; exit 0
fi
if ! tout=$($NGINX_TEST 2>&1); then
log err "disks healthy but nginx config test failed, staying stopped: ${tout//$'\n'/ | }"; echo 0 >"$OKFILE"; status "stopped; nginx -t failed"; exit 1
fi
for s in $SERVICES; do $SYSTEMCTL start "$s" 2>&1 | sed 's/^/start: /' >&2; done
sleep 2
why=$(check_fetch); rc=$?
if [ $rc = 1 ]; then
log err "restarted but the fetch check fails ($why); stopping again"; stop_services "restart check failed: $why"; status "stopped; restart check failed"; exit 1
fi
rm -f "$MARKER" "$OKFILE"
log notice "RECOVERED: $OK_NEEDED consecutive healthy runs, nginx -t ok, services started"; status "ok (recovered)"; exit 0
else
echo 0 >"$OKFILE"; log err "still unhealthy, services stay stopped: $why"; status "stopped; $why"; exit 1
fi
fi
# normal operation
if ! why=$(check_disks); then
log err "UNHEALTHY: $why -> stopping ${SERVICES} so clients fall back to the origin (connection refused)"
stop_services "$why"; status "stopped; $why"; exit 1
fi
if ! $SYSTEMCTL is-active --quiet nginx; then
log warning "nginx is not active (not stopped by this script); disks fine; fetch check skipped"; status "nginx inactive (manual?)"; exit 0
fi
why=$(check_fetch); rc=$?
case $rc in
0) status ok; exit 0 ;;
2) log warning "$why"; status "warn: $why"; exit 0 ;;
*) log err "UNHEALTHY: $why -> stopping ${SERVICES}"; stop_services "$why"; status "stopped; $why"; exit 1 ;;
esac
+10
View File
@@ -0,0 +1,10 @@
[Unit]
Description=Run the pkg-cache self-check every 60 s
[Timer]
OnBootSec=45s
OnUnitActiveSec=60s
AccuracySec=1s
[Install]
WantedBy=timers.target
+1 -1
View File
@@ -128,7 +128,7 @@ cmd_check() {
fi
# Positive control: nothing the platform uses may have disappeared with them.
for m in $REQUIRED_MODULES; do
if ! printf '%s\n' "$mods" | grep -qE "^ ${m} "; then
if ! grep -qE "^ ${m} " <<<"$mods"; then
echo "gate FAIL: required module ${m} is NOT loaded" >&2; fail=1
fi
done
Regular → Executable
+24 -9
View File
@@ -37,7 +37,6 @@ LSWSCTRL="${LSWSCTRL:-/usr/local/lsws/bin/lswsctrl}"
## render-shared-ols-config.sh; overridable so tests can run without OLS).
LSWS_CONF="${OLS_LSWS_CONF:-/usr/local/lsws/conf}"
SITES_ROOT="${OLS_SITES_ROOT:-${SITES_ROOT:-$LSWS_CONF/shared-sites}}"
last_restart=0
## Set of vhost docRoot directories (absolute, no trailing slash), keyed by
## path. Rebuilt from $SITES_ROOT/*/vhconf.conf only when the rendered
@@ -92,15 +91,31 @@ is_docroot_htaccess() {
log() { echo "ols-htaccess-watcher: $*" >&2; }
## Time comes from bash's $SECONDS (monotonic w.r.t. wall-clock steps, no fork
## per check). A backward clock jump therefore cannot stretch the floor wait, and
## the drain loops below stay cheap even when unrelated churn under $WATCH_ROOT
## makes `read` return instantly on every event.
last_restart="" # $SECONDS of the last restart ATTEMPT; empty = none yet
do_restart() {
path="$1"
now=$(date +%s)
if [ $((now - last_restart)) -lt "$FLOOR" ]; then
log "within ${FLOOR}s floor — coalescing, skipping restart ($path)"
return
local wait_until
if [ -n "$last_restart" ] && [ $((SECONDS - last_restart)) -lt "$FLOOR" ]; then
## COALESCE, don't drop: an edit inside the floor window used to be
## discarded, so it never applied until some later edit happened. Instead
## wait out the remainder of the window (hard-bounded by FLOOR), draining
## the event stream meanwhile so the pipe cannot back up, then restart ONCE
## for everything that arrived. A burst of N edits still costs one restart.
wait_until=$((last_restart + FLOOR))
log "within ${FLOOR}s floor — deferring restart to end of window ($path)"
while [ "$SECONDS" -lt "$wait_until" ]; do
read -r -t 1 _ || true
done
fi
## Stamp the ATTEMPT (not only success) so a failing lswsctrl is also limited
## to one try per FLOOR instead of retrying on every event.
last_restart=$SECONDS
if "$LSWSCTRL" restart >/dev/null 2>&1; then
last_restart=$now
log "graceful restart issued — $path changed"
else
log "WARNING: lswsctrl restart failed ($path)"
@@ -135,7 +150,7 @@ log "watching $WATCH_ROOT for vhost-docroot .htaccess changes (debounce=${DEBOUN
## directories is what ties a change to something OLS will reread. (Legacy
## */public_html/.htaccess match is kept only when that set is empty.)
inotifywait -m -r -e modify,create,delete,move "$WATCH_ROOT" --format '%w%f' 2>/dev/null |
while read -r path; do
while IFS= read -r path; do
is_docroot_htaccess "$path" || continue
## A tenant DOCROOT .htaccess changed. Coalesce the save-burst, then restart ONCE.
##
@@ -146,8 +161,8 @@ while read -r path; do
## events only until the deadline OR ~2s of total quiet, whichever comes first,
## so continuous activity can delay us by at most DEBOUNCE. do_restart's FLOOR
## then rate-limits across consecutive bursts.
deadline=$(( $(date +%s) + DEBOUNCE ))
while [ "$(date +%s)" -lt "$deadline" ]; do
deadline=$((SECONDS + DEBOUNCE))
while [ "$SECONDS" -lt "$deadline" ]; do
if read -r -t 2 _; then
continue # more activity — keep coalescing toward the deadline
else
@@ -124,7 +124,12 @@ for p in pa:ajp pf:ftp ps:scgi pu:uwsgi; do
# error log, which names the missing scheme handler only when the module is gone.
if [ "$EXPECT_OPEN" = 1 ]; then ok "[P] ${p##*:}:// : not asserted on an unhardened image"; continue; fi
l=$(docker exec "$N" sh -c "grep -c 'No protocol handler was valid for the URL /${p%%:*}/' /var/log/httpd/a.test-error.log 2>/dev/null || true")
# The server-scope proxy guard now answers 403 BEFORE mod_proxy picks a handler, so the
# request never reaches the scheme lookup and AH01144 is no longer logged. A 403 is the
# secure outcome (the [P] is refused); AH01144 is the older one (module removed). Anything
# else (502/503/500/200, i.e. a proxy attempt or served content) is a failure.
if [ "${l:-0}" -ge 1 ]; then ok "[P] ${p##*:}:// has no protocol handler (AH01144 for /${p%%:*}/)"
elif [ "$(printf %s "${r: -5}" | tr -d '\n')" = "[403]" ]; then ok "[P] ${p##*:}:// refused by the proxy guard (403) before any handler lookup"
else bad "[P] ${p##*:}://: no 'No protocol handler' for /${p%%:*}/ in the error log -> ${r: -12}"; fi
done
echo "== surfaces that must stay (reported, not failed)"
+29 -3
View File
@@ -10,9 +10,17 @@ W="$HERE/ols-htaccess-watcher.sh"
if ! command -v inotifywait >/dev/null 2>&1; then
echo "SKIP - inotifywait (inotify-tools) not installed; watcher test not run"; exit 0
fi
## The watcher must be executable as checked out (CI run 6313 failed with
## "Permission denied" because git tracked it 100644; the image chmods it, a bare
## checkout does not). Assert it, and launch via bash so the test never depends on it.
if [ ! -x "$W" ]; then echo "FAIL - $W is not executable (git mode must be 100755)"; exit 1; fi
T=$(mktemp -d)
WPID=""
cleanup() { [ -n "$WPID" ] && kill "$WPID" 2>/dev/null || true; pkill -P "${WPID:-0}" 2>/dev/null || true; rm -rf "$T"; }
## Stop children (inotifywait + the while-subshell) BEFORE the parent: once the
## parent is dead they are reparented and `pkill -P` no longer finds them, and the
## leaked watcher would keep restarting against later sections.
stopw() { [ -n "$WPID" ] || return 0; pkill -P "$WPID" 2>/dev/null || true; kill "$WPID" 2>/dev/null || true; WPID=""; }
cleanup() { stopw; rm -rf "$T"; }
trap cleanup EXIT
fail=0
ok() { echo "ok - $1"; }
@@ -36,7 +44,7 @@ chmod +x "$T/lswsctrl"
start() {
env OLS_WATCH_ROOT="$U" OLS_LSWS_CONF="$CONF" OLS_SITES_ROOT="$SITES" LSWSCTRL="$T/lswsctrl" \
OLS_HTACCESS_DEBOUNCE=1 OLS_HTACCESS_FLOOR=0 "$W" 2>"$T/log" &
OLS_HTACCESS_DEBOUNCE=1 OLS_HTACCESS_FLOOR="${FLOOR_T:-0}" bash "$W" 2>"$T/log" &
WPID=$!
sleep 1.5
}
@@ -63,7 +71,7 @@ mkdir -p "$U/u4/d.example/public_html/pub"
mkdir -p "$SITES/d"; printf 'docRoot %s\n' "$U/u4/d.example/public_html/pub" >"$SITES/d/vhconf.conf"
echo '# cfg2' >"$CONF/.tmp" && mv "$CONF/.tmp" "$CONF/httpd_config.conf"
check "site added after start (re-render) triggers" 1 "$U/u4/d.example/public_html/pub/.htaccess"
kill "$WPID" 2>/dev/null || true; pkill -P "$WPID" 2>/dev/null || true; WPID=""
stopw
## Fallback: no vhconf files -> legacy */public_html/.htaccess match
rm -rf "$SITES"; mkdir -p "$SITES"
@@ -71,4 +79,22 @@ start
check "fallback (empty docRoot set): public_html/.htaccess triggers" 1 "$U/u3/c.example/public_html/.htaccess"
check "fallback: deep plugin file still does NOT" 0 "$U/u1/a.example/public_html/wp-content/cache/x/.htaccess"
stopw
## Floor window: an edit inside it is DEFERRED to the window end (one restart),
## not dropped; a burst of several edits inside it still costs a single restart.
FLOOR_T=8
start
: >"$T/restarts"
H="$U/u3/c.example/public_html/.htaccess"
echo a >>"$H"; sleep 4
r1=$(count)
echo b >>"$H"; sleep 0.5; echo c >>"$H"; sleep 1
r2=$(count)
sleep 9
r3=$(count)
[ "$r1" -eq 1 ] && ok "floor: first edit restarts immediately" || bad "floor: first edit (restarts $r1, want 1)"
[ "$r2" -eq 1 ] && ok "floor: edits inside window do not restart early" || bad "floor: early restart (restarts $r2, want 1)"
[ "$r3" -eq 2 ] && ok "floor: edits inside window coalesce into ONE deferred restart" || bad "floor: deferred restart (restarts $r3, want 2)"
[ "$fail" -eq 0 ] && echo "ALL PASS" || { echo "FAILURES"; cat "$T/log"; exit 1; }
+86
View File
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
## pkgcache-selfcheck.test.sh — fixture test for pkg-cache/pkgcache-selfcheck.sh.
## Fakes findmnt/curl/systemctl/logger via PATH; one extra case uses a REAL
## read-only bind mount when `sudo -n` works (skipped otherwise).
set -euo pipefail
HERE=$(cd "$(dirname "$0")/../.." && pwd)
S="$HERE/pkg-cache/pkgcache-selfcheck.sh"
T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
fail=0
ok() { echo "ok - $1"; }
bad() { echo "FAIL - $1"; fail=1; }
mkdir -p "$T/bin" "$T/disk1" "$T/disk2"
cat >"$T/bin/findmnt" <<'EOS'
#!/bin/sh
# last arg = path; $FAKE_RO = path that reports ro
for a; do p=$a; done
case "$p" in "$FAKE_RO") echo "ro,relatime" ;; *) echo "rw,relatime" ;; esac
EOS
cat >"$T/bin/curl" <<'EOS'
#!/bin/sh
# FAKE_PROBE=ok|http500|empty|refused ; FAKE_ORIGIN=ok|down
for a; do last=$a; done
case "$last" in
*probe*) case "$FAKE_PROBE" in
ok) printf -- '-----BEGIN PGP PUBLIC KEY BLOCK-----\nx\n200'; exit 0;;
http500) printf 'err\n500'; exit 0;;
empty) echo "curl: (52) Empty reply from server" >&2; exit 52;;
refused) echo "curl: (7) refused" >&2; exit 7;; esac;;
*origin*) [ "$FAKE_ORIGIN" = ok ] && exit 0 || exit 7;;
esac
EOS
cat >"$T/bin/systemctl" <<'EOS'
#!/bin/sh
echo "$*" >>"$CALLS"
case "$1" in is-active) [ -e "$ACTIVE" ]; exit $?;; start) touch "$ACTIVE";; stop) rm -f "$ACTIVE";; esac
exit 0
EOS
printf '#!/bin/sh\nexit 0\n' >"$T/bin/logger"; chmod +x "$T/bin/"*
export PATH="$T/bin:$PATH" CALLS="$T/calls" ACTIVE="$T/active"
export PKGCACHE_STATE_DIR="$T/state" PKGCACHE_CHECK_PATHS="$T/disk1 $T/disk2"
export PKGCACHE_PROBE_URL=http://probe PKGCACHE_ORIGIN_URL=http://origin
export PKGCACHE_SERVICES="nginx docker-registry" # explicit: never rely on the script default in a test
export PKGCACHE_NGINX_TEST=true FAKE_RO=none FAKE_PROBE=ok FAKE_ORIGIN=ok
run() { "$S" >"$T/out" 2>&1; }
reset() { rm -rf "$T/state" "$T/calls"; touch "$T/calls" "$ACTIVE"; }
stopped() { [ ! -e "$ACTIVE" ] && grep -q '^stop nginx' "$CALLS"; }
reset; run && ! stopped && ok "healthy: nothing stopped" || bad "healthy"
[ -z "$(ls -A "$T/disk1")" ] && ok "test file removed" || bad "test file left behind"
reset; FAKE_RO="$T/disk2" run && bad "ro disk exit" || { stopped && grep -q '^stop docker-registry' "$CALLS" && ok "ro mount: nginx+registry stopped" || bad "ro mount not stopped"; }
reset; chmod 555 "$T/disk1"; if [ "$(id -u)" != 0 ]; then run && bad "unwritable exit" || { stopped && ok "write failure: stopped" || bad "write failure not stopped"; }; fi; chmod 755 "$T/disk1"
reset; FAKE_PROBE=empty run && bad "empty reply exit" || { stopped && ok "empty reply (curl 52), origin up: stopped" || bad "empty reply not stopped"; }
reset; FAKE_PROBE=http500 run && bad "500 exit" || { stopped && ok "HTTP 500, origin up: stopped" || bad "500 not stopped"; }
reset; FAKE_PROBE=empty FAKE_ORIGIN=down run && ! stopped && ok "origin down too: warn only, not stopped" || bad "upstream outage must not stop"
# recovery: needs 3 consecutive good runs, only if WE stopped it
reset; FAKE_PROBE=empty run || true
export FAKE_PROBE=ok
run; stopped && ok "recovery 1/3: still stopped" || bad "recovery 1"
FAKE_RO="$T/disk1" run || true; run; stopped && ok "failure resets the streak (1/3 again)" || bad "streak reset"
run; stopped && ok "recovery 2/3: still stopped" || bad "recovery 2"
run && [ -e "$ACTIVE" ] && [ ! -e "$T/state/stopped" ] && grep -q '^start nginx' "$CALLS" && ok "3rd healthy run: services started, marker cleared" || bad "recovery 3"
# nginx -t failure blocks the restart
reset; FAKE_PROBE=empty run || true; export FAKE_PROBE=ok
run; run; PKGCACHE_NGINX_TEST=false run && bad "nginx -t fail exit" || { [ ! -e "$ACTIVE" ] && ok "bad nginx config: stays stopped" || bad "started despite bad config"; }
# restart whose fetch check fails is stopped again
reset; FAKE_PROBE=empty run || true; run; run; FAKE_PROBE=empty run && bad "restart-fail exit" || { [ ! -e "$ACTIVE" ] && [ -e "$T/state/stopped" ] && ok "restart with failing fetch: stopped again" || bad "restart-fail"; }
# never start something an admin stopped
reset; rm -f "$ACTIVE"; run && ! grep -q '^start' "$CALLS" && ok "admin-stopped nginx is left alone" || bad "admin stop"
# empty services list must mean "manage nothing", never the real defaults
reset; PKGCACHE_SERVICES="" FAKE_PROBE=empty run || true
! grep -q '^stop' "$CALLS" && ok "empty PKGCACHE_SERVICES: nothing stopped" || bad "empty services list stopped something"
# something else restarts nginx while our marker exists: re-checked, stopped again if still bad
reset; FAKE_PROBE=empty run || true; touch "$ACTIVE"
FAKE_RO="$T/disk1" run || true
[ ! -e "$ACTIVE" ] && ok "nginx restarted by someone else while unhealthy: stopped again" || bad "fight: left running"
reset; FAKE_PROBE=empty run || true; touch "$ACTIVE"
run && [ -e "$ACTIVE" ] && [ ! -e "$T/state/stopped" ] && ok "nginx restarted by someone else and healthy: left running, marker cleared" || bad "fight: healthy case"
# REAL read-only bind mount
mkdir -p "$T/real" "$T/robind"
if sudo -n mount --bind "$T/real" "$T/robind" 2>/dev/null && sudo -n mount -o remount,bind,ro "$T/robind"; then
rm "$T/bin/findmnt"; reset; PKGCACHE_CHECK_PATHS="$T/robind" run && bad "real ro exit" || { stopped && ok "REAL read-only bind mount: stopped" || bad "real ro"; }
sudo -n umount "$T/robind"
else echo "skip - cannot bind-mount here, skipping the real ro bind mount case"; fi
exit $fail