Control: tags -1 + patch The following MR (and patches) restarts and stops template units in postinst and prerm respectively https://salsa.debian.org/debian/debhelper/-/merge_requests/172
From 30e6a16d7bc6c7e459291fd7c96c1903195a1c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <[email protected]> Date: Sun, 22 Nov 2026 23:34:12 +0100 Subject: [PATCH 1/3] dh_installsystemd: postinst: systemctl try-reload template-unit@*.service... X-Mutt-PGP: OS
Sponsored-by: https://beaverlabs.net Ref: #889635 --- dh_installsystemd | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git dh_installsystemd dh_installsystemd index 1bf10d8..a6cd984 100755 --- dh_installsystemd +++ dh_installsystemd @@ -335,7 +335,7 @@ if (compat(12)) { # installed, upgraded or removed. foreach my $package (@{$dh{DOPACKAGES}}) { my $tmpdir = tmpdir($package); - my (@args, @start_units, @enable_units, %aliases); + my (@args, @start_units, @restart_units, @enable_units, %aliases); my @installed_units = list_installed_units($tmpdir, \%aliases); @@ -375,10 +375,13 @@ foreach my $package (@{$dh{DOPACKAGES}}) { error("Package '$package' does not install unit '$unit'.") unless (-f $path); } - # Skip template service files. Enabling, disabling, starting + # Only restart template service files. Enabling, disabling, starting # or stopping those services without specifying the instance # is not useful. - next if ($unit =~ /\@/); + if ($unit =~ s/@[^.]*\./@*./) { + push @restart_units, $unit; + next; + } # Handle all unit files specified via Also= explicitly. This # is not necessary for enabling, but for disabling, as we @@ -411,6 +414,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) { @enable_units = map { quote($_) } uniq sort @enable_units; @start_units = map { quote($_) } uniq sort @start_units; + @restart_units = map { quote($_) } uniq sort @restart_units; my %options = ('snippet-order' => 'service'); @@ -422,6 +426,11 @@ foreach my $package (@{$dh{DOPACKAGES}}) { autoscript($package, 'postrm', 'postrm-systemd', {'UNITFILES' => join(' ', @enable_units) }); } + if (not $dh{NOSCRIPTS} and $dh{RESTART_AFTER_UPGRADE} and @restart_units) { + my $replace = { 'UNITFILES' => join(' ', @restart_units), 'RESTART_ACTION' => 'try-restart' }; + autoscript($package, 'postinst', 'postinst-systemd-restartnostart', $replace, \%options); + } + if (not $dh{NOSCRIPTS} and @start_units) { my $replace = { 'UNITFILES' => join(' ', @start_units) }; -- 2.39.5
From 02a1b6ded9aa57bba1db6daa4255871e07763df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <[email protected]> Date: Sun, 22 Nov 2026 23:37:56 +0100 Subject: [PATCH 2/3] autoscripts/postinst-systemd-*start: systemctl daemon-reload at most once X-Mutt-PGP: OS We can now insert p-s-restartnostart before any of the others, reloading multiple times doesn't give us anything and is slow Sponsored-by: https://beaverlabs.net --- autoscripts/postinst-systemd-restart | 5 ++++- autoscripts/postinst-systemd-restartnostart | 5 ++++- autoscripts/postinst-systemd-start | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git autoscripts/postinst-systemd-restart autoscripts/postinst-systemd-restart index 9a8fa43..f9e21bf 100644 --- autoscripts/postinst-systemd-restart +++ autoscripts/postinst-systemd-restart @@ -1,6 +1,9 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -z "$DPKG_ROOT" ] && [ -d /run/systemd/system ]; then - systemctl --system daemon-reload >/dev/null || true + if [ -z "$_dh_systemd_daemon_reloaded" ]; then + systemctl --system daemon-reload >/dev/null || true + _dh_systemd_daemon_reloaded=y + fi if [ -n "$2" ]; then _dh_action=#RESTART_ACTION# else diff --git autoscripts/postinst-systemd-restartnostart autoscripts/postinst-systemd-restartnostart index 261606b..d0dec58 100644 --- autoscripts/postinst-systemd-restartnostart +++ autoscripts/postinst-systemd-restartnostart @@ -1,6 +1,9 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -z "$DPKG_ROOT" ] && [ -d /run/systemd/system ]; then - systemctl --system daemon-reload >/dev/null || true + if [ -z "$_dh_systemd_daemon_reloaded" ]; then + systemctl --system daemon-reload >/dev/null || true + _dh_systemd_daemon_reloaded=y + fi if [ -n "$2" ]; then deb-systemd-invoke #RESTART_ACTION# #UNITFILES# >/dev/null || true fi diff --git autoscripts/postinst-systemd-start autoscripts/postinst-systemd-start index 951e47a..8de4f87 100644 --- autoscripts/postinst-systemd-start +++ autoscripts/postinst-systemd-start @@ -1,6 +1,9 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -z "$DPKG_ROOT" ] && [ -d /run/systemd/system ]; then - systemctl --system daemon-reload >/dev/null || true + if [ -z "$_dh_systemd_daemon_reloaded" ]; then + systemctl --system daemon-reload >/dev/null || true + _dh_systemd_daemon_reloaded=y + fi deb-systemd-invoke start #UNITFILES# >/dev/null || true fi fi -- 2.39.5
From 1bc85b14eaa7e318d338286af221358aad05c451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <[email protected]> Date: Mon, 23 Nov 2026 00:01:43 +0100 Subject: [PATCH 3/3] dh_installsystemd: prerm: also stop template units X-Mutt-PGP: OS Sponsored-by: https://beaverlabs.net Closes: #889635 --- dh_installsystemd | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git dh_installsystemd dh_installsystemd index a6cd984..b3bc700 100755 --- dh_installsystemd +++ dh_installsystemd @@ -431,6 +431,13 @@ foreach my $package (@{$dh{DOPACKAGES}}) { autoscript($package, 'postinst', 'postinst-systemd-restartnostart', $replace, \%options); } + if (not $dh{NOSCRIPTS} and (@start_units or @restart_units)) { + my $replace = { 'UNITFILES' => join(' ', (@start_units, @restart_units)) }; + + # stop service only on remove + autoscript($package, 'prerm', 'prerm-systemd-restart', $replace, \%options); + } + if (not $dh{NOSCRIPTS} and @start_units) { my $replace = { 'UNITFILES' => join(' ', @start_units) }; @@ -453,9 +460,6 @@ foreach my $package (@{$dh{DOPACKAGES}}) { autoscript($package, 'preinst', 'preinst-systemd-stop', $replace, \%options) unless ($dh{R_FLAG} || $dh{RESTART_AFTER_UPGRADE}); - # stop service only on remove - autoscript($package, 'prerm', 'prerm-systemd-restart', $replace, \%options); - # Run this with "default" order so it is always after other # service related autosnippets. autoscript($package, 'postrm', 'postrm-systemd-reload-only', $replace); -- 2.39.5
signature.asc
Description: PGP signature

