Skip to content

Commit 3bdf40c

Browse files
committed
set targets
1 parent c4ca82b commit 3bdf40c

File tree

1 file changed

+125
-7
lines changed

1 file changed

+125
-7
lines changed

concepts/systemd-targets.xml

Lines changed: 125 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@
1515
xmlns:xlink="http://www.w3.org/1999/xlink"
1616
xmlns:trans="http://docbook.org/ns/transclusion">
1717
<info>
18-
<title>&systemd; targets</title> <!-- can be changed via merge in the assembly -->
18+
<title>Understanding &systemd; targets</title> <!-- can be changed via merge in the assembly -->
1919
<!--add author's email address-->
2020
<meta name="maintainer" content="[email protected]" its:translate="no"/>
2121
<abstract> <!-- can be changed via merge in the assembly -->
2222
<para>
2323
&systemd; uses units and targets. A &systemd; unit defines a service or action on the system, which consists of a name, type, and configuration file.
24-
A &systemd; target combines several units and defines which services have to be started to reach the target.
24+
</para>
25+
</abstract>
26+
</info>
27+
<section xml:id="systemd-what-are-targets">
28+
<title>What are &systemd; targets?</title>
29+
<para>
30+
A &systemd; target combines several units and defines which services have to be started to reach the target.
2531
On a server, for example, this is a state where the network is running and multiple users can log in.
2632
These files are identified by the suffix <literal>.target</literal>.
2733
</para>
2834
<para>Similar to unit files, different targets may be nested via dependencies. For example, <literal>multi-user.target</literal> requires (among others) the targets
2935
that set up login and user session services.
3036
</para>
31-
</abstract>
32-
</info>
33-
<para>
37+
<para>
3438
Common &systemd; targets:
3539
</para>
3640
<variablelist>
@@ -87,7 +91,121 @@
8791
</listitem>
8892
</varlistentry>
8993
</variablelist>
90-
<para>For more information on &systemd; targets, refer to <emphasis>man 5 systemd.target</emphasis>
91-
and <emphasis>man 7 systemd.special</emphasis>.
94+
</section>
95+
<section xml:id="systemd-set-targets">
96+
<title>Setting up a &systemd; target</title>
97+
<para>To set up a &systemd; target, you need to create a new target unit file and define any required dependencies.
98+
A target is a group of unit files that manages the state of services. A target can be used to control groups of services
99+
or define system states.</para>
100+
<procedure>
101+
<step>
102+
<para>Create a new file with the <literal>.target</literal> extension in <filename>/etc/systemd/system/</filename>. </para>
103+
<para>For example:</para>
104+
<screen>&prompt.sudo; <command>vi /etc/systemd/system/test.target</command></screen>
105+
</step>
106+
<step>
107+
<para>Define the target with basic configuration.</para>
108+
<para>For example:</para>
109+
<screen>[Unit]
110+
Description= Test target
111+
Requires=multi-user.target
112+
After=multi-user.target
113+
114+
[Install]
115+
WantedBy=multi-user.target
116+
</screen>
117+
<itemizedlist>
118+
<listitem>
119+
<para>
120+
<emphasis>Requires:</emphasis> specifies that <literal>multi-user.target</literal> must be reached
121+
for <literal>test.target</literal> to be active.
92122
</para>
123+
</listitem>
124+
<listitem>
125+
<para>
126+
<emphasis>After:</emphasis> specifies that this target starts after the <literal>multi-user.target</literal>.
127+
</para>
128+
</listitem>
129+
<listitem>
130+
<para>
131+
<emphasis>WantedBy:</emphasis> specifies that this target should be a part of <literal>multi-user.target</literal>.
132+
</para>
133+
</listitem>
134+
</itemizedlist>
135+
</step>
136+
<step>
137+
<para>Set permissions for the target file. </para>
138+
<para>For example:</para>
139+
<screen>&prompt.sudo; <command>chmod 644 /etc/systemd/system/test.target
140+
</command></screen> </step>
141+
<step>
142+
<para>Link the required services to the target file. Create a <literal>.wants</literal> directory and then create
143+
symbolic links to the services you want to include in your custom target.</para>
144+
<para>For example:</para>
145+
<screen>&prompt.sudo; <command>mkdir -p /etc/systemd/system/custom.target.wants/ </command></screen>
146+
<screen>&prompt.sudo; <command>ln -s /etc/systemd/system/test.service /etc/systemd/system/custom.target.wants/
147+
</command></screen>
148+
</step>
149+
<step>
150+
<para>Reload &systemd;. </para>
151+
<para>For example:</para>
152+
<screen>&prompt.sudo; <command>systemctl daemon-reload</command></screen> </step>
153+
<step>
154+
<para>Start and enable the target. </para>
155+
<para>For example:</para>
156+
<screen>&prompt.sudo; <command>systemctl start test.target</command></screen>
157+
<screen>&prompt.sudo; <command>systemctl enable test.target</command></screen>
158+
</step>
159+
<step>
160+
<para>Verify the status of the custom target. </para>
161+
<para>For example:</para>
162+
<screen>&prompt.sudo; <command>systemctl status test.target</command></screen>
163+
</step>
164+
<step>
165+
<para>Verify all the units that are part of this target. </para>
166+
<para>For example:</para>
167+
<screen>&prompt.sudo; <command>systemctl list-dependencies test.target </command></screen>
168+
</step>
169+
<step><para>Your custom &systemd; target is set up and configured.</para></step>
170+
</procedure>
171+
<para>You can use the following common configuration options: </para>
172+
<itemizedlist>
173+
<listitem>
174+
<para>
175+
<emphasis>Description:</emphasis> human-readable description of the target.
176+
</para>
177+
</listitem>
178+
<listitem>
179+
<para>
180+
<emphasis>Documentation:</emphasis> URIs to documentation.</para>
181+
</listitem>
182+
<listitem>
183+
<para>
184+
<emphasis>AllowIsolate:</emphasis>
185+
If set to <literal>true</literal>, this unit can be used with the <command>systemctl isolate</command> command.
186+
</para>
187+
</listitem>
188+
<listitem>
189+
<para>
190+
<emphasis>Wants:</emphasis>
191+
Units that can be started but is not mandatory.
192+
</para>
193+
</listitem>
194+
<listitem>
195+
<para>
196+
<emphasis>After/Before:</emphasis>
197+
the order of the dependency.
198+
</para>
199+
</listitem>
200+
<listitem>
201+
<para>
202+
<emphasis>Conflicts:</emphasis>
203+
units that should not be active while this target is active.
204+
</para>
205+
</listitem>
206+
</itemizedlist>
207+
<para>For more information on &systemd; targets, refer to <emphasis>man 5 systemd.target</emphasis>
208+
and <emphasis>man 7 systemd.special</emphasis>.
209+
</para>
210+
</section>
93211
</topic>

0 commit comments

Comments
 (0)