#889635 debhelper: dh_installsystemd - please support templated unit files

#889635#5
Date:
2018-02-05 08:22:57 UTC
From:
To:
i'm working on packaging knot-resolver 2.0.0.

Upstream has gone with a templated approach to take advantage of
multiple cores.

each daemon can consume a full core, and listens on its own control
socket, and on shared network-facing sockets:

   kresd@.service
   kresd@.socket        (port 53)
   kresd-tls@.socket    (port 853)
   kresd-control@socket (/run/knot-resolver/control@%i)

We ship all of these templates, but we *also* want to start with 1
daemon's sockets enabled (kresd{,-tls,-control}@1.socket, in particular).

i can ship those as symlinks in /lib/systemd/system/, like this:

  2387690      4 drwxr-xr-x   2 dkg      dkg          4096 Feb  5 03:00 lib/systemd/system/
  2384490      4 -rw-r--r--   1 dkg      dkg           281 Feb  5 03:00 lib/systemd/system/kresd-control@.socket
  2384493      0 lrwxrwxrwx   1 dkg      dkg            17 Feb  5 03:00 lib/systemd/system/kresd-tls@1.socket -> kresd-tls@.socket
  2384488      4 -rw-r--r--   1 dkg      dkg           347 Feb  5 03:00 lib/systemd/system/kresd@.service
  2384489      4 -rw-r--r--   1 dkg      dkg           302 Feb  5 03:00 lib/systemd/system/kresd@.socket
  2384492      0 lrwxrwxrwx   1 dkg      dkg            13 Feb  5 03:00 lib/systemd/system/kresd@1.socket -> kresd@.socket
  2384491      4 -rw-r--r--   1 dkg      dkg           303 Feb  5 03:00 lib/systemd/system/kresd-tls@.socket
  2384494      0 lrwxrwxrwx   1 dkg      dkg            21 Feb  5 03:00 lib/systemd/system/kresd-control@1.socket -> kresd-control@.socket

however, dh_installsystemd doesn't recognize the linked files as units
worthy of managing in the maintscripts.

in particular, there's a line in dh_installsystemd that looks like it
ignores symlinks entirely:


		wanted => sub {
			my $name = $File::Find::name;
			return unless -f $name;
			return unless $name =~ m,^\Q${tmpdir}\E/lib/systemd/system/[^/]+$,;
			if (-l) {
				my $target = abs_path(readlink());
				$target =~ s,^\Q${oldcwd}\E/,,g;
				$aliases{$target} = [ $_ ];
			} else {
				push @installed_units, $name;
			}
		},


It's not clear to me what the "if (-l)" is doing there, since there's
a "return unless -f $fname" two lines above it.

could we have dh_installsystemd perform the same management for the
symlinked socket instantiations that it does for other units?

Note that if i list kresd{,-tls,-control}@1.socket on the command line
to dh_installsystemd, i get the following warnings:

dh_installsystemd: Could not find "kresd@1.socket" in the /lib/systemd/system directory of knot-resolver. This could be a typo, or using Also= with a service file from another package. Please check carefully that this message is harmless.
dh_installsystemd: Could not find "kresd-tls@1.socket" in the /lib/systemd/system directory of knot-resolver. This could be a typo, or using Also= with a service file from another package. Please check carefully that this message is harmless.
dh_installsystemd: Could not find "kresd-control@1.socket" in the /lib/systemd/system directory of knot-resolver. This could be a typo, or using Also= with a service file from another package. Please check carefully that this message is harmless.

i do not believe these messages are harmless!

#889635#14
Date:
2021-11-09 08:02:09 UTC
From:
To:
Hi,

Also, dh_systemd could restart template instances on upgrade, which it
does not.

Alex

#889635#19
Date:
2022-07-11 14:36:07 UTC
From:
To:
I second the request to support templated unit files. My MR for
init-system-helpers to support enabling template units with a default instance
was accepted two days ago [0].

There's two possible action dh_installsystemd could take for a template unit
with a default instance: 1. Only run the enable, purge and unmask actions on
postinst, because these are actions that don't require an instance. 2. Do the
actions in option 1, but additionally parse the DefaultInstance line and run
start, stop, and restart actions as well.

Option 1 is also available for template units without instance, so that has
broader applicability than just template units with a default instance. If
there's interest, I'd be willing to try to code an implementation of either or
both options.

Regards,

Victor Westerhuis

[0]: https://salsa.debian.org/debian/init-system-helpers/-/merge_requests/20
-----BEGIN PGP SIGNATURE-----

iQJHBAEBCAAxFiEE6OxII3T+o0Ujs6ECQz2Rq5dHQPsFAmLMNVATHHZpY3RvckB3
ZXN0ZXJodS5pcwAKCRBDPZGrl0dA+w89D/4ntsR/5YpIWZz7vaHUUn6aCimVT0/2
4TvPKieEMXixiJNMbHSs0y6l4ssezWMZbbGxQoH+Xiua0zZDij7drGuZgXSmAyjB
Aoo9OHnWfikvc5NzVjiY8po/xW48r2C0ALpgxx8kG5wdJTR0frtj7zx9c3iuaois
hfMuGNxF+lBw9jZ9CFNC2rPLrA5cQvTsdWknhfkz1UsAcOoblFOAv/3g+GNjSZLb
JUwCdCWrmlozUAB0hSV3mK2scGlf57ndXwr/NbNIXk1yNpfOmK8v5Y2QBaFzn8z6
GbpBc0ewHPVObjPlRLizJxt+DBdjga7ZtoDE5i9EJXayr/eA6Z7MD+JRYd5STup5
64zoYPKaujt97cLnLimaJv8xaTLGMh7XBFx5k7XkHtUCm5yqDK3hJZKJL5FTTrkI
GEjX+vT7LKe4CmsNkGFrooAvmRb1DR2fruXB0D6OSl4MjxqLYMaQB7puAV1sQA2L
xv+ie5RiqTEfHzRNI/If43nb+y/0jjrbsdZ6KJ4PlmppGfSq3rW0r9ErXpp9/RNN
CcAOfMw+f8rvosGNXehgy58SljDN486D+JA6H44Gvg5Qp/POr64pg4Tsek1rxonU
TtEF7K4DMQT5BC3oHRWp6u5Uy698MeR1njSKmel9cLob8e14vppEXw6OO3hplcw9
NbyDDW/HQlGFEQ==
=6ak0
-----END PGP SIGNATURE-----

#889635#24
Date:
2023-05-28 17:40:03 UTC
From:
To:
Hi,

I’m also interested in this feature, needed for the drkonqi KDE crash
manager to be started when systemd-coredump starts.

Drkonqi ships a drkonqi-coredump-processor@.service unit with a
WantedBy=systemd-coredump@.service and I had to reimplement [0] part of
what dh_installsystemd does in the maintainer scripts.

Note that in this case we don’t have a DefaultInstance so unlike what
Vinctor wrote above we *don’t want* to start / restart the unit on
install / upgrade as this would make no sense in this situation.

[0] https://salsa.debian.org/qt-kde-team/kde/drkonqi/-/tree/master/debian


Happy hacking,
--
Aurélien