teknoraver / rpms / systemd

Forked from rpms/systemd a month ago
Clone

Blame SOURCES/0180-man-fix-invalid-description-of-template-handling-in-.patch

594167
From 842c3bade0b593e5c4eabbe1c18dfab503683cc6 Mon Sep 17 00:00:00 2001
594167
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
594167
Date: Thu, 10 Mar 2022 21:33:25 +0100
594167
Subject: [PATCH] man: fix invalid description of template handling in
594167
 WantedBy=
594167
594167
We don't need to talk about Alias=. The approach of using Alias= to enable
594167
units is still supported, but hasn't been advertised as the way to do thing
594167
for many years. Using it as an explanation is just confusing.
594167
594167
Also, the description of templated units did not take DefaultInstance=
594167
into account. It is updated and extended.
594167
594167
(cherry picked from commit 17a2679e9925c9ec3c5764d01def92c5627973e4)
594167
594167
Related: #2082131
594167
---
594167
 man/systemd.unit.xml          | 53 +++++++++++++++++------------------
594167
 test/test-systemctl-enable.sh | 49 ++++++++++++++++++++++++++++++++
594167
 2 files changed, 74 insertions(+), 28 deletions(-)
594167
594167
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
594167
index 2e6261c1ed..caebaecfdc 100644
594167
--- a/man/systemd.unit.xml
594167
+++ b/man/systemd.unit.xml
594167
@@ -1906,34 +1906,31 @@
594167
         <term><varname>WantedBy=</varname></term>
594167
         <term><varname>RequiredBy=</varname></term>
594167
 
594167
-        <listitem><para>This option may be used more than once, or a
594167
-        space-separated list of unit names may be given. A symbolic
594167
-        link is created in the <filename>.wants/</filename> or
594167
-        <filename>.requires/</filename> directory of each of the
594167
-        listed units when this unit is installed by <command>systemctl
594167
-        enable</command>. This has the effect that a dependency of
594167
-        type <varname>Wants=</varname> or <varname>Requires=</varname>
594167
-        is added from the listed unit to the current unit. The primary
594167
-        result is that the current unit will be started when the
594167
-        listed unit is started. See the description of
594167
-        <varname>Wants=</varname> and <varname>Requires=</varname> in
594167
-        the [Unit] section for details.</para>
594167
-
594167
-        <para><command>WantedBy=foo.service</command> in a service
594167
-        <filename>bar.service</filename> is mostly equivalent to
594167
-        <command>Alias=foo.service.wants/bar.service</command> in the
594167
-        same file. In case of template units listing non template units,
594167
-        <command>systemctl enable</command> must be called with an
594167
-        instance name, and this instance will be added to the
594167
-        <filename>.wants/</filename> or
594167
-        <filename>.requires/</filename> list of the listed unit. E.g.
594167
-        <command>WantedBy=getty.target</command> in a service
594167
-        <filename>getty@.service</filename> will result in
594167
-        <command>systemctl enable getty@tty2.service</command>
594167
-        creating a
594167
-        <filename>getty.target.wants/getty@tty2.service</filename>
594167
-        link to <filename>getty@.service</filename>.
594167
-        </para></listitem>
594167
+        <listitem><para>This option may be used more than once, or a space-separated list of unit names may
594167
+        be given. A symbolic link is created in the <filename>.wants/</filename> or
594167
+        <filename>.requires/</filename> directory of each of the listed units when this unit is installed by
594167
+        <command>systemctl enable</command>. This has the effect of a dependency of type
594167
+        <varname>Wants=</varname> or <varname>Requires=</varname> being added from the listed unit to the
594167
+        current unit. The primary result is that the current unit will be started when the listed unit is
594167
+        started, see the description of <varname>Wants=</varname> and <varname>Requires=</varname> in the
594167
+        [Unit] section for details.</para>
594167
+
594167
+        <para>In case of template units listing non template units, the listing unit must have
594167
+        <varname>DefaultInstance=</varname> set, or <command>systemctl enable</command> must be called with
594167
+        an instance name. The instance (default or specified) will be added to the
594167
+        <filename>.wants/</filename> or <filename>.requires/</filename> list of the listed unit. For example,
594167
+        <command>WantedBy=getty.target</command> in a service <filename>getty@.service</filename> will result
594167
+        in <command>systemctl enable getty@tty2.service</command> creating a
594167
+        <filename>getty.target.wants/getty@tty2.service</filename> link to
594167
+        <filename>getty@.service</filename>. This also applies to listing specific instances of templated
594167
+        units: this specific instance will gain the dependency. A template unit may also list a template
594167
+        unit, in which case a generic dependency will be added where each instance of the listing unit will
594167
+        have a dependency on an instance of the listed template with the same instance value. For example,
594167
+        <command>WantedBy=container@.target</command> in a service <filename>monitor@.service</filename> will
594167
+        result in <command>systemctl enable monitor@.service</command> creating a
594167
+        <filename>container@.target.wants/monitor@.service</filename> link to
594167
+        <filename>monitor@.service</filename>, which applies to all instances of
594167
+        <filename>container@.target</filename>.</para></listitem>
594167
       </varlistentry>
