|
138 | 138 | a symlink, so when <command>systemd</command> is asked through D-Bus to load |
139 | 139 | <filename>dbus-org.freedesktop.network1.service</filename>, it'll load |
140 | 140 | <filename>systemd-networkd.service</filename>. As another example, <filename>default.target</filename> — |
141 | | - the default system target started at boot — is commonly symlinked (aliased) to either |
| 141 | + the default system target started at boot — is commonly aliased to either |
142 | 142 | <filename>multi-user.target</filename> or <filename>graphical.target</filename> to select what is started |
143 | 143 | by default. Alias names may be used in commands like <command>disable</command>, |
144 | 144 | <command>start</command>, <command>stop</command>, <command>status</command>, and similar, and in all |
|
154 | 154 | template instance (e.g. <literal>alias@inst.service</literal>) may be a symlink to different template |
155 | 155 | (e.g. <literal>template@inst.service</literal>). In that case, just this specific instance is aliased, |
156 | 156 | while other instances of the template (e.g. <literal>alias@foo.service</literal>, |
157 | | - <literal>alias@bar.service</literal>) are not aliased. Those rule preserve the requirement that the |
158 | | - instance (if any) is always uniquely defined for a given unit and all its aliases.</para> |
| 157 | + <literal>alias@bar.service</literal>) are not aliased. Those rules preserve the requirement that the |
| 158 | + instance (if any) is always uniquely defined for a given unit and all its aliases. The target of alias |
| 159 | + symlink must point to a valid unit file location, i.e. the symlink target name must match the symlink |
| 160 | + source name as described, and the destination path must be in one of the unit search paths, see UNIT FILE |
| 161 | + LOAD PATH section below for more details. Note that the target file may not exist, i.e. the symlink may |
| 162 | + be dangling.</para> |
159 | 163 |
|
160 | 164 | <para>Unit files may specify aliases through the <varname>Alias=</varname> directive in the [Install] |
161 | 165 | section. When the unit is enabled, symlinks will be created for those names, and removed when the unit is |
|
175 | 179 | exists for <varname>Requires=</varname> type dependencies as well, the directory suffix is |
176 | 180 | <filename>.requires/</filename> in this case. This functionality is useful to hook units into the |
177 | 181 | start-up of other units, without having to modify their unit files. For details about the semantics of |
178 | | - <varname>Wants=</varname>, see below. The preferred way to create symlinks in the |
179 | | - <filename>.wants/</filename> or <filename>.requires/</filename> directory of a unit file is by embedding |
180 | | - the dependency in [Install] section of the target unit, and creating the symlink in the file system with |
181 | | - the <command>enable</command> or <command>preset</command> commands of |
182 | | - <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para> |
| 182 | + <varname>Wants=</varname> and <varname>Requires=</varname>, see below. The preferred way to create |
| 183 | + symlinks in the <filename>.wants/</filename> or <filename>.requires/</filename> directories is by |
| 184 | + specifying the dependency in [Install] section of the target unit, and creating the symlink in the file |
| 185 | + system with the <command>enable</command> or <command>preset</command> commands of |
| 186 | + <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>. The |
| 187 | + target can be a normal unit (either plain or a specific instance of a template unit). In case when the |
| 188 | + source unit is a template, the target can also be a template, in which case the instance will be |
| 189 | + "propagated" to the target unit to form a valid unit instance. The target of symlinks in |
| 190 | + <filename>.wants/</filename> or <filename>.requires/</filename> must thus point to a valid unit file |
| 191 | + location, i.e. the symlink target name must satisfy the described requirements, and the destination path |
| 192 | + must be in one of the unit search paths, see UNIT FILE LOAD PATH section below for more details. Note |
| 193 | + that the target file may not exist, i.e. the symlink may be dangling.</para> |
183 | 194 |
|
184 | 195 | <para>Along with a unit file <filename>foo.service</filename>, a "drop-in" directory |
185 | 196 | <filename>foo.service.d/</filename> may exist. All files with the suffix |
|
501 | 512 | <programlisting>systemd-analyze --user unit-paths</programlisting> |
502 | 513 | </para> |
503 | 514 |
|
504 | | - <para>Moreover, additional units might be loaded into systemd from |
505 | | - directories not on the unit load path by creating a symlink pointing to a |
506 | | - unit file in the directories. You can use <command>systemctl link</command> |
507 | | - for this operation. See |
508 | | - <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
509 | | - for its usage and precaution. |
510 | | - </para> |
| 515 | + <para>Moreover, additional units might be loaded into systemd from directories not on the unit load path |
| 516 | + by creating a symlink pointing to a unit file in the directories. You can use <command>systemctl |
| 517 | + link</command> for this; see |
| 518 | + <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>. The file |
| 519 | + system where the linked unit files are located must be accessible when systemd is started (e.g. anything |
| 520 | + underneath <filename>/home/</filename> or <filename>/var/</filename> is not allowed, unless those |
| 521 | + directories are located on the root file system).</para> |
| 522 | + |
| 523 | + <para>It is important to distinguish "linked unit files" from "unit file aliases": any symlink where the |
| 524 | + symlink <emphasis>target</emphasis> is within the unit load path becomes an alias: the source name and |
| 525 | + the target file name must satisfy specific constraints listed above in the discussion of aliases, but the |
| 526 | + symlink target doesn't have to exist, and in fact the symlink target path is not used, except to check |
| 527 | + whether the target is within the unit load path. In constrast, a symlink which goes outside of the unit |
| 528 | + load path signifies a linked unit file. The symlink is followed when loading the file, but the |
| 529 | + destination name is otherwise unused (and may even not be a valid unit file name). For example, symlinks |
| 530 | + <filename index='false'>/etc/systemd/system/alias1.service</filename> → <filename index='false'>service1.service</filename>, |
| 531 | + <filename index='false'>/etc/systemd/system/alias2.service</filename> → <filename index='false'>/usr/lib/systemd/service1.service</filename>, |
| 532 | + <filename index='false'>/etc/systemd/system/alias3.service</filename> → <filename index='false'>/etc/systemd/system/service1.service</filename> |
| 533 | + are all valid aliases and <filename index='false'>service1.service</filename> will have |
| 534 | + four names, even if the unit file is located at |
| 535 | + <filename index='false'>/run/systemd/system/service1.service</filename>. In contrast, |
| 536 | + a symlink <filename index='false'>/etc/systemd/system/link1.service</filename> → <filename index='false'>../link1_service_file</filename> |
| 537 | + means that <filename index='false'>link1.service</filename> is a "linked unit" and the contents of |
| 538 | + <filename index='false'>/etc/systemd/link1_service_file</filename> provide its configuration.</para> |
511 | 539 | </refsect1> |
512 | 540 |
|
513 | 541 | <refsect1> |
|
1876 | 1904 | <term><varname>WantedBy=</varname></term> |
1877 | 1905 | <term><varname>RequiredBy=</varname></term> |
1878 | 1906 |
|
1879 | | - <listitem><para>This option may be used more than once, or a |
1880 | | - space-separated list of unit names may be given. A symbolic |
1881 | | - link is created in the <filename>.wants/</filename> or |
1882 | | - <filename>.requires/</filename> directory of each of the |
1883 | | - listed units when this unit is installed by <command>systemctl |
1884 | | - enable</command>. This has the effect that a dependency of |
1885 | | - type <varname>Wants=</varname> or <varname>Requires=</varname> |
1886 | | - is added from the listed unit to the current unit. The primary |
1887 | | - result is that the current unit will be started when the |
1888 | | - listed unit is started. See the description of |
1889 | | - <varname>Wants=</varname> and <varname>Requires=</varname> in |
1890 | | - the [Unit] section for details.</para> |
1891 | | - |
1892 | | - <para><command>WantedBy=foo.service</command> in a service |
1893 | | - <filename>bar.service</filename> is mostly equivalent to |
1894 | | - <command>Alias=foo.service.wants/bar.service</command> in the |
1895 | | - same file. In case of template units listing non template units, |
1896 | | - <command>systemctl enable</command> must be called with an |
1897 | | - instance name, and this instance will be added to the |
1898 | | - <filename>.wants/</filename> or |
1899 | | - <filename>.requires/</filename> list of the listed unit. E.g. |
1900 | | - <command>WantedBy=getty.target</command> in a service |
1901 | | - <filename>getty@.service</filename> will result in |
1902 | | - <command>systemctl enable getty@tty2.service</command> |
1903 | | - creating a |
1904 | | - <filename>getty.target.wants/getty@tty2.service</filename> |
1905 | | - link to <filename>getty@.service</filename>. |
1906 | | - </para></listitem> |
| 1907 | + <listitem><para>This option may be used more than once, or a space-separated list of unit names may |
| 1908 | + be given. A symbolic link is created in the <filename>.wants/</filename> or |
| 1909 | + <filename>.requires/</filename> directory of each of the listed units when this unit is installed by |
| 1910 | + <command>systemctl enable</command>. This has the effect of a dependency of type |
| 1911 | + <varname>Wants=</varname> or <varname>Requires=</varname> being added from the listed unit to the |
| 1912 | + current unit. The primary result is that the current unit will be started when the listed unit is |
| 1913 | + started, see the description of <varname>Wants=</varname> and <varname>Requires=</varname> in the |
| 1914 | + [Unit] section for details.</para> |
| 1915 | + |
| 1916 | + <para>In case of template units listing non template units, the listing unit must have |
| 1917 | + <varname>DefaultInstance=</varname> set, or <command>systemctl enable</command> must be called with |
| 1918 | + an instance name. The instance (default or specified) will be added to the |
| 1919 | + <filename>.wants/</filename> or <filename>.requires/</filename> list of the listed unit. For example, |
| 1920 | + <command>WantedBy=getty.target</command> in a service <filename>getty@.service</filename> will result |
| 1921 | + in <command>systemctl enable getty@tty2.service</command> creating a |
| 1922 | + <filename>getty.target.wants/getty@tty2.service</filename> link to |
| 1923 | + <filename>getty@.service</filename>. This also applies to listing specific instances of templated |
| 1924 | + units: this specific instance will gain the dependency. A template unit may also list a template |
| 1925 | + unit, in which case a generic dependency will be added where each instance of the listing unit will |
| 1926 | + have a dependency on an instance of the listed template with the same instance value. For example, |
| 1927 | + <command>WantedBy=container@.target</command> in a service <filename>monitor@.service</filename> will |
| 1928 | + result in <command>systemctl enable monitor@.service</command> creating a |
| 1929 | + <filename>container@.target.wants/monitor@.service</filename> link to |
| 1930 | + <filename>monitor@.service</filename>, which applies to all instances of |
| 1931 | + <filename>container@.target</filename>.</para></listitem> |
1907 | 1932 | </varlistentry> |
1908 | 1933 |
|
1909 | 1934 | <varlistentry> |
|
0 commit comments