richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
8d419f
From 2c9079ca0eaa2a1df2a1775c28fa7a49785999df Mon Sep 17 00:00:00 2001
8d419f
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
8d419f
Date: Mon, 28 Mar 2022 11:46:38 +0200
8d419f
Subject: [PATCH] man: clarify the descriptions of aliases and linked unit
8d419f
 files
8d419f
8d419f
This just describes the rules that are implemented by the manager, and this
8d419f
pull request does not change any of them.
8d419f
8d419f
(cherry picked from commit ecd6c000d3a2e743a0f533d427250714c7593cf7)
8d419f
8d419f
Related: #2082131
8d419f
---
8d419f
 man/systemd.unit.xml | 58 ++++++++++++++++++++++++++++++++------------
8d419f
 1 file changed, 43 insertions(+), 15 deletions(-)
8d419f
8d419f
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
8d419f
index 2a44b8cfd8..4ba602b5ad 100644
8d419f
--- a/man/systemd.unit.xml
8d419f
+++ b/man/systemd.unit.xml
8d419f
@@ -140,7 +140,7 @@
8d419f
     a symlink, so when <command>systemd</command> is asked through D-Bus to load
8d419f
     <filename>dbus-org.freedesktop.network1.service</filename>, it'll load
8d419f
     <filename>systemd-networkd.service</filename>. As another example, <filename>default.target</filename> —
8d419f
-    the default system target started at boot — is commonly symlinked (aliased) to either
8d419f
+    the default system target started at boot — is commonly aliased to either
8d419f
     <filename>multi-user.target</filename> or <filename>graphical.target</filename> to select what is started
8d419f
     by default. Alias names may be used in commands like <command>disable</command>,
8d419f
     <command>start</command>, <command>stop</command>, <command>status</command>, and similar, and in all
8d419f
@@ -156,8 +156,12 @@
8d419f
     template instance (e.g. <literal>alias@inst.service</literal>) may be a symlink to different template
8d419f
     (e.g. <literal>template@inst.service</literal>). In that case, just this specific instance is aliased,
8d419f
     while other instances of the template (e.g. <literal>alias@foo.service</literal>,
8d419f
-    <literal>alias@bar.service</literal>) are not aliased. Those rule preserve the requirement that the
8d419f
-    instance (if any) is always uniquely defined for a given unit and all its aliases.</para>
8d419f
+    <literal>alias@bar.service</literal>) are not aliased. Those rules preserve the requirement that the
8d419f
+    instance (if any) is always uniquely defined for a given unit and all its aliases. The target of alias
8d419f
+    symlink must point to a valid unit file location, i.e. the symlink target name must match the symlink
8d419f
+    source name as described, and the destination path must be in one of the unit search paths, see UNIT FILE
8d419f
+    LOAD PATH section below for more details. Note that the target file may not exist, i.e. the symlink may
8d419f
+    be dangling.</para>
8d419f
 
8d419f
     <para>Unit files may specify aliases through the <varname>Alias=</varname> directive in the [Install]
8d419f
     section. When the unit is enabled, symlinks will be created for those names, and removed when the unit is
8d419f
@@ -177,11 +181,18 @@
8d419f
     exists for <varname>Requires=</varname> type dependencies as well, the directory suffix is
8d419f
     <filename>.requires/</filename> in this case. This functionality is useful to hook units into the
8d419f
     start-up of other units, without having to modify their unit files. For details about the semantics of
