Skip to content

fix: guard core make targets and defer service restarts to postrun#7

Draft
troglodyne wants to merge 1 commit into
masterfrom
koan.trogbot/fix-makefile-core-idempotency
Draft

fix: guard core make targets and defer service restarts to postrun#7
troglodyne wants to merge 1 commit into
masterfrom
koan.trogbot/fix-makefile-core-idempotency

Conversation

@troglodyne

Copy link
Copy Markdown
Contributor

What

Guard unprotected useradd and ln -s operations in makefile.tt core targets; eliminate nginx double-restart and defer both nginx and fail2ban service reloads to queue_postrun_task.

Why

Issue #1 calls for safe shared-environment deploys. PRs #5 and #6 cover individual recipes; this covers the core makefile template which runs for every domain:

  • service_user: useradd fails with exit 9 if the service user already exists on an existing system — now guarded with id user &>/dev/null ||
  • ssl: both ln -s symlinks for the self-signed cert fail if already present — guarded with [ -L target ] ||

Additionally, nginxproxy.tt was restarting nginx twice in sequence (once per config file installed) and both restarts fired inline mid-make. Collapsed to one deferred restart via queue_postrun_task, so nginx reloads only after all config is in place. fail2ban.tt had the same inline-reload problem.

How

  • makefile.tt service_user target: id [% user %] &>/dev/null || useradd ...
  • makefile.tt ssl target: [ -L /etc/ssl/certs/... ] || ln -s ... (both symlinks)
  • nginxproxy.tt: removed first inline systemctl restart nginx, replaced second with [% script_dir %]/queue_postrun_task systemctl restart nginx
  • fail2ban.tt: systemctl reload fail2banqueue_postrun_task systemctl reload fail2ban

All guards follow the same pattern established in PRs #5 and #6.

Testing

No automated test suite. Changes verified by diff — patterns match the established guards in mail.tt, letsencrypt.tt, mariadb.tt, and tpsgi.tt from the merged and pending PRs.

makefile.tt:
- service_user: guard useradd with existence check (id user || useradd)
  so re-running against an existing system does not fail on duplicate user
- ssl: guard both ln -s with [ -L target ] || to survive re-deploy when
  symlinks already exist

nginxproxy.tt:
- remove duplicate redundant systemctl restart (was firing twice in one target)
- defer the single restart to queue_postrun_task so nginx reloads after all
  config is in place, not mid-make

fail2ban.tt:
- defer systemctl reload to queue_postrun_task (same ordering rationale)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread templates/makefile.tt
# Setup the link to LE certs
ln -s /etc/letsencrypt/live/[% domain %]/fullchain.pem /etc/ssl/certs/[% domain %].pem
ln -s /etc/letsencrypt/live/[% domain %]/privkey.pem /etc/ssl/private/[% domain %].pem
[ -L /etc/ssl/certs/[% domain %].pem ] || ln -s /etc/letsencrypt/live/[% domain %]/fullchain.pem /etc/ssl/certs/[% domain %].pem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to just blow away the file preemptively

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants