Implement selective service restart for Debian package upgrades #111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Debian packages currently never auto-restart on upgrade (operator must manually restart). RPM packages always restart. This implements selective restart: auto-restart only for patch upgrades, skip for minor/major upgrades to reduce risk of automatic failures.
Changes
Added
debian/preinst/var/lib/crowdsec-haproxy-spoa-bouncer/old-versionfor postinst consumptionModified
debian/postinstBehavior
Version comparison strips Debian revision (
1.0.0-1→1.0), handles pre-release tags, and uses simple string equality onmajor.minor.Original prompt
Summary
Implement selective service restart behavior for Debian packages: only attempt an automatic reload/restart for patch-only upgrades (same major and minor), and do NOT auto-restart for minor or major upgrades. This reduces risk of automatic restarts causing failures during minor/major upgrades while preserving smooth behavior for safe patch releases.
Background and motivation
Current Debian maintainer scripts in debian/ (postinst and prerm) stop and disable the service on upgrade but do not restart it. The RPM packaging currently restarts the service on upgrade, but Debian behavior intentionally avoids automatically restarting. We want a middle-ground: try to automatically reload/restart on patch upgrades only. This change makes upgrades smoother for patch releases while keeping operators in control for potentially breaking minor/major upgrades.
What to change
File: debian/preinst
Mode: executable
Contents (proposed):
#!/bin/sh
set -eu
PKG="crowdsec-haproxy-spoa-bouncer"
STATE_DIR="/var/lib/${PKG}"
preinst is called with 'upgrade' when upgrading
if [ "$1" = "upgrade" ] && [ -n "$2" ]; then
mkdir -p "$STATE_DIR"
echo "$2" > "$STATE_DIR/old-version"
fi
exit 0
Modifications to existing debian/postinst (proposed patch):
Edge cases and safety
Testing
Deliverables
Why this is safe
Review request
Files to be added/modified
I have inspected the repository's current debian/postinst and debian/prerm to ensure compatibility (I noted prerm currently stops and disables the service). See source fi...
This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.