fix(frank-archon): raise the ttm knob from a root ExecStartPre — User=dank cannot write it
a9da65e put the raise inside the serve script, which runs as `User=dank`: the knob is root-owned 0644, so `-w` is false and the write silently failed — the gate printed its refusal on a cap it had just failed to move. The privileged path is systemd's `+` prefix: `ExecStartPre=+scripts/ttm-preflight.sh --raise` runs as root even under `User=`, before ExecStart, so `Restart=always` can never outrun it. The lib is now also executable (`--raise` sources the env file and verifies), and keeps a `sudo -n` fallback for a human running the gate from a shell. Seam: the refusal cases run with a PATH that has `cat`+`bash` and NO `sudo` (root writes a 444 file, so a passwordless dev box would have tested nothing), and both now assert the gate's own exit 1, not merely non-zero. New seam covers the unit line and the `--raise` entry point end to end (writable knob -> raised, no args -> usage exit 2).
This commit is contained in:
@@ -35,6 +35,13 @@ Group=dank
|
||||
LimitMEMLOCK=infinity
|
||||
Environment="FRANK_ARCHON_ENV_FILE=/home/dank/serverAppConfigs/scripts/frank-archon.env"
|
||||
ExecStart=/home/dank/serverAppConfigs/scripts/serve-frank-archon.sh
|
||||
# The `+` prefix runs this as root even though the service is User=dank — the
|
||||
# ttm pages cap is a root-owned knob and the pinned-RAM ledger (~147 GiB) is
|
||||
# unusable below it. After a reboot the knob is back at its default (half of
|
||||
# RAM), so the raise must be part of the start, not a note in a runbook: the
|
||||
# 2026-10-12 power failure reset it and the endpoint refused to boot 6,919
|
||||
# times. The serve script re-verifies the cap after this hook.
|
||||
ExecStartPre=+/home/dank/serverAppConfigs/scripts/ttm-preflight.sh --raise
|
||||
# systemd stop: wait alone cannot stop the container child; stop it
|
||||
# explicitly. No graceful drain contract is claimed (the OpenAI front end
|
||||
# holds no queue to drain — in-flight decodes are lost, which a stop
|
||||
|
||||
@@ -42,15 +42,24 @@ ttm_cap_mib() {
|
||||
echo "${cur:-0}"
|
||||
}
|
||||
|
||||
# Writes $1 MiB (as 4 KiB pages) into every writable knob present. Failures are
|
||||
# Writes $1 MiB (as 4 KiB pages) into every knob present. Failures are
|
||||
# swallowed: the caller re-reads the cap, and a write the kernel refused shows
|
||||
# up there (ttm refuses a limit below the pages it has already pinned).
|
||||
#
|
||||
# PRIVILEGE, measured the hard way: the knob is root-owned 0644 and the service
|
||||
# process runs as User=dank, so `-w` is FALSE there and a plain echo fails. The
|
||||
# canonical privileged path is the unit's ExecStartPre with the `+` prefix
|
||||
# (systemd runs it as root even under User=); `sudo -n` is the fallback for a
|
||||
# human running the gate from a shell (passwordless sudo on both hosts).
|
||||
ttm_raise_cap() {
|
||||
local pages=$(( $1 * 256 )) p
|
||||
for p in "$FRANK_ARCHON_TTM_SYS_DIR/pages_limit" \
|
||||
"$FRANK_ARCHON_TTM_SYS_DIR/pages_max"; do
|
||||
[ -e "$p" ] || continue
|
||||
if [ -w "$p" ]; then
|
||||
echo "$pages" > "$p" 2>/dev/null || true
|
||||
elif command -v sudo >/dev/null 2>&1; then
|
||||
sudo -n sh -c "echo $pages > '$p'" >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -74,3 +83,22 @@ ttm_ensure_cap() {
|
||||
fi
|
||||
echo "frank-archon: ttm pages cap ${cap} MiB clears the pinned-ledger floor $FRANK_ARCHON_TTM_MIN_MIB" >&2
|
||||
}
|
||||
|
||||
# Executed (not sourced) it is the privileged pre-start hook: systemd runs this
|
||||
# as root from the unit's `ExecStartPre=+…`, where the knob write is legal and
|
||||
# the `Restart=always` loop can never outrun it.
|
||||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
|
||||
set -euo pipefail
|
||||
case "${1:-}" in
|
||||
--raise)
|
||||
TTM_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=/dev/null
|
||||
source "${FRANK_ARCHON_ENV_FILE:-$TTM_DIR/frank-archon.env}"
|
||||
ttm_ensure_cap
|
||||
;;
|
||||
*)
|
||||
echo "usage: ${0##*/} --raise (raise the ttm pages cap, then verify)" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user