| 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.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="systemd.target"> |
| 7 |
<refentryinfo> |
| 8 |
<title>systemd.target</title> |
| 9 |
<productname>systemd</productname> |
| 10 |
</refentryinfo> |
| 11 |
|
| 12 |
<refmeta> |
| 13 |
<refentrytitle>systemd.target</refentrytitle> |
| 14 |
<manvolnum>5</manvolnum> |
| 15 |
</refmeta> |
| 16 |
|
| 17 |
<refnamediv> |
| 18 |
<refname>systemd.target</refname> |
| 19 |
<refpurpose>Target unit configuration</refpurpose> |
| 20 |
</refnamediv> |
| 21 |
|
| 22 |
<refsynopsisdiv> |
| 23 |
<para><filename><replaceable>target</replaceable>.target</filename></para> |
| 24 |
</refsynopsisdiv> |
| 25 |
|
| 26 |
<refsect1> |
| 27 |
<title>Description</title> |
| 28 |
|
| 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> |
| 32 |
|
| 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> |
| 38 |
|
| 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> |
| 46 |
|
| 47 |
<para>Target units provide a more flexible replacement for SysV runlevels in the classic SysV init |
| 48 |
system.</para> |
| 49 |
|
| 50 |
<para>Note that a target unit file must not be empty, lest it be considered a masked unit. It is |
| 51 |
recommended to provide a [Unit] section which includes informative <varname>Description=</varname> and |
| 52 |
<varname>Documentation=</varname> options.</para> |
| 53 |
</refsect1> |
| 54 |
|
| 55 |
<refsect1> |
| 56 |
<title>Automatic Dependencies</title> |
| 57 |
|
| 58 |
<refsect2> |
| 59 |
<title>Implicit Dependencies</title> |
| 60 |
|
| 61 |
<para>There are no implicit dependencies for target units.</para> |
| 62 |
</refsect2> |
| 63 |
|
| 64 |
<refsect2> |
| 65 |
<title>Default Dependencies</title> |
| 66 |
|
| 67 |
<para>The following dependencies are added unless |
| 68 |
<varname>DefaultDependencies=no</varname> is set:</para> |
| 69 |
|
| 70 |
<itemizedlist> |
| 71 |
<listitem><para>Target units will automatically complement all configured dependencies of type |
| 72 |
<varname>Wants=</varname> or <varname>Requires=</varname> with dependencies of type |
| 73 |
<varname>After=</varname> unless <varname>DefaultDependencies=no</varname> is set in the specified |
| 74 |
units.</para> |
| 75 |
|
| 76 |
<para>Note that the reverse is not true. For example, defining <option>Wants=that.target</option> in |
| 77 |
<filename index='false'>some.service</filename> will not automatically add the |
| 78 |
<option>After=that.target</option> ordering dependency for <filename>some.service</filename>. |
| 79 |
Instead, <filename>some.service</filename> should use the primary synchronization function of target |
| 80 |
type units, by setting a specific <option>After=that.target</option> or |
| 81 |
<option>Before=that.target</option> ordering dependency in its .service unit file. |
| 82 |
</para></listitem> |
| 83 |
|
| 84 |
<listitem><para>Target units automatically gain <varname>Conflicts=</varname> |
| 85 |
and <varname>Before=</varname> dependencies against |
| 86 |
<filename>shutdown.target</filename>.</para></listitem> |
| 87 |
</itemizedlist> |
| 88 |
</refsect2> |
| 89 |
</refsect1> |
| 90 |
|
| 91 |
<refsect1> |
| 92 |
<title>Options</title> |
| 93 |
|
| 94 |
<para>Target unit files may include [Unit] and [Install] sections, which are described in |
| 95 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 96 |
No options specific to this file type are supported.</para> |
| 97 |
</refsect1> |
| 98 |
|
| 99 |
<refsect1> |
| 100 |
<title>Example</title> |
| 101 |
|
| 102 |
<example> |
| 103 |
<title>Simple standalone target</title> |
| 104 |
|
| 105 |
<programlisting># emergency-net.target |
| 106 |
|
| 107 |
[Unit] |
| 108 |
Description=Emergency Mode with Networking |
| 109 |
Requires=emergency.target systemd-networkd.service |
| 110 |
After=emergency.target systemd-networkd.service |
| 111 |
AllowIsolate=yes</programlisting> |
| 112 |
|
| 113 |
<para>When adding dependencies to other units, it is important to check if they set |
| 114 |
<varname>DefaultDependencies=</varname>. Service units, unless they set |
| 115 |
<varname>DefaultDependencies=no</varname>, automatically get a dependency on |
| 116 |
<filename>sysinit.target</filename>. In this case, both |
| 117 |
<filename>emergency.target</filename> and <filename>systemd-networkd.service</filename> |
| 118 |
have <varname>DefaultDependencies=no</varname>, so they are suitable for use |
| 119 |
in this target, and do not pull in <filename>sysinit.target</filename>.</para> |
| 120 |
|
| 121 |
<para>You can now switch into this emergency mode by running <varname>systemctl |
| 122 |
isolate emergency-net.target</varname> or by passing the option |
| 123 |
<varname>systemd.unit=emergency-net.target</varname> on the kernel command |
| 124 |
line.</para> |
| 125 |
|
| 126 |
<para>Other units can have <varname>WantedBy=emergency-net.target</varname> in the |
| 127 |
<varname>[Install]</varname> section. After they are enabled using |
| 128 |
<command>systemctl enable</command>, they will be started before |
| 129 |
<varname>emergency-net.target</varname> is started. It is also possible to add |
| 130 |
arbitrary units as dependencies of <filename>emergency.target</filename> without |
| 131 |
modifying them by using <command>systemctl add-wants</command>. |
| 132 |
</para> |
| 133 |
</example> |
| 134 |
</refsect1> |
| 135 |
|
| 136 |
<refsect1> |
| 137 |
<title>See Also</title> |
| 138 |
<para><simplelist type="inline"> |
| 139 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 140 |
<member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 141 |
<member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 142 |
<member><citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 143 |
<member><citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 144 |
</simplelist></para> |
| 145 |
</refsect1> |
| 146 |
|
| 147 |
</refentry> |