···99CERT_DIR="/var/lib/acme/ewancroft.uk"
1010SECRET_PATH="/run/secrets/cloudflare-acme.env"
1111ACME_SERVICE="acme-ewancroft.uk.service"
1212+ACME_ORDER_SERVICE="acme-order-renew-ewancroft.uk.service"
1213FLAKE="/home/ewan/.config/nix-config#server"
13141415RED='\033[0;31m'
···133134fi
134135135136# ─────────────────────────────────────────────────────────────────────────────
136136-header "6d. Triggering ACME (systemctl clean + start)"
137137+header "6d. Triggering ACME order/renew service"
137138# ─────────────────────────────────────────────────────────────────────────────
138138-# systemctl clean --what=state is the official NixOS method: it removes the
139139-# cert dir AND the lego accounts/state directory so the next start is a full
140140-# fresh run rather than a renewal.
141141-info "Cleaning all ACME state (official NixOS method)..."
142142-systemctl clean --what=state "$ACME_SERVICE"
139139+# acme-order-renew-ewancroft.uk.service is the unit that actually runs lego.
140140+# Stop the preliminary service first so systemctl clean can proceed.
141141+info "Stopping preliminary service..."
142142+systemctl stop "$ACME_SERVICE" 2>/dev/null || true
143143+info "Cleaning ACME state..."
144144+systemctl clean --what=state "$ACME_SERVICE" 2>/dev/null || true
145145+systemctl clean --what=state "$ACME_ORDER_SERVICE" 2>/dev/null || true
143146ok "State cleaned"
144147145145-info "Starting $ACME_SERVICE — this may take ~30–90s (DNS propagation)..."
148148+info "Starting $ACME_ORDER_SERVICE — this may take ~30–90s (DNS propagation)..."
146149START_TIME=$(date --iso-8601=seconds)
147147-if systemctl start "$ACME_SERVICE"; then
148148- ok "ACME service completed successfully"
150150+if systemctl start "$ACME_ORDER_SERVICE"; then
151151+ ok "ACME order service completed successfully"
149152else
150150- fail "ACME service failed"
153153+ fail "ACME order service failed"
151154 echo ""
152155 echo " Full journal for this run:"
153153- journalctl -u "$ACME_SERVICE" --since "$START_TIME" --no-pager
156156+ journalctl -u "$ACME_ORDER_SERVICE" --since "$START_TIME" --no-pager
154157 die "See journal output above for the root cause"
155158fi
156159157160info "Journal output from this run:"
158158-journalctl -u "$ACME_SERVICE" --since "$START_TIME" --no-pager
161161+journalctl -u "$ACME_ORDER_SERVICE" --since "$START_TIME" --no-pager
159162160163# ─────────────────────────────────────────────────────────────────────────────
161164header "7. Verifying new cert"