fix(deploy): sync deploy/systemd/ units from webhook-deploy.sh (BIT-28183) #45

Merged
spark merged 1 commits from fix/BIT-28183-webhook-systemd-sync into main 2026-08-05 02:58:17 +01:00
2 changed files with 16 additions and 1 deletions

No files matched your search

+13
View File
@@ -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..."
+3 -1
View File
@@ -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 <unit>`), 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 <token>` 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)