8d419f
-    <varname>Wants=</varname>, see below. The preferred way to create symlinks in the
8d419f
-    <filename>.wants/</filename> or <filename>.requires/</filename> directory of a unit file is by embedding
8d419f
-    the dependency in [Install] section of the target unit, and creating the symlink in the file system with
8d419f
-    the <command>enable</command> or <command>preset</command> commands of
8d419f
-    <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para>
8d419f
+    <varname>Wants=</varname> and <varname>Requires=</varname>, see below. The preferred way to create
8d419f
+    symlinks in the <filename>.wants/</filename> or <filename>.requires/</filename> directories is by
8d419f
+    specifying the dependency in [Install] section of the target unit, and creating the symlink in the file
8d419f
+    system with the <command>enable</command> or <command>preset</command> commands of
8d419f
+    <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.  The
8d419f
+    target can be a normal unit (either plain or a specific instance of a template unit). In case when the
8d419f
+    source unit is a template, the target can also be a template, in which case the instance will be
8d419f
+    "propagated" to the target unit to form a valid unit instance. The target of symlinks in
8d419f
+    <filename>.wants/</filename> or <filename>.requires/</filename> must thus point to a valid unit file
8d419f
+    location, i.e. the symlink target name must satisfy the described requirements, and the destination path
8d419f
+    must be in one of the unit search paths, see UNIT FILE LOAD PATH section below for more details. Note
8d419f
+    that the target file may not exist, i.e. the symlink may be dangling.</para>
8d419f
 
8d419f
     <para>Along with a unit file <filename>foo.service</filename>, a "drop-in" directory
8d419f
     <filename>foo.service.d/</filename> may exist. All files with the suffix
8d419f
@@ -503,13 +514,30 @@
8d419f
     <programlisting>systemd-analyze --user unit-paths</programlisting>
8d419f
     </para>
8d419f
 
8d419f
-    <para>Moreover, additional units might be loaded into systemd from
8d419f
-    directories not on the unit load path by creating a symlink pointing to a
8d419f
-    unit file in the directories. You can use <command>systemctl link</command>
8d419f
-    for this operation. See
8d419f
-    <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
8d419f
-    for its usage and precaution.
8d419f
-    </para>
8d419f
+    <para>Moreover, additional units might be loaded into systemd from directories not on the unit load path
8d419f
+    by creating a symlink pointing to a unit file in the directories. You can use <command>systemctl
8d419f
+    link</command> for this; see
8d419f
+    <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>. The file
8d419f
+    system where the linked unit files are located must be accessible when systemd is started (e.g. anything
8d419f
+    underneath <filename>/home/</filename> or <filename>/var/</filename> is not allowed, unless those
8d419f
+    directories are located on the root file system).</para>
8d419f
+
8d419f
+    <para>It is important to distinguish "linked unit files" from "unit file aliases": any symlink where the
8d419f
+    symlink <emphasis>target</emphasis> is within the unit load path becomes an alias: the source name and
8d419f
+    the target file name must satisfy specific constraints listed above in the discussion of aliases, but the
8d419f
+    symlink target doesn't have to exist, and in fact the symlink target path is not used, except to check
8d419f
+    whether the target is within the unit load path. In constrast, a symlink which goes outside of the unit
8d419f
+    load path signifies a linked unit file. The symlink is followed when loading the file, but the
8d419f
+    destination name is otherwise unused (and may even not be a valid unit file name). For example, symlinks
8d419f
+    <filename index='false'>/etc/systemd/system/alias1.service</filename> → <filename index='false'>service1.service</filename>,
8d419f
+    <filename index='false'>/etc/systemd/system/alias2.service</filename> → <filename index='false'>/usr/lib/systemd/service1.service</filename>,
8d419f
+    <filename index='false'>/etc/systemd/system/alias3.service</filename> → <filename index='false'>/etc/systemd/system/service1.service</filename>
8d419f
+    are all valid aliases and <filename index='false'>service1.service</filename> will have
8d419f
+    four names, even if the unit file is located at
8d419f
+    <filename index='false'>/run/systemd/system/service1.service</filename>. In contrast,
8d419f
+    a symlink <filename index='false'>/etc/systemd/system/link1.service</filename> → <filename index='false'>../link1_service_file</filename>
8d419f
+    means that <filename index='false'>link1.service</filename> is a "linked unit" and the contents of
8d419f
+    <filename index='false'>/etc/systemd/link1_service_file</filename> provide its configuration.</para>
8d419f
   </refsect1>
8d419f
 
8d419f
   <refsect1>