1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="systemd.target">
8 <title>systemd.target</title>
9 <productname>systemd</productname>
13 <refentrytitle>systemd.target</refentrytitle>
14 <manvolnum>5</manvolnum>
18 <refname>systemd.target</refname>
19 <refpurpose>Target unit configuration</refpurpose>
23 <para><filename><replaceable>target</replaceable>.target</filename></para>
27 <title>Description</title>
29 <para>A unit configuration file whose name ends in <literal>.target</literal> encodes information about a
30 target unit of systemd. Target units are used to group units and to set synchronization points for
31 ordering dependencies with other unit files.</para>
33 <para>This unit type has no specific options. See
34 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for the
35 common options of all unit configuration files. The common configuration items are configured in the
36 generic [Unit] and [Install] sections. A separate [Target] section does not exist, since no
37 target-specific options may be configured.</para>
39 <para>Target units do not offer any additional functionality on top of the generic functionality provided
40 by units. They merely group units, allowing a single target name to be used in <varname>Wants=</varname>
41 and <varname>Requires=</varname> settings to establish a dependency on a set of units defined by the
42 target, and in <varname>Before=</varname> and <varname>After=</varname> settings to establish ordering.
43 Targets establish standardized names for synchronization points during boot and shutdown. Importantly,
44 see <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>
45 for examples and descriptions of standard systemd targets.</para>
47 <para>Target units provide a more flexible replacement for SysV runlevels in the classic SysV init
48 system. For compatibility reasons special target units such as <filename>runlevel3.target</filename>
49 exist which are used by the SysV runlevel compatibility code in systemd, see
50 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
53 <para>Note that a target unit file must not be empty, lest it be considered a masked unit. It is
54 recommended to provide a [Unit] section which includes informative <varname>Description=</varname> and
55 <varname>Documentation=</varname> options.</para>
59 <title>Automatic Dependencies</title>
62 <title>Implicit Dependencies</title>
64 <para>There are no implicit dependencies for target units.</para>
68 <title>Default Dependencies</title>
70 <para>The following dependencies are added unless
71 <varname>DefaultDependencies=no</varname> is set:</para>
74 <listitem><para>Target units will automatically complement all configured dependencies of type
75 <varname>Wants=</varname> or <varname>Requires=</varname> with dependencies of type
76 <varname>After=</varname> unless <varname>DefaultDependencies=no</varname> is set in the specified
79 <para>Note that the reverse is not true. For example, defining <option>Wants=that.target</option> in
80 <filename index='false'>some.service</filename> will not automatically add the
81 <option>After=that.target</option> ordering dependency for <filename>some.service</filename>.
82 Instead, <filename>some.service</filename> should use the primary synchronization function of target
83 type units, by setting a specific <option>After=that.target</option> or
84 <option>Before=that.target</option> ordering dependency in its .service unit file.
87 <listitem><para>Target units automatically gain <varname>Conflicts=</varname>
88 and <varname>Before=</varname> dependencies against
89 <filename>shutdown.target</filename>.</para></listitem>
95 <title>Options</title>
97 <para>Target unit files may include [Unit] and [Install] sections, which are described in
98 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
99 No options specific to this file type are supported.</para>
103 <title>Example</title>
106 <title>Simple standalone target</title>
108 <programlisting># emergency-net.target
111 Description=Emergency Mode with Networking
112 Requires=emergency.target systemd-networkd.service
113 After=emergency.target systemd-networkd.service
114 AllowIsolate=yes</programlisting>
116 <para>When adding dependencies to other units, it's important to check if they set
117 <varname>DefaultDependencies=</varname>. Service units, unless they set
118 <varname>DefaultDependencies=no</varname>, automatically get a dependency on
119 <filename>sysinit.target</filename>. In this case, both
120 <filename>emergency.target</filename> and <filename>systemd-networkd.service</filename>
121 have <varname>DefaultDependencies=no</varname>, so they are suitable for use
122 in this target, and do not pull in <filename>sysinit.target</filename>.</para>
124 <para>You can now switch into this emergency mode by running <varname>systemctl
125 isolate emergency-net.target</varname> or by passing the option
126 <varname>systemd.unit=emergency-net.target</varname> on the kernel command
129 <para>Other units can have <varname>WantedBy=emergency-net.target</varname> in the
130 <varname>[Install]</varname> section. After they are enabled using
131 <command>systemctl enable</command>, they will be started before
132 <varname>emergency-net.target</varname> is started. It is also possible to add
133 arbitrary units as dependencies of <filename>emergency.target</filename> without
134 modifying them by using <command>systemctl add-wants</command>.
140 <title>See Also</title>
142 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
143 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
144 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
145 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
146 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>