594167
 
594167
       <varlistentry>
594167
diff --git a/test/test-systemctl-enable.sh b/test/test-systemctl-enable.sh
594167
index 4117436462..3aa61222a8 100644
594167
--- a/test/test-systemctl-enable.sh
594167
+++ b/test/test-systemctl-enable.sh
594167
@@ -324,6 +324,31 @@ test ! -h "$root/etc/systemd/system/services.target.wants/templ1@333.service"
594167
 test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
594167
 test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
594167
 
594167
+: -------template enablement for another template-------------
594167
+cat >"$root/etc/systemd/system/templ2@.service" <
594167
+[Install]
594167
+RequiredBy=another-template@.target
594167
+EOF
594167
+
594167
+"$systemctl" --root="$root" enable 'templ2@.service'
594167
+islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
594167
+
594167
+"$systemctl" --root="$root" enable 'templ2@two.service'
594167
+islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
594167
+islink "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service" "/etc/systemd/system/templ2@.service"
594167
+
594167
+"$systemctl" --root="$root" disable 'templ2@other.service'
594167
+islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
594167
+islink "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service" "/etc/systemd/system/templ2@.service"
594167
+
594167
+"$systemctl" --root="$root" disable 'templ2@two.service'
594167
+islink "$root/etc/systemd/system/another-template@.target.requires/templ2@.service" "/etc/systemd/system/templ2@.service"
594167
+test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service"
594167
+
594167
+"$systemctl" --root="$root" disable 'templ2@.service'
594167
+test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@.service"
594167
+test ! -h "$root/etc/systemd/system/another-template@.target.requires/templ2@two.service"
594167
+
594167
 : -------aliases w/ and w/o instance--------------------------
594167
 test ! -e "$root/etc/systemd/system/link4.service"
594167
 cat >"$root/etc/systemd/system/link4.service" <
594167
@@ -529,6 +554,30 @@ check_alias % '%' && { echo "Expected failure because % is not legal in unit nam
594167
 
594167
 check_alias z 'z' && { echo "Expected failure because %z is not known" >&2; exit 1; }
594167
 
594167
+: -------specifiers in WantedBy-------------------------------
594167
+# We don't need to repeat all the tests. Let's do a basic check that specifier
594167
+# expansion is performed.
594167
+
594167
+cat >"$root/etc/systemd/system/some-some-link7.socket" <
594167
+[Install]
594167
+WantedBy=target@%p.target
594167
+WantedBy=another-target@.target
594167
+RequiredBy=target2@%p.target
594167
+RequiredBy=another-target2@.target
594167
+EOF
594167
+
594167
+"$systemctl" --root="$root" enable 'some-some-link7.socket'
594167
+islink "$root/etc/systemd/system/target@some-some-link7.target.wants/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
594167
+islink "$root/etc/systemd/system/another-target@.target.wants/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
594167
+islink "$root/etc/systemd/system/target2@some-some-link7.target.requires/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
594167
+islink "$root/etc/systemd/system/another-target2@.target.requires/some-some-link7.socket" "/etc/systemd/system/some-some-link7.socket"
594167
+
594167
+"$systemctl" --root="$root" disable 'some-some-link7.socket'
594167
+test ! -h "$root/etc/systemd/system/target@some-some-link7.target.wants/some-some-link7.socket"
594167
+test ! -h "$root/etc/systemd/system/another-target@.target.wants/some-some-link7.socket"
594167
+test ! -h "$root/etc/systemd/system/target2@some-some-link7.target.requires/some-some-link7.socket"
594167
+test ! -h "$root/etc/systemd/system/another-target2@.target.requires/some-some-link7.socket"
594167
+
594167
 # TODO: repeat the tests above for presets
594167
 
594167
 : -------SYSTEMD_OS_RELEASE relative to root------------------