fix: handle masked/missing caddy.service during package transition #2

Merged
madcat merged 1 commits from fix/postinst-masked-unit into main 2026-06-12 19:25:07 +00:00
Owner

Problem

The deb postinst script fails when replacing stock caddy on hosts where caddy.service was masked. The unit file /usr/lib/systemd/system/caddy.service doesn't survive the transition — it's listed in the deb manifest but not on disk after dpkg removes the old caddy package. systemctl enable caddy.service then fails.

Changes

debian/postinst

  • Unmask before enable: systemctl unmask caddy.service removes the /dev/null symlink if the unit was masked
  • Recreate unit file if missing: If the unit file is gone after unmasking (removed during package transition), recreates it from an embedded copy matching debian/caddy.service
  • Guard caddy-api.service stop: systemctl stop caddy-api.service 2>/dev/null || true
  • Double unmask: Unmask both before and after daemon-reload to cover all edge cases

debian/preinst (new)

  • Stops caddy.service and caddy-api.service with || true guards before install/upgrade
  • Prevents "Failed to stop" errors when services don't exist

Makefile

  • Includes preinst in deb build alongside other maintainer scripts

Scenarios Handled

  1. Fresh install — no prior caddy, all guards pass cleanly
  2. Upgrade from stock caddy with masked service — unmasks, recreates unit if needed
  3. Upgrade from previous madcat-caddy — standard upgrade path, no recreation needed

Testing

  • Built deb successfully with make deb
  • Verified preinst, postinst, prerm, postrm all present in built package
  • Logic verified against all three scenarios

Closes #1

## Problem The deb postinst script fails when replacing stock caddy on hosts where `caddy.service` was masked. The unit file `/usr/lib/systemd/system/caddy.service` doesn't survive the transition — it's listed in the deb manifest but not on disk after dpkg removes the old caddy package. `systemctl enable caddy.service` then fails. ## Changes ### `debian/postinst` - **Unmask before enable**: `systemctl unmask caddy.service` removes the `/dev/null` symlink if the unit was masked - **Recreate unit file if missing**: If the unit file is gone after unmasking (removed during package transition), recreates it from an embedded copy matching `debian/caddy.service` - **Guard caddy-api.service stop**: `systemctl stop caddy-api.service 2>/dev/null || true` - **Double unmask**: Unmask both before and after `daemon-reload` to cover all edge cases ### `debian/preinst` (new) - Stops `caddy.service` and `caddy-api.service` with `|| true` guards before install/upgrade - Prevents "Failed to stop" errors when services don't exist ### `Makefile` - Includes `preinst` in deb build alongside other maintainer scripts ## Scenarios Handled 1. **Fresh install** — no prior caddy, all guards pass cleanly 2. **Upgrade from stock caddy with masked service** — unmasks, recreates unit if needed 3. **Upgrade from previous madcat-caddy** — standard upgrade path, no recreation needed ## Testing - Built deb successfully with `make deb` - Verified preinst, postinst, prerm, postrm all present in built package - Logic verified against all three scenarios Closes #1
madcat added 1 commit 2026-06-12 19:24:31 +00:00
Fixes the postinst failure when replacing stock caddy on hosts where
caddy.service was masked. The unit file could be missing after dpkg
removes the old caddy package, causing systemctl enable to fail.

Changes:
- postinst: unmask caddy.service before enable, recreate unit file
  from embedded copy if missing after unmasking, stop caddy-api.service
  with guard
- preinst (new): stop caddy.service and caddy-api.service with || true
  guards before install/upgrade
- Makefile: include preinst in deb build

Handles three scenarios:
1. Fresh install (no prior caddy)
2. Upgrade from stock caddy with masked service
3. Upgrade from previous madcat-caddy

Closes #1
madcat merged commit ddc066db4a into main 2026-06-12 19:25:07 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: madcat-os/madcat-caddy#2