doc: Add an example for target units (#5951)

This adds an example target unit to the man page of systemd targets.

Closes #67.
This commit is contained in:
Janne Heß 2017-06-27 09:50:28 +02:00 committed by Lennart Poettering
parent 23e4a234fc
commit 259d1af8d6
1 changed files with 37 additions and 0 deletions

View File

@ -98,6 +98,43 @@
</refsect1>
<refsect1>
<title>Example</title>
<example>
<title>Simple standalone target</title>
<programlisting># emergency-net.target
[Unit]
Description=Emergency Mode with Networking
Requires=emergency.target systemd-networkd.service
After=emergency.target systemd-networkd.service
AllowIsolate=yes</programlisting>
<para>When adding dependencies to other units, it's important to check if they set
<varname>DefaultDependencies=</varname>. Service units, unless they set
<varname>DefaultDependencies=no</varname>, automatically get a dependency on
<filename>sysinit.target</filename>. In this case, both
<filename>emergency.target</filename> and <filename>systemd-networkd.service</filename>
have <varname>DefaultDependencies=no</varname>, so they are suitable for use
in this target, and do not pull in <filename>sysinit.target</filename>.</para>
<para>You can now switch into this emergency mode by running <varname>systemctl
isolate emergency-net.target</varname> or by passing the option
<varname>systemd.unit=emergency-net.target</varname> on the kernel command
line.</para>
<para>Other units can have <varname>WantedBy=emergency-net.target</varname> in the
<varname>[Install]</varname> section. After they are enabled using
<command>systemctl enable</command>, they will be started before
<varname>emergency-net.target</varname> is started. It is also possible to add
arbitrary units as dependencies of <filename>emergency.target</filename> without
modifying them by using <command>systemctl add-wants</command>.
</para>
</example>
</refsect1>
<refsect1>
<title>See Also</title>
<para>