fix(supervisor): relaunch haproxy directly from bash in ~1 s; restart marker for the host watchdog
whp02 2026-11-26: after a worker abort the supervisor took 16 s just to log
'haproxy process not found' (ensure_haproxy.py imports the whole manager,
slow on a swapping host), and the WHP watchdog docker-restarted on top.
- When haproxy is gone, validate the on-disk config (haproxy -c) and start
haproxy -W -db -S ... exactly like spawn_haproxy_master(), detached to PID 1,
waiting for 'Loading success.'; fall back to ensure_haproxy.py only if the
config is missing/invalid or the launch fails. pidof re-checked right before
launch (never a second master).
- Poll interval default 1 s (was 2 s). Each step logged with a UTC ms timestamp.
- /tmp/haproxy-restarting ('<epoch> <pid>') exists while a recovery runs
(HAPROXY_SUPERVISOR_MARKER) so the host watchdog can back off.
- Tests: stubbed fast/fallback/idempotency cases in test-haproxy-supervisor.py;
new test-haproxy-supervisor-relaunch.py with a real haproxy (SIGABRT the
worker, relaunch < 3 s, measured 0.77 s idle). Both run in the image build.
No VERSION bump.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
ff535fae1f
commit
6df8d4b332
5 files changed
+440
-8
No files matched your search
@@ -15,6 +15,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||
- **Superseded-cert retirement**: covered by the same file (`TestRetirementRules`, `TestSanOverlapRetirement`). A new bundle retires any OTHER pem/lineage sharing ANY name (CN or SAN) with it - the pem moved to `cert-retired/`, the lineage's live+archive+renewal moved TOGETHER to `/etc/letsencrypt/retired/<stamp>/` (leaving archive/ behind makes certbot refuse the name forever), never deleted; the bundle's own `--cert-name` lineage is `live/<primary>` exactly and is never retired - unless that cert is still the only valid one for a name this edge serves (`retirement_blockers()`). `GET /api/capabilities` advertises this to WHP, which must not use whole-site re-bundling without it. Expired pems already in the crt dir are moved to `cert-retired/` by `cert_retire_expired_pems` (never the last pem, never `default_self_signed_cert.pem`). Expired lineages are never published (`cert_is_expired` in `cert-publish-lib.sh`, `leaf_is_expired()` in Python). Fixtures: `scripts/test-fixtures/san-certs/`.
|
||||
- **Multi-arch index assembly (coraza-spoa)**: `python3 scripts/test-assemble-multiarch-index.py` - offline (NOT run in the image build; it also reads `.gitea/workflows/build-push-coraza.yaml`); `scripts/assemble-multiarch-index.sh` turns the by-digest amd64 + arm64 pushes into the tag(s): arm64 is attached only if THIS run's arm64 step outcome is `success` (failure => amd64-only tag, never a stale arm64), a bad amd64 digest publishes nothing. `scripts/e2e-coraza-multiarch.sh` rehearses the whole thing against throwaway local registries (see coraza-spoa/README.md "Multi-arch").
|
||||
- **Publish verify gate**: `python3 scripts/test-verify-published-tags.py` - offline (needs `jq`; NOT run in the image build); `scripts/verify-published-tags.sh` is the last build-push.yaml step: every tag in every registry must resolve, carry the assembled platforms, and share ONE index digest. The digest is the sha256 of `imagetools inspect --raw` cross-checked against the text `Digest:` line / bare `--format` output (buildx 0.28 ignores `--format` and prints full text; CI run 5381).
|
||||
- **Supervisor fast relaunch**: `python3 scripts/test-haproxy-supervisor-relaunch.py` - runs in the image build; needs a real `haproxy` (skips without one). Starts a real master, runs the real `haproxy-supervisor.sh`, SIGABRTs the worker and asserts a new master is serving < 3 s after the old one exits, started from bash (python stub never ran), marker present during and gone after, no second master, invalid config -> python fallback. `scripts/test-haproxy-supervisor.py` (stubs, ~60 s) covers the fast/fallback/idempotency logic. Run both after touching `haproxy-supervisor.sh`.
|
||||
- **Per-host thread count knob**: `python3 scripts/test-nbthread-knob.py` - runs in the image build; `HAPROXY_NBTHREAD` (container env, 1-64; invalid/unset = ignored) renders `nbthread N` in `global` ONLY when set, so every other host's config is byte-identical. Real `haproxy -c` of `nbthread 1` is the `nbthread-1` scenario in `scripts/validate-rendered-config.py`. WHP side: `/etc/whp/edge-nbthread` -> `lib-edge-container.sh` -> `docker run -e` at recreate.
|
||||
- **Health-check timing**: `python3 scripts/test-health-check-timing.py` - runs in the image build; one `default-server inter 30s fastinter 10s downinter 30s rise 2 fall 3` in `defaults` + `spread-checks 50` in `global` (hap_header.tpl), never per server line; the Coraza SPOA server keeps `inter 2s`. Pins that a dead backend is still detected in <= 2 min and that `fastinter` (which sizes the post-reload start-up stagger window) stays >= 5s. Real `haproxy -c` coverage: the `check-timing`/`spread-checks` assertions in `scripts/validate-rendered-config.py`.
|
||||
- **Default splash**: `python3 scripts/test-default-splash.py` - offline (runs in the image build); unrouted hosts (server hostname, bare IP, unknown names) are answered by `http-request return ... file /haproxy/errors/default-splash.html` BEFORE the Coraza SPOE call, never for a routed host (`routed_hosts.list`/`routed_wildcards.list`, written by `generate_config()` from the routing rows and in the rollback set), never for ACME/blocked/suspended. Run it after touching the splash block, the routing ACL templates, or the domain loops in `generate_config()`. See README "Default Splash".
|
||||
@@ -183,4 +184,4 @@ re-reads it on reload, so a failed runtime command must degrade to
|
||||
- gunicorn uses `haproxy_gunicorn_worker.TimeoutThreadWorker` (gthread + client socket timeout + first-byte deadline + total header deadline + wedge watchdog). Stock gthread leaves client sockets blocking with NO timeout; `--timeout` only watches the main thread's heartbeat
|
||||
- Supports deployment on servers with git directory at `/root/whp` and web file sync via rsync to `/docker/whp/web/`
|
||||
- HAProxy is the 3.2 LTS series from haproxy.debian.net (`trixie-backports-3.2`, native OpenSSL 3.5 QUIC); exact build in `/haproxy/HAPROXY_VERSION`. Debian trixie's 3.0.11 had the DNS-resolver watchdog abort (haproxy #3101)
|
||||
- HAProxy runs as `haproxy -W -db` (foreground master, started by `haproxy_manager.spawn_haproxy_master()`), NOT daemonised: `daemon` re-points the master's stderr at /dev/null and loses ALERTs and the ha_panic/watchdog thread dump. Its stderr is appended to `/var/log/haproxy/haproxy-stderr.log` (haproxy-logs volume) and `scripts/haproxy-stderr-relay.py` re-emits it on the container stderr (`haproxy-stderr: ` prefix). The in-container supervisor probes with `pidof` every `HAPROXY_SUPERVISOR_INTERVAL` (default 2 s) and only runs python when HAProxy is gone; Crash evidence (dump blocks opened only by the anchored `Thread N is about to kill` header, `[ALERT] (PID) :`, `Current worker (N) exited with code N`; ANCHORED patterns, so keywords echoed from URLs/Host/server names never match) bypasses the bucket within a budget (1000 lines / 10 min, 60 s cooldown after a bound closes a block) and goes to STDERR (journald PRIORITY 3); routine reload noise is collapsed into one `[relay] reload/start ok: N routine lines collapsed` line per reload and everything benign goes to STDOUT (PRIORITY 6; docker's journald driver does not parse `<N>` prefixes), with a per-minute `[relay] suppressed N lines` summary. `python3 scripts/test-haproxy-stderr-relay.py` (offline) covers the relay
|
||||
- HAProxy runs as `haproxy -W -db` (foreground master, started by `haproxy_manager.spawn_haproxy_master()`), NOT daemonised: `daemon` re-points the master's stderr at /dev/null and loses ALERTs and the ha_panic/watchdog thread dump. Its stderr is appended to `/var/log/haproxy/haproxy-stderr.log` (haproxy-logs volume) and `scripts/haproxy-stderr-relay.py` re-emits it on the container stderr (`haproxy-stderr: ` prefix). The in-container supervisor probes with `pidof` every `HAPROXY_SUPERVISOR_INTERVAL` (default 1 s) and, when HAProxy is gone, relaunches it DIRECTLY FROM BASH against the on-disk config (`haproxy -c` then the same `haproxy -W -db -S ...` command, detached to PID 1; ~0.8 s measured on an idle host, was 16 s through python on a starved one) and falls back to `ensure_haproxy.py` only if the config is missing/invalid or the launch fails; while recovering it keeps the marker `/tmp/haproxy-restarting` (`<epoch> <pid>`, `HAPROXY_SUPERVISOR_MARKER`) so the host watchdog does not `docker restart` on top of it; Crash evidence (dump blocks opened only by the anchored `Thread N is about to kill` header, `[ALERT] (PID) :`, `Current worker (N) exited with code N`; ANCHORED patterns, so keywords echoed from URLs/Host/server names never match) bypasses the bucket within a budget (1000 lines / 10 min, 60 s cooldown after a bound closes a block) and goes to STDERR (journald PRIORITY 3); routine reload noise is collapsed into one `[relay] reload/start ok: N routine lines collapsed` line per reload and everything benign goes to STDOUT (PRIORITY 6; docker's journald driver does not parse `<N>` prefixes), with a per-minute `[relay] suppressed N lines` summary. `python3 scripts/test-haproxy-stderr-relay.py` (offline) covers the relay
|
||||
Reference in new issue
Block a user