From 9e41743c5306ea775a5a3f2b9613f0e48644a8b8 Mon Sep 17 00:00:00 2001 From: Tiago Neves Date: Wed, 5 Aug 2026 02:52:17 +0100 Subject: [PATCH] fix(deploy): sync deploy/systemd/ units from webhook-deploy.sh (BIT-28183) The cron-driven webhook-deploy.sh never refreshed /etc/systemd/system, so new/changed units in deploy/systemd/ silently rotted in git after the one-shot deploy.sh bootstrap (root cause of the BIT-28132 gap). Add a step that copies deploy/systemd/*.service and *.timer to /etc/systemd/system + daemon-reload whenever deploy/systemd/ changes in the diff; new units still need one manual systemctl enable --now. Also record the BIT-28183 decision to keep the 5-minute cron poll as the permanent deploy path on CT222 and leave news-deploy-hook.service unenabled, in docs/deployment.md. Paperclip-Agent: Tiago Neves (urlKey tiago-neves; id 5d084b36-f38f-42a5-a92a-520005afda4f) Paperclip-Issue: BIT-28183 Paperclip-Run: 267defb1-b2d1-4a95-a8c0-4dd1c777834e --- deploy/scripts/webhook-deploy.sh | 13 +++++++++++++ docs/deployment.md | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/deploy/scripts/webhook-deploy.sh b/deploy/scripts/webhook-deploy.sh index 294a4e3..22adb61 100755 --- a/deploy/scripts/webhook-deploy.sh +++ b/deploy/scripts/webhook-deploy.sh @@ -81,6 +81,19 @@ if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^deploy/nginx/"; then log "Nginx reloaded." fi +# Sync systemd units if deploy/systemd/ changed (BIT-28183 — deploy.sh installs these +# once at bootstrap; webhook-deploy.sh never refreshed them, so new/changed units in +# git silently never reached /etc/systemd/system on subsequent deploys). +if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^deploy/systemd/"; then + log "Systemd units changed — syncing to /etc/systemd/system..." + for src in "$APP_DIR"/deploy/systemd/*.service "$APP_DIR"/deploy/systemd/*.timer; do + [ -f "$src" ] || continue + cp "$src" "/etc/systemd/system/$(basename "$src")" + done + systemctl daemon-reload + log "Systemd units synced. New units are not auto-enabled/started — enable per docs/deployment.md." +fi + # Domain JSON is cached in the bridge process — restart when config changes if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^config/"; then log "Domain config changed — restarting bridge + frontend..." diff --git a/docs/deployment.md b/docs/deployment.md index dc9ab0d..88fbaca 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -241,7 +241,7 @@ pm2 startup After the first manual bootstrap, pushes to `main` can trigger a pull + selective rebuild on the container. -1. **Script** — `deploy/scripts/webhook-deploy.sh` compares `HEAD` to `origin/main`, runs `git reset --hard`, rebuilds bridge/frontend when those trees change, reloads nginx when `deploy/nginx/` changes, restarts bridge + frontend when `config/` changes (domain JSON is cached in the bridge process), and runs `docker compose` when `wordpress/` changes. +1. **Script** — `deploy/scripts/webhook-deploy.sh` compares `HEAD` to `origin/main`, runs `git reset --hard`, rebuilds bridge/frontend when those trees change, reloads nginx when `deploy/nginx/` changes, syncs `deploy/systemd/*.service` and `*.timer` into `/etc/systemd/system/` + `daemon-reload` when `deploy/systemd/` changes (BIT-28183 — units are copied but not auto-enabled/started, so a brand-new unit still needs one manual `systemctl enable --now`; a change to a unit already enabled just needs `systemctl restart `), restarts bridge + frontend when `config/` changes (domain JSON is cached in the bridge process), and runs `docker compose` when `wordpress/` changes. 2. **Hook server** — `deploy/scripts/deploy-hook-server.mjs` listens on loopback (default `127.0.0.1:9090`), path `POST /hook`, and accepts `Authorization: Bearer ` or `X-Deploy-Token` matching `DEPLOY_HOOK_TOKEN`. It returns `202` and runs the script in the background. Systemd unit: `deploy/systemd/news-deploy-hook.service`; env template: `deploy/systemd/deploy-hook.env.example` → `/etc/news-platform/deploy-hook.env`. @@ -249,6 +249,8 @@ After the first manual bootstrap, pushes to `main` can trigger a pull + selectiv 4. **Alternative** — Gitea **Actions** can `curl -fsS -X POST -H "Authorization: Bearer $TOKEN" http://.../hook` from a runner that has network access to the CT. +**Decision (BIT-28183, 2026-08-05): the 5-minute cron poll is the accepted permanent design on CT222.** `news-deploy-hook.service` is *not enabled* there — deploys go through `webhook-deploy.sh` via the root crontab only. (The step-1 systemd sync copies its unit file to `/etc/systemd/system/` like any other `deploy/systemd/*.service`, since a stale/missing copy on disk is exactly the BIT-28183 bug; a unit that's merely present but never enabled stays inactive and harmless.) Rationale for not enabling it: the push-hook adds a second listening service (`:9090`) plus a bearer-token secret to manage, for a latency win (≤5 min saved) that doesn't matter for this platform's publish cadence. The hook server code and unit stay in the repo as a documented, ready-to-enable option (steps 2–4 above) if a future workload needs faster propagation — enabling it then is: fill `deploy-hook.env.example` → `/etc/news-platform/deploy-hook.env`, `systemctl enable --now news-deploy-hook`, then wire the Gitea webhook (step 3). Until that decision changes, don't add `news-deploy-hook.service` to `deploy.sh`'s curated install/enable loop, and don't `systemctl enable` it manually on CT222. + --- ## Writer Pipeline — andebol.net (systemd timer) -- 2.47.3