From 31c00cd65a2438a8244250fa74b3538fe969a425 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sun, 14 Jun 2026 10:31:29 +0000 Subject: [PATCH] setup.sh: persistent Go cache + HOME so timer deploys build instead of OOM/erroring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The self-update timer runs setup.sh as a systemd oneshot with no $HOME, so `go build` aborted with "module cache not found: neither GOMODCACHE nor GOPATH is set" before compiling — auto-deploys silently pulled new code but never rebuilt or restarted. On top of that, a cold cache made the 458MB droplet OOM-kill the compiler. Set explicit, root-owned, persistent Go caches (/var/cache/agentbbs/{go,go-build}) plus HOME and GOMAXPROCS=1 in setup.sh, and add HOME=/root to the generated agentbbs-update.service. A warm persistent cache means incremental redeploys recompile almost nothing, keeping peak memory within RAM+swap; combined with the existing `go build -p=1` the compiler no longer gets OOM-killed. Co-Authored-By: Claude Opus 4.8 --- setup.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/setup.sh b/setup.sh index 6d8d986..26d1d8a 100755 --- a/setup.sh +++ b/setup.sh @@ -111,6 +111,21 @@ if [ "$("$GO_ROOT/bin/go" version 2>/dev/null | awk '{print $3}')" != "go${GO_VE fi export PATH="$GO_ROOT/bin:$PATH" +# Persistent, root-owned Go caches. Two reasons this matters on this box: +# 1. The self-update timer runs setup.sh as a systemd oneshot with no $HOME, so +# a bare `go build` aborts with "module cache not found: neither GOMODCACHE +# nor GOPATH is set" before it compiles a thing. Setting these explicitly +# (not relying on $HOME) fixes timer-driven redeploys. +# 2. A warm cache means an incremental redeploy recompiles only what changed, so +# the 458MB droplet stops OOM-killing the compiler on every build. Combined +# with GOMAXPROCS=1 + `go build -p=1`, peak memory stays within RAM+swap. +export HOME="${HOME:-/root}" +export GOPATH="${GOPATH:-/var/cache/agentbbs/go}" +export GOMODCACHE="${GOMODCACHE:-$GOPATH/pkg/mod}" +export GOCACHE="${GOCACHE:-/var/cache/agentbbs/go-build}" +export GOMAXPROCS=1 +mkdir -p "$GOPATH" "$GOCACHE" + # ---- 3. service user + rootless podman prerequisites ----------------------- if ! id "$SVC_USER" >/dev/null 2>&1; then log "creating service user $SVC_USER" @@ -304,6 +319,9 @@ Wants=network-online.target [Service] Type=oneshot +# systemd oneshots start with no HOME; set one so git (and Go, via setup.sh) +# behave the same as an interactive root deploy instead of erroring. +Environment=HOME=/root Environment=REPO=${REPO} Environment=BRANCH=${BRANCH} Environment=SRC_DIR=${SRC_DIR}