From a04f728d65df64acc2769ce93c3368e0abd6fdf2 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sat, 17 Oct 2026 14:28:17 +0000 Subject: [PATCH] fix(setup-origin): a name's own template survives renewal (/etc/moshpit/templates/.conf) Renewal re-runs setup-origin.sh, which rewrote every site from the static webroot template, so a name served as a proxy to an app (seo.rank, now live.streaming) reverted at its next renewal. A template at $MOSHPIT_TEMPLATE_DIR/.conf (default /etc/moshpit/templates) is used for that name; MOSHPIT_TEMPLATE still wins when set. Co-Authored-By: Claude Opus 5.5 --- scripts/setup-origin.sh | 11 ++++++++++- tests/setup-origin-registry.test.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/scripts/setup-origin.sh b/scripts/setup-origin.sh index 4cea467..5ff3755 100755 --- a/scripts/setup-origin.sh +++ b/scripts/setup-origin.sh @@ -282,7 +282,16 @@ fi # ------------------------------------------------------------------ nginx -step "writing the nginx server block" +# A name can bring its own server block: /etc/moshpit/templates/.conf +# (MOSHPIT_TEMPLATE_DIR). Without it, a name whose site is a proxy to an app +# (seo.rank, live.streaming) was rewritten back to the static webroot by the +# next renewal, which re-runs this script. MOSHPIT_TEMPLATE, when set, still +# wins, for a box whose every name is served the same way. +NAME_TEMPLATE="${MOSHPIT_TEMPLATE_DIR:-/etc/moshpit/templates}/$NAME.conf" +if [ -z "${MOSHPIT_TEMPLATE:-}" ] && [ -f "$NAME_TEMPLATE" ]; then + TEMPLATE="$NAME_TEMPLATE" +fi +step "writing the nginx server block from $TEMPLATE" CONF="$SITEDIR/$NAME" if [ "$DRY_RUN" = "0" ]; then mkdir -p "$SITEDIR" "$ENABLEDIR" "$WEBROOT" diff --git a/tests/setup-origin-registry.test.ts b/tests/setup-origin-registry.test.ts index bfd170a..87c39e4 100644 --- a/tests/setup-origin-registry.test.ts +++ b/tests/setup-origin-registry.test.ts @@ -92,3 +92,17 @@ describe("moshpit-renew.sh", () => { assert.match(r.stdout, /1 renewed, 0 failed/); }); }); + +describe("setup-origin.sh — a name's own server block", () => { + test("a template named for the site is used, so a renewal keeps its proxy", async () => { + const dir = await tempDir(); + const templates = join(dir, "templates"); + await mkdir(templates, { recursive: true }); + await writeFile(join(templates, "live.streaming.conf"), "server { server_name NAME; }\n"); + const own = await sh(setup, ["live.streaming", "--dry-run"], { MOSHPIT_TEMPLATE_DIR: templates, MOSHPIT_TEMPLATE: "" }); + assert.equal(own.code, 0, own.stderr); + assert.match(own.stderr + own.stdout, new RegExp(`server block from ${join(templates, "live.streaming.conf").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`)); + const other = await sh(setup, ["blue.eggs", "--dry-run"], { MOSHPIT_TEMPLATE_DIR: templates, MOSHPIT_TEMPLATE: "" }); + assert.match(other.stderr + other.stdout, /server block from .*moshpit-origin\.conf/); + }); +});