]> git.ipfire.org Git - thirdparty/systemd.git/blame_incremental - man/systemd.exec.xml
pidref: propagate critical errors in pidref_acquire_pidfd_id()
[thirdparty/systemd.git] / man / systemd.exec.xml
... / ...
CommitLineData
1<?xml version='1.0'?>
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.exec" xmlns:xi="http://www.w3.org/2001/XInclude">
7 <refentryinfo>
8 <title>systemd.exec</title>
9 <productname>systemd</productname>
10 </refentryinfo>
11
12 <refmeta>
13 <refentrytitle>systemd.exec</refentrytitle>
14 <manvolnum>5</manvolnum>
15 </refmeta>
16
17 <refnamediv>
18 <refname>systemd.exec</refname>
19 <refpurpose>Execution environment configuration</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23 <para><filename><replaceable>service</replaceable>.service</filename>,
24 <filename><replaceable>socket</replaceable>.socket</filename>,
25 <filename><replaceable>mount</replaceable>.mount</filename>,
26 <filename><replaceable>swap</replaceable>.swap</filename></para>
27 </refsynopsisdiv>
28
29 <refsect1>
30 <title>Description</title>
31
32 <para>Unit configuration files for services, sockets, mount points, and swap devices share a subset of
33 configuration options which define the execution environment of spawned processes.</para>
34
35 <para>This man page lists the configuration options shared by these four unit types. See
36 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for the common
37 options of all unit configuration files, and
38 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
39 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
40 <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>, and
41 <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
42 information on the specific unit configuration files. The execution specific configuration options are configured
43 in the [Service], [Socket], [Mount], or [Swap] sections, depending on the unit type.</para>
44
45 <para>In addition, options which control resources through Linux Control Groups (cgroups) are listed in
46 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
47 Those options complement options listed here.</para>
48 </refsect1>
49
50 <refsect1>
51 <title>Implicit Dependencies</title>
52
53 <para>A few execution parameters result in additional, automatic dependencies to be added:</para>
54
55 <itemizedlist>
56 <listitem><para>Units with <varname>WorkingDirectory=</varname>, <varname>RootDirectory=</varname>,
57 <varname>RootImage=</varname>, <varname>RuntimeDirectory=</varname>, <varname>StateDirectory=</varname>,
58 <varname>CacheDirectory=</varname>, <varname>LogsDirectory=</varname> or
59 <varname>ConfigurationDirectory=</varname> set automatically gain dependencies of type
60 <varname>Requires=</varname> and <varname>After=</varname> on all mount units required to access the specified
61 paths. This is equivalent to having them listed explicitly in
62 <varname>RequiresMountsFor=</varname>.</para></listitem>
63
64 <listitem><para>Units with <varname>PrivateTmp=yes</varname> automatically gain dependencies of type
65 <varname>Wants=</varname> and <varname>After=</varname> on all mounts required to access
66 <filename>/tmp/</filename> and <filename>/var/tmp/</filename>. They will also gain an automatic
67 <varname>After=</varname> dependency on
68 <citerefentry><refentrytitle>systemd-tmpfiles-setup.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
69 </para></listitem>
70
71 <listitem><para>Units with <varname>PrivateTmp=disconnected</varname> automatically gain dependencies
72 of type <varname>Wants=</varname> and <varname>After=</varname> on the mount required to access
73 <filename>/var/</filename>, unless <varname>DefaultDependencies=no</varname> and/or
74 <varname>RootDirectory=/RootImage=</varname> are specified.</para></listitem>
75
76 <listitem><para>Units whose standard output or error output is connected to <option>journal</option> or
77 <option>kmsg</option> (or their combinations with console output, see below) automatically acquire
78 dependencies of type <varname>After=</varname> on
79 <filename>systemd-journald.socket</filename>.</para></listitem>
80
81 <listitem><para>Units using <varname>LogNamespace=</varname> will automatically gain ordering and
82 requirement dependencies on the two socket units associated with
83 <filename>systemd-journald@.service</filename> instances.</para></listitem>
84 </itemizedlist>
85 </refsect1>
86
87 <!-- We do not have any default dependency here. -->
88
89 <refsect1>
90 <title>Paths</title>
91
92 <para>The following settings may be used to change a service's view of the filesystem. Please note that the paths
93 must be absolute and must not contain a <literal>..</literal> path component.</para>
94
95 <variablelist class='unit-directives'>
96
97 <varlistentry>
98 <term><varname>ExecSearchPath=</varname></term>
99
100 <listitem><para>Takes a colon separated list of absolute paths relative to which the executable
101 used by the <varname>Exec*=</varname> (e.g. <varname>ExecStart=</varname>,
102 <varname>ExecStop=</varname>, etc.) properties can be found. <varname>ExecSearchPath=</varname>
103 overrides <varname>$PATH</varname> if <varname>$PATH</varname> is not supplied by the user through
104 <varname>Environment=</varname>, <varname>EnvironmentFile=</varname> or
105 <varname>PassEnvironment=</varname>. Assigning an empty string removes previous assignments
106 and setting <varname>ExecSearchPath=</varname> to a value multiple times will append
107 to the previous setting.
108 </para>
109
110 <xi:include href="version-info.xml" xpointer="v250"/></listitem>
111 </varlistentry>
112
113 <varlistentry>
114 <term><varname>WorkingDirectory=</varname></term>
115
116 <listitem><para>Takes a directory path relative to the service's root directory specified by
117 <varname>RootDirectory=</varname>, or the special value <literal>~</literal>. Sets the working directory for
118 executed processes. If set to <literal>~</literal>, the home directory of the user specified in
119 <varname>User=</varname> is used. If not set, defaults to the root directory when systemd is running as a
120 system instance and the respective user's home directory if run as user. If the setting is prefixed with the
121 <literal>-</literal> character, a missing working directory is not considered fatal. If
122 <varname>RootDirectory=</varname>/<varname>RootImage=</varname> is not set, then
123 <varname>WorkingDirectory=</varname> is relative to the root of the system running the service manager. Note
124 that setting this parameter might result in additional dependencies to be added to the unit (see
125 above).</para></listitem>
126 </varlistentry>
127
128 <varlistentry>
129 <term><varname>RootDirectory=</varname></term>
130
131 <listitem><para>Takes a directory path relative to the host's root directory (i.e. the root of the system
132 running the service manager). Sets the root directory for executed processes, with the <citerefentry
133 project='man-pages'><refentrytitle>pivot_root</refentrytitle><manvolnum>2</manvolnum></citerefentry>
134 or <citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>2</manvolnum></citerefentry>
135 system call. If this is used, it must be ensured that the process binary and all its auxiliary files
136 are available in the new root. Note that setting this parameter might result in additional
137 dependencies to be added to the unit (see above).</para>
138
139 <para>The <varname>MountAPIVFS=</varname> and <varname>PrivateUsers=</varname> settings are particularly useful
140 in conjunction with <varname>RootDirectory=</varname>. For details, see below.</para>
141
142 <para>If <varname>RootDirectory=</varname>/<varname>RootImage=</varname> are used together with
143 <varname>NotifyAccess=</varname> the notification socket is automatically mounted from the host into
144 the root environment, to ensure the notification interface can work correctly.</para>
145
146 <para>Note that services using <varname>RootDirectory=</varname>/<varname>RootImage=</varname> will
147 not be able to log via the syslog or journal protocols to the host logging infrastructure, unless the
148 relevant sockets are mounted from the host, specifically:</para>
149
150 <para>The host's
151 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>
152 file will be made available for the service (read-only) as
153 <filename>/run/host/os-release</filename>.
154 It will be updated automatically on soft reboot (see:
155 <citerefentry><refentrytitle>systemd-soft-reboot.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>),
156 in case the service is configured to survive it.</para>
157
158 <example>
159 <title>Mounting logging sockets into root environment</title>
160
161 <programlisting>BindReadOnlyPaths=/dev/log /run/systemd/journal/socket /run/systemd/journal/stdout</programlisting>
162 </example>
163
164 <xi:include href="vpick.xml" xpointer="directory"/>
165
166 <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
167 </varlistentry>
168
169 <varlistentry>
170 <term><varname>RootImage=</varname></term>
171
172 <listitem><para>Takes a path to a block device node or regular file as argument. This call is similar
173 to <varname>RootDirectory=</varname> however mounts a file system hierarchy from a block device node
174 or loopback file instead of a directory. The device node or file system image file needs to contain a
175 file system without a partition table, or a file system within an MBR/MS-DOS or GPT partition table
176 with only a single Linux-compatible partition, or a set of file systems within a GPT partition table
177 that follows the
178 <ulink url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">
179 Discoverable Partitions Specification</ulink>.</para>
180
181 <para>When <varname>DevicePolicy=</varname> is set to <literal>closed</literal> or
182 <literal>strict</literal>, or set to <literal>auto</literal> and <varname>DeviceAllow=</varname> is
183 set, then this setting adds <filename>/dev/loop-control</filename> with <constant>rw</constant> mode,
184 <literal>block-loop</literal> and <literal>block-blkext</literal> with <constant>rwm</constant> mode
185 to <varname>DeviceAllow=</varname>. See
186 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
187 for the details about <varname>DevicePolicy=</varname> or <varname>DeviceAllow=</varname>. Also, see
188 <varname>PrivateDevices=</varname> below, as it may change the setting of
189 <varname>DevicePolicy=</varname>.</para>
190
191 <para>Units making use of <varname>RootImage=</varname> automatically gain an
192 <varname>After=</varname> dependency on <filename>systemd-udevd.service</filename>.</para>
193
194 <para>The host's
195 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>
196 file will be made available for the service (read-only) as
197 <filename>/run/host/os-release</filename>.
198 It will be updated automatically on soft reboot (see:
199 <citerefentry><refentrytitle>systemd-soft-reboot.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>),
200 in case the service is configured to survive it.</para>
201
202 <xi:include href="vpick.xml" xpointer="image"/>
203
204 <xi:include href="system-only.xml" xpointer="singular"/>
205
206 <xi:include href="version-info.xml" xpointer="v233"/></listitem>
207 </varlistentry>
208
209 <varlistentry>
210 <term><varname>RootImageOptions=</varname></term>
211
212 <listitem><para>Takes a comma-separated list of mount options that will be used on disk images specified by
213 <varname>RootImage=</varname>. Optionally a partition name can be prefixed, followed by colon, in
214 case the image has multiple partitions, otherwise partition name <literal>root</literal> is implied.
215 Options for multiple partitions can be specified in a single line with space separators. Assigning an empty
216 string removes previous assignments. Duplicated options are ignored. For a list of valid mount options, please
217 refer to
218 <citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
219 </para>
220
221 <para>Valid partition names follow the
222 <ulink url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">
223 Discoverable Partitions Specification</ulink>:
224 <constant>root</constant>, <constant>usr</constant>, <constant>home</constant>, <constant>srv</constant>,
225 <constant>esp</constant>, <constant>xbootldr</constant>, <constant>tmp</constant>,
226 <constant>var</constant>.</para>
227
228 <xi:include href="system-only.xml" xpointer="singular"/>
229
230 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
231 </varlistentry>
232
233 <varlistentry>
234 <term><varname>RootEphemeral=</varname></term>
235
236 <listitem><para>Takes a boolean argument. If enabled, executed processes will run in an ephemeral
237 copy of the root directory or root image. The ephemeral copy is placed in
238 <filename>/var/lib/systemd/ephemeral-trees/</filename> while the service is active and is cleaned up
239 when the service is stopped or restarted. If <varname>RootDirectory=</varname> is used and the root
240 directory is a subvolume, the ephemeral copy will be created by making a snapshot of the subvolume.
241 </para>
242
243 <para>To make sure making ephemeral copies can be made efficiently, the root directory or root image
244 should be located on the same filesystem as <filename>/var/lib/systemd/ephemeral-trees/</filename>.
245 When using <varname>RootEphemeral=</varname> with root directories,
246 <citerefentry project='url'><refentrytitle url='https://btrfs.readthedocs.io/en/latest/btrfs-man5.html'>btrfs</refentrytitle><manvolnum>5</manvolnum></citerefentry>
247 should be used as the filesystem and the root directory should ideally be a subvolume which
248 <command>systemd</command> can snapshot to make the ephemeral copy. For root images, a filesystem
249 with support for reflinks should be used to ensure an efficient ephemeral copy.</para>
250
251 <xi:include href="system-only.xml" xpointer="singular"/>
252
253 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
254 </varlistentry>
255
256 <varlistentry>
257 <term><varname>RootHash=</varname></term>
258
259 <listitem><para>Takes a data integrity (dm-verity) root hash specified in hexadecimal, or the path to a file
260 containing a root hash in ASCII hexadecimal format. This option enables data integrity checks using dm-verity,
261 if the used image contains the appropriate integrity data (see above) or if <varname>RootVerity=</varname> is used.
262 The specified hash must match the root hash of integrity data, and is usually at least 256 bits (and hence 64
263 formatted hexadecimal characters) long (in case of SHA256 for example). If this option is not specified, but
264 the image file carries the <literal>user.verity.roothash</literal> extended file attribute (see <citerefentry
265 project='man-pages'><refentrytitle>xattr</refentrytitle><manvolnum>7</manvolnum></citerefentry>), then the root
266 hash is read from it, also as formatted hexadecimal characters. If the extended file attribute is not found (or
267 is not supported by the underlying file system), but a file with the <filename>.roothash</filename> suffix is
268 found next to the image file, bearing otherwise the same name (except if the image has the
269 <filename>.raw</filename> suffix, in which case the root hash file must not have it in its name), the root hash
270 is read from it and automatically used, also as formatted hexadecimal characters.</para>
271
272 <para>If the disk image contains a separate <filename>/usr/</filename> partition it may also be
273 Verity protected, in which case the root hash may configured via an extended attribute
274 <literal>user.verity.usrhash</literal> or a <filename>.usrhash</filename> file adjacent to the disk
275 image. There's currently no option to configure the root hash for the <filename>/usr/</filename> file
276 system via the unit file directly.</para>
277
278 <xi:include href="system-only.xml" xpointer="singular"/>
279
280 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
281 </varlistentry>
282
283 <varlistentry>
284 <term><varname>RootHashSignature=</varname></term>
285
286 <listitem><para>Takes a PKCS7 signature of the <varname>RootHash=</varname> option as a path to a
287 DER-encoded signature file, or as an ASCII base64 string encoding of a DER-encoded signature prefixed
288 by <literal>base64:</literal>. The dm-verity volume will only be opened if the signature of the root
289 hash is valid and signed by a public key present in the kernel keyring. If this option is not
290 specified, but a file with the <filename>.roothash.p7s</filename> suffix is found next to the image
291 file, bearing otherwise the same name (except if the image has the <filename>.raw</filename> suffix,
292 in which case the signature file must not have it in its name), the signature is read from it and
293 automatically used.</para>
294
295 <para>If the disk image contains a separate <filename>/usr/</filename> partition it may also be
296 Verity protected, in which case the signature for the root hash may configured via a
297 <filename>.usrhash.p7s</filename> file adjacent to the disk image. There's currently no option to
298 configure the root hash signature for the <filename>/usr/</filename> via the unit file
299 directly.</para>
300
301 <xi:include href="system-only.xml" xpointer="singular"/>
302
303 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
304 </varlistentry>
305
306 <varlistentry>
307 <term><varname>RootVerity=</varname></term>
308
309 <listitem><para>Takes the path to a data integrity (dm-verity) file. This option enables data integrity checks
310 using dm-verity, if <varname>RootImage=</varname> is used and a root-hash is passed and if the used image itself
311 does not contain the integrity data. The integrity data must be matched by the root hash. If this option is not
312 specified, but a file with the <filename>.verity</filename> suffix is found next to the image file, bearing otherwise
313 the same name (except if the image has the <filename>.raw</filename> suffix, in which case the verity data file must
314 not have it in its name), the verity data is read from it and automatically used.</para>
315
316 <para>This option is supported only for disk images that contain a single file system, without an
317 enveloping partition table. Images that contain a GPT partition table should instead include both
318 root file system and matching Verity data in the same image, implementing the
319 <ulink url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">
320 Discoverable Partitions Specification</ulink>.</para>
321
322 <xi:include href="system-only.xml" xpointer="singular"/>
323
324 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
325 </varlistentry>
326
327 <varlistentry>
328 <term><varname>RootImagePolicy=</varname></term>
329 <term><varname>MountImagePolicy=</varname></term>
330 <term><varname>ExtensionImagePolicy=</varname></term>
331
332 <listitem><para>Takes an image policy string as per
333 <citerefentry><refentrytitle>systemd.image-policy</refentrytitle><manvolnum>7</manvolnum></citerefentry>
334 to use when mounting the disk images (DDI) specified in <varname>RootImage=</varname>,
335 <varname>MountImage=</varname>, <varname>ExtensionImage=</varname>, respectively. If not specified
336 the following policy string is the default for <varname>RootImagePolicy=</varname> and <varname>MountImagePolicy</varname>:</para>
337
338 <programlisting>root=verity+signed+encrypted+unprotected+absent: \
339 usr=verity+signed+encrypted+unprotected+absent: \
340 home=encrypted+unprotected+absent: \
341 srv=encrypted+unprotected+absent: \
342 tmp=encrypted+unprotected+absent: \
343 var=encrypted+unprotected+absent</programlisting>
344
345 <para>The default policy for <varname>ExtensionImagePolicy=</varname> is:</para>
346
347 <programlisting>root=verity+signed+encrypted+unprotected+absent: \
348 usr=verity+signed+encrypted+unprotected+absent</programlisting>
349
350 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
351 </varlistentry>
352
353 <varlistentry>
354 <term><varname>MountAPIVFS=</varname></term>
355
356 <listitem><para>Takes a boolean argument. If on, a private mount namespace for the unit's processes is created
357 and the API file systems <filename>/proc/</filename>, <filename>/sys/</filename>, <filename>/dev/</filename> and
358 <filename>/run/</filename> (as an empty <literal>tmpfs</literal>) are mounted inside of it, unless they are
359 already mounted. Note that this option has no effect unless used in conjunction with
360 <varname>RootDirectory=</varname>/<varname>RootImage=</varname> as these four mounts are
361 generally mounted in the host anyway, and unless the root directory is changed, the private mount namespace
362 will be a 1:1 copy of the host's, and include these four mounts. Note that the <filename>/dev/</filename> file
363 system of the host is bind mounted if this option is used without <varname>PrivateDevices=</varname>. To run
364 the service with a private, minimal version of <filename>/dev/</filename>, combine this option with
365 <varname>PrivateDevices=</varname>.</para>
366
367 <para>In order to allow propagating mounts at runtime in a safe manner, <filename>/run/systemd/propagate/</filename>
368 on the host will be used to set up new mounts, and <filename>/run/host/incoming/</filename> in the private namespace
369 will be used as an intermediate step to store them before being moved to the final mount point.</para>
370
371 <xi:include href="version-info.xml" xpointer="v233"/></listitem>
372 </varlistentry>
373
374 <varlistentry>
375 <term><varname>BindLogSockets=</varname></term>
376
377 <listitem><para>Takes a boolean argument. If true, sockets from <citerefentry>
378 <refentrytitle>systemd-journald.socket</refentrytitle><manvolnum>8</manvolnum></citerefentry>
379 will be bind mounted into the mount namespace. This is particularly useful when a different instance
380 of <filename>/run/</filename> is employed, to make sure processes running in the namespace
381 can still make use of <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
382 </para>
383
384 <para>This option is implied when <varname>LogNamespace=</varname> is used,
385 when <varname>MountAPIVFS=yes</varname>, or when <varname>PrivateDevices=yes</varname> is used
386 in conjunction with either <varname>RootDirectory=</varname> or <varname>RootImage=</varname>.</para>
387
388 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
389 </varlistentry>
390
391 <varlistentry>
392 <term><varname>ProtectProc=</varname></term>
393
394 <listitem><para>Takes one of <literal>noaccess</literal>, <literal>invisible</literal>,
395 <literal>ptraceable</literal> or <literal>default</literal> (which it defaults to). When set, this
396 controls the <literal>hidepid=</literal> mount option of the <literal>procfs</literal> instance for
397 the unit that controls which directories with process metainformation
398 (<filename>/proc/<replaceable>PID</replaceable></filename>) are visible and accessible: when set to
399 <literal>noaccess</literal> the ability to access most of other users' process metadata in
400 <filename>/proc/</filename> is taken away for processes of the service. When set to
401 <literal>invisible</literal> processes owned by other users are hidden from
402 <filename>/proc/</filename>. If <literal>ptraceable</literal> all processes that cannot be
403 <function>ptrace()</function>'ed by a process are hidden to it. If <literal>default</literal> no
404 restrictions on <filename>/proc/</filename> access or visibility are made. For further details see
405 <ulink url="https://docs.kernel.org/filesystems/proc.html#mount-options">The /proc
406 Filesystem</ulink>. It is generally recommended to run most system services with this option set to
407 <literal>invisible</literal>. This option is implemented via file system namespacing, and thus cannot
408 be used with services that shall be able to install mount points in the host file system
409 hierarchy. Note that the root user is unaffected by this option, so to be effective it has to be used
410 together with <varname>User=</varname> or <varname>DynamicUser=yes</varname>, and also without the
411 <literal>CAP_SYS_PTRACE</literal> capability, which also allows a process to bypass this feature. It
412 cannot be used for services that need to access metainformation about other users' processes. This
413 option implies <varname>MountAPIVFS=</varname>.</para>
414
415 <para>If the kernel does not support per-mount point <option>hidepid=</option> mount options this
416 setting remains without effect, and the unit's processes will be able to access and see other process
417 as if the option was not used.</para>
418
419 <xi:include href="system-only.xml" xpointer="singular"/>
420
421 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
422 </varlistentry>
423
424 <varlistentry>
425 <term><varname>ProcSubset=</varname></term>
426
427 <listitem><para>Takes one of <literal>all</literal> (the default) and <literal>pid</literal>. If
428 <literal>pid</literal>, all files and directories not directly associated with process management and
429 introspection are made invisible in the <filename>/proc/</filename> file system configured for the
430 unit's processes. This controls the <literal>subset=</literal> mount option of the
431 <literal>procfs</literal> instance for the unit. For further details see <ulink
432 url="https://docs.kernel.org/filesystems/proc.html#mount-options">The /proc
433 Filesystem</ulink>. Note that Linux exposes various kernel APIs via <filename>/proc/</filename>,
434 which are made unavailable with this setting. Since these APIs are used frequently this option is
435 useful only in a few, specific cases, and is not suitable for most non-trivial programs.</para>
436
437 <para>Much like <varname>ProtectProc=</varname> above, this is implemented via file system mount
438 namespacing, and hence the same restrictions apply: it is only available to system services, it
439 disables mount propagation to the host mount table, and it implies
440 <varname>MountAPIVFS=</varname>. Also, like <varname>ProtectProc=</varname> this setting is gracefully
441 disabled if the used kernel does not support the <literal>subset=</literal> mount option of
442 <literal>procfs</literal>.</para>
443
444 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
445 </varlistentry>
446
447 <varlistentry>
448 <term><varname>BindPaths=</varname></term>
449 <term><varname>BindReadOnlyPaths=</varname></term>
450
451 <listitem><para>Configures unit-specific bind mounts. A bind mount makes a particular file or directory
452 available at an additional place in the unit's view of the file system. Any bind mounts created with this
453 option are specific to the unit, and are not visible in the host's mount table. This option expects a
454 whitespace separated list of bind mount definitions. Each definition consists of a colon-separated triple of
455 source path, destination path and option string, where the latter two are optional. If only a source path is
456 specified the source and destination is taken to be the same. The option string may be either
457 <literal>rbind</literal> or <literal>norbind</literal> for configuring a recursive or non-recursive bind
458 mount. If the destination path is omitted, the option string must be omitted too.
459 Each bind mount definition may be prefixed with <literal>-</literal>, in which case it will be ignored
460 when its source path does not exist.</para>
461
462 <para><varname>BindPaths=</varname> creates regular writable bind mounts (unless the source file system mount
463 is already marked read-only), while <varname>BindReadOnlyPaths=</varname> creates read-only bind mounts. These
464 settings may be used more than once, each usage appends to the unit's list of bind mounts. If the empty string
465 is assigned to either of these two options the entire list of bind mounts defined prior to this is reset. Note
466 that, in this case, both read-only and regular bind mounts are reset, regardless which of the two settings is
467 used.</para>
468
469 <para>Using this option implies that a mount namespace is allocated for the unit, i.e. it implies the
470 effect of <varname>PrivateMounts=</varname> (see below).</para>
471
472 <para>This option is particularly useful when <varname>RootDirectory=</varname>/<varname>RootImage=</varname>
473 is used. In this case, the source path refers to a path on the host file system, while the destination path
474 refers to a path below the root directory of the unit.</para>
475
476 <para>Note that the destination directory must exist or systemd must be able to create it. Thus, it
477 is not possible to use those options for mount points nested underneath paths specified in
478 <varname>InaccessiblePaths=</varname>, or under <filename>/home/</filename> and other protected
479 directories if <varname>ProtectHome=yes</varname> is
480 specified. <varname>TemporaryFileSystem=</varname> with <literal>:ro</literal> or
481 <varname>ProtectHome=tmpfs</varname> should be used instead.</para>
482
483 <xi:include href="version-info.xml" xpointer="v233"/></listitem>
484 </varlistentry>
485
486 <varlistentry>
487 <term><varname>MountImages=</varname></term>
488
489 <listitem><para>This setting is similar to <varname>RootImage=</varname> in that it mounts a file
490 system hierarchy from a block device node or loopback file, but the destination directory can be
491 specified as well as mount options. This option expects a whitespace separated list of mount
492 definitions. Each definition consists of a colon-separated tuple of source path and destination
493 definitions, optionally followed by another colon and a list of mount options.</para>
494
495 <para>Mount options may be defined as a single comma-separated list of options, in which case they
496 will be implicitly applied to the root partition on the image, or a series of colon-separated tuples
497 of partition name and mount options. Valid partition names and mount options are the same as for
498 <varname>RootImageOptions=</varname> setting described above.</para>
499
500 <para>Each mount definition may be prefixed with <literal>-</literal>, in which case it will be
501 ignored when its source path does not exist. The source argument is a path to a block device node or
502 regular file. If source or destination contain a <literal>:</literal>, it needs to be escaped as
503 <literal>\:</literal>. The device node or file system image file needs to follow the same rules as
504 specified for <varname>RootImage=</varname>. Any mounts created with this option are specific to the
505 unit, and are not visible in the host's mount table.</para>
506
507 <para>These settings may be used more than once, each usage appends to the unit's list of mount
508 paths. If the empty string is assigned, the entire list of mount paths defined prior to this is
509 reset.</para>
510
511 <para>Note that the destination directory must exist or systemd must be able to create it. Thus, it
512 is not possible to use those options for mount points nested underneath paths specified in
513 <varname>InaccessiblePaths=</varname>, or under <filename>/home/</filename> and other protected
514 directories if <varname>ProtectHome=yes</varname> is specified.</para>
515
516 <para>When <varname>DevicePolicy=</varname> is set to <literal>closed</literal> or
517 <literal>strict</literal>, or set to <literal>auto</literal> and <varname>DeviceAllow=</varname> is
518 set, then this setting adds <filename>/dev/loop-control</filename> with <constant>rw</constant> mode,
519 <literal>block-loop</literal> and <literal>block-blkext</literal> with <constant>rwm</constant> mode
520 to <varname>DeviceAllow=</varname>. See
521 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
522 for the details about <varname>DevicePolicy=</varname> or <varname>DeviceAllow=</varname>. Also, see
523 <varname>PrivateDevices=</varname> below, as it may change the setting of
524 <varname>DevicePolicy=</varname>.</para>
525
526 <xi:include href="system-only.xml" xpointer="singular"/>
527
528 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
529 </varlistentry>
530
531 <varlistentry>
532 <term><varname>ExtensionImages=</varname></term>
533
534 <listitem><para>This setting is similar to <varname>MountImages=</varname> in that it mounts a file
535 system hierarchy from a block device node or loopback file, but instead of providing a destination
536 path, an overlay will be set up. This option expects a whitespace separated list of mount
537 definitions. Each definition consists of a source path, optionally followed by a colon and a list of
538 mount options.</para>
539
540 <para>A read-only OverlayFS will be set up on top of <filename>/usr/</filename> and
541 <filename>/opt/</filename> hierarchies for sysext images and <filename>/etc/</filename>
542 hierarchy for confext images. The order in which the images are listed will determine the
543 order in which the overlay is laid down: images specified first to last will result in overlayfs
544 layers bottom to top.</para>
545
546 <para>Mount options may be defined as a single comma-separated list of options, in which case they
547 will be implicitly applied to the root partition on the image, or a series of colon-separated tuples
548 of partition name and mount options. Valid partition names and mount options are the same as for
549 <varname>RootImageOptions=</varname> setting described above.</para>
550
551 <para>Each mount definition may be prefixed with <literal>-</literal>, in which case it will be
552 ignored when its source path does not exist. The source argument is a path to a block device node or
553 regular file. If the source path contains a <literal>:</literal>, it needs to be escaped as
554 <literal>\:</literal>. The device node or file system image file needs to follow the same rules as
555 specified for <varname>RootImage=</varname>. Any mounts created with this option are specific to the
556 unit, and are not visible in the host's mount table.</para>
557
558 <para>These settings may be used more than once, each usage appends to the unit's list of image
559 paths. If the empty string is assigned, the entire list of mount paths defined prior to this is
560 reset.</para>
561
562 <para>Each sysext image must carry a <filename>/usr/lib/extension-release.d/extension-release.IMAGE</filename>
563 file while each confext image must carry a <filename>/etc/extension-release.d/extension-release.IMAGE</filename>
564 file, with the appropriate metadata which matches <varname>RootImage=</varname>/<varname>RootDirectory=</varname>
565 or the host. See:
566 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
567 To disable the safety check that the extension-release file name matches the image file name, the
568 <varname>x-systemd.relax-extension-release-check</varname> mount option may be appended.</para>
569
570 <para>This option can be used together with a <option>notify-reload</option> service type and
571 <citerefentry><refentrytitle>systemd.v</refentrytitle><manvolnum>7</manvolnum></citerefentry>
572 to manage configuration updates. When such a service carrying confext images is reloaded via
573 <command>systemctl reload foo.service</command> or equivalent D-Bus method, the confext itself will
574 be reloaded to pick up any changes. This only applies to confext extensions. Note that in case a
575 service has this configuration enabled at first, and then it is subsequently removed in an update
576 followed by a daemon-reload operation, reloading the confexts will be a no-op, and a full service
577 restart is required instead. See
578 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
579 also for details.</para>
580
581 <para>When <varname>DevicePolicy=</varname> is set to <literal>closed</literal> or
582 <literal>strict</literal>, or set to <literal>auto</literal> and <varname>DeviceAllow=</varname> is
583 set, then this setting adds <filename>/dev/loop-control</filename> with <constant>rw</constant> mode,
584 <literal>block-loop</literal> and <literal>block-blkext</literal> with <constant>rwm</constant> mode
585 to <varname>DeviceAllow=</varname>. See
586 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
587 for the details about <varname>DevicePolicy=</varname> or <varname>DeviceAllow=</varname>. Also, see
588 <varname>PrivateDevices=</varname> below, as it may change the setting of
589 <varname>DevicePolicy=</varname>.</para>
590
591 <xi:include href="vpick.xml" xpointer="image"/>
592
593 <xi:include href="system-only.xml" xpointer="singular"/>
594
595 <xi:include href="version-info.xml" xpointer="v248"/></listitem>
596 </varlistentry>
597
598 <varlistentry>
599 <term><varname>ExtensionDirectories=</varname></term>
600
601 <listitem><para>This setting is similar to <varname>BindReadOnlyPaths=</varname> in that it mounts a file
602 system hierarchy from a directory, but instead of providing a destination path, an overlay will be set
603 up. This option expects a whitespace separated list of source directories.</para>
604
605 <para>A read-only OverlayFS will be set up on top of <filename>/usr/</filename> and
606 <filename>/opt/</filename> hierarchies for sysext images and <filename>/etc/</filename>
607 hierarchy for confext images. The order in which the directories are listed will determine
608 the order in which the overlay is laid down: directories specified first to last will result in overlayfs
609 layers bottom to top.</para>
610
611 <para>Each directory listed in <varname>ExtensionDirectories=</varname> may be prefixed with <literal>-</literal>,
612 in which case it will be ignored when its source path does not exist. Any mounts created with this option are
613 specific to the unit, and are not visible in the host's mount table.</para>
614
615 <para>These settings may be used more than once, each usage appends to the unit's list of directories
616 paths. If the empty string is assigned, the entire list of mount paths defined prior to this is
617 reset.</para>
618
619 <para>Each sysext directory must contain a <filename>/usr/lib/extension-release.d/extension-release.IMAGE</filename>
620 file while each confext directory must carry a <filename>/etc/extension-release.d/extension-release.IMAGE</filename>
621 file, with the appropriate metadata which matches <varname>RootImage=</varname>/<varname>RootDirectory=</varname>
622 or the host. See:
623 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
624
625 <para>This option can be used together with a <option>notify-reload</option> service type and
626 <citerefentry><refentrytitle>systemd.v</refentrytitle><manvolnum>7</manvolnum></citerefentry>
627 to manage configuration updates. When such a service carrying confext directories is reloaded via
628 <command>systemctl reload foo.service</command> or equivalent D-Bus method, the confext itself will
629 be reloaded to pick up any changes. This only applies to confext extensions. Note that in case a
630 service has this configuration enabled at first, and then it is subsequently removed in an update
631 followed by a daemon-reload operation, reloading the confexts will be a no-op, and a full service
632 restart is required instead. See
633 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
634 also for details.</para>
635
636 <para>Note that usage from user units requires overlayfs support in unprivileged user namespaces,
637 which was first introduced in kernel v5.11.</para>
638
639 <xi:include href="vpick.xml" xpointer="directory"/>
640
641 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
642
643 <xi:include href="version-info.xml" xpointer="v251"/></listitem>
644 </varlistentry>
645 </variablelist>
646 </refsect1>
647
648 <refsect1>
649 <title>User/Group Identity</title>
650
651 <xi:include href="system-only.xml" xpointer="plural"/>
652
653 <variablelist class='unit-directives'>
654
655 <varlistentry>
656 <term><varname>User=</varname></term>
657 <term><varname>Group=</varname></term>
658
659 <listitem><para>Set the UNIX user or group that the processes are executed as, respectively. Takes a single
660 user or group name, or a numeric ID as argument. For system services (services run by the system service
661 manager, i.e. managed by PID 1) and for user services of the root user (services managed by root's instance of
662 <command>systemd --user</command>), the default is <literal>root</literal>, but <varname>User=</varname> may be
663 used to specify a different user. For user services of any other user, switching user identity is not
664 permitted, hence the only valid setting is the same user the user's service manager is running as. If no group
665 is set, the default group of the user is used. This setting does not affect commands whose command line is
666 prefixed with <literal>+</literal>.</para>
667
668 <para>Note that this enforces only weak restrictions on the user/group name syntax, but will generate
669 warnings in many cases where user/group names do not adhere to the following rules: the specified
670 name should consist only of the characters a-z, A-Z, 0-9, <literal>_</literal> and
671 <literal>-</literal>, except for the first character which must be one of a-z, A-Z and
672 <literal>_</literal> (i.e. digits and <literal>-</literal> are not permitted as first character). The
673 user/group name must have at least one character, and at most 31. These restrictions are made in
674 order to avoid ambiguities and to ensure user/group names and unit files remain portable among Linux
675 systems. For further details on the names accepted and the names warned about see <ulink
676 url="https://systemd.io/USER_NAMES">User/Group Name Syntax</ulink>.</para>
677
678 <para>When used in conjunction with <varname>DynamicUser=</varname> the user/group name specified is
679 dynamically allocated at the time the service is started, and released at the time the service is
680 stopped — unless it is already allocated statically (see below). If <varname>DynamicUser=</varname>
681 is not used the specified user and group must have been created statically in the user database no
682 later than the moment the service is started, for example using the
683 <citerefentry><refentrytitle>sysusers.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>
684 facility, which is applied at boot or package install time. If the user does not exist by then
685 program invocation will fail.</para>
686
687 <para>If the <varname>User=</varname> setting is used the supplementary group list is initialized
688 from the specified user's default group list, as defined in the system's user and group
689 database. Additional groups may be configured through the <varname>SupplementaryGroups=</varname>
690 setting (see below).</para></listitem>
691 </varlistentry>
692
693 <varlistentry>
694 <term><varname>DynamicUser=</varname></term>
695
696 <listitem><para>Takes a boolean parameter. If set, a UNIX user and group pair is allocated
697 dynamically when the unit is started, and released as soon as it is stopped. The user and group will
698 not be added to <filename>/etc/passwd</filename> or <filename>/etc/group</filename>, but are managed
699 transiently during runtime. The
700 <citerefentry><refentrytitle>nss-systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> glibc
701 NSS module provides integration of these dynamic users/groups into the system's user and group
702 databases. The user and group name to use may be configured via <varname>User=</varname> and
703 <varname>Group=</varname> (see above). If these options are not used and dynamic user/group
704 allocation is enabled for a unit, the name of the dynamic user/group is implicitly derived from the
705 unit name. If the unit name without the type suffix qualifies as valid user name it is used directly,
706 otherwise a name incorporating a hash of it is used. If a statically allocated user or group of the
707 configured name already exists, it is used and no dynamic user/group is allocated. Note that if
708 <varname>User=</varname> is specified and the static group with the name exists, then it is required
709 that the static user with the name already exists. Similarly, if <varname>Group=</varname> is
710 specified and the static user with the name exists, then it is required that the static group with
711 the name already exists. Dynamic users/groups are allocated from the UID/GID range 61184…65519. It is
712 recommended to avoid this range for regular system or login users. At any point in time each UID/GID
713 from this range is only assigned to zero or one dynamically allocated users/groups in use. However,
714 UID/GIDs are recycled after a unit is terminated. Care should be taken that any processes running as
715 part of a unit for which dynamic users/groups are enabled do not leave files or directories owned by
716 these users/groups around, as a different unit might get the same UID/GID assigned later on, and thus
717 gain access to these files or directories. If <varname>DynamicUser=</varname> is enabled,
718 <varname>RemoveIPC=</varname> is implied (and cannot be turned off). This ensures that the lifetime
719 of IPC objects and temporary files created by the executed processes is bound to the runtime of the
720 service, and hence the lifetime of the dynamic user/group. Since <filename>/tmp/</filename> and
721 <filename>/var/tmp/</filename> are usually the only world-writable directories on a system, unless
722 <varname>PrivateTmp=</varname> is manually set to <literal>true</literal>, <literal>disconnected</literal>
723 would be implied. This ensures that a unit making use of dynamic user/group allocation cannot
724 leave files around after unit termination. Furthermore
725 <varname>NoNewPrivileges=</varname> and <varname>RestrictSUIDSGID=</varname> are implicitly enabled
726 (and cannot be disabled), to ensure that processes invoked cannot take benefit or create SUID/SGID
727 files or directories. Moreover, <varname>ProtectSystem=strict</varname> and
728 <varname>ProtectHome=read-only</varname> are implied, thus prohibiting the service to write to
729 arbitrary file system locations. In order to allow the service to write to certain directories, they
730 have to be allow-listed using <varname>ReadWritePaths=</varname>, but care must be taken so that
731 UID/GID recycling does not create security issues involving files created by the service. Use
732 <varname>RuntimeDirectory=</varname> (see below) in order to assign a writable runtime directory to a
733 service, owned by the dynamic user/group and removed automatically when the unit is terminated. Use
734 <varname>StateDirectory=</varname>, <varname>CacheDirectory=</varname> and
735 <varname>LogsDirectory=</varname> in order to assign a set of writable directories for specific
736 purposes to the service in a way that they are protected from vulnerabilities due to UID reuse (see
737 below). If this option is enabled, care should be taken that the unit's processes do not get access
738 to directories outside of these explicitly configured and managed ones. Specifically, do not use
739 <varname>BindPaths=</varname> and be careful with <constant>AF_UNIX</constant> file descriptor
740 passing for directory file descriptors, as this would permit processes to create files or directories
741 owned by the dynamic user/group that are not subject to the lifecycle and access guarantees of the
742 service. Note that this option is currently incompatible with D-Bus policies, thus a service using
743 this option may currently not allocate a D-Bus service name (note that this does not affect calling
744 into other D-Bus services). Defaults to off.</para>
745
746 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
747 </varlistentry>
748
749 <varlistentry>
750 <term><varname>SupplementaryGroups=</varname></term>
751
752 <listitem><para>Sets the supplementary Unix groups the processes are executed as. This takes a space-separated
753 list of group names or IDs. This option may be specified more than once, in which case all listed groups are
754 set as supplementary groups. When the empty string is assigned, the list of supplementary groups is reset, and
755 all assignments prior to this one will have no effect. In any way, this option does not override, but extends
756 the list of supplementary groups configured in the system group database for the user. This does not affect
757 commands prefixed with <literal>+</literal>.</para></listitem>
758 </varlistentry>
759
760 <varlistentry>
761 <term><varname>SetLoginEnvironment=</varname></term>
762
763 <listitem><para>Takes a boolean parameter that controls whether to set the <varname>$HOME</varname>,
764 <varname>$LOGNAME</varname>, and <varname>$SHELL</varname> environment variables. If not set, this
765 defaults to true if <varname>User=</varname>, <varname>DynamicUser=</varname> or
766 <varname>PAMName=</varname> are set, false otherwise. If set to true, the variables will always be
767 set for system services, i.e. even when the default user <literal>root</literal> is used. If set to
768 false, the mentioned variables are not set by the service manager, no matter whether
769 <varname>User=</varname>, <varname>DynamicUser=</varname>, or <varname>PAMName=</varname> are used or
770 not. This option normally has no effect on services of the per-user service manager, since in that
771 case these variables are typically inherited from user manager's own environment anyway.</para>
772
773 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
774 </varlistentry>
775
776 <varlistentry>
777 <term><varname>PAMName=</varname></term>
778
779 <listitem><para>Sets the PAM service name to set up a session as. If set, the executed process will be
780 registered as a PAM session under the specified service name. This is only useful in conjunction with the
781 <varname>User=</varname> setting, and is otherwise ignored. If not set, no PAM session will be opened for the
782 executed processes. See <citerefentry
783 project='man-pages'><refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
784 details.</para>
785
786 <para>Note that for each unit making use of this option a PAM session handler process will be maintained as
787 part of the unit and stays around as long as the unit is active, to ensure that appropriate actions can be
788 taken when the unit and hence the PAM session terminates. This process is named <literal>(sd-pam)</literal> and
789 is an immediate child process of the unit's main process.</para>
790
791 <para>Note that when this option is used for a unit it is very likely (depending on PAM configuration) that the
792 main unit process will be migrated to its own session scope unit when it is activated. This process will hence
793 be associated with two units: the unit it was originally started from (and for which
794 <varname>PAMName=</varname> was configured), and the session scope unit. Any child processes of that process
795 will however be associated with the session scope unit only. This has implications when used in combination
796 with <varname>NotifyAccess=</varname><option>all</option>, as these child processes will not be able to affect
797 changes in the original unit through notification messages. These messages will be considered belonging to the
798 session scope unit and not the original unit. It is hence not recommended to use <varname>PAMName=</varname> in
799 combination with <varname>NotifyAccess=</varname><option>all</option>.</para>
800
801 <para>If a PAM module interactively requests input (a password or suchlike) it will be attempted to
802 be read from a service credential (as configured via <varname>SetCredential=</varname>,
803 <varname>ImportCredential=</varname> and related calls) under the name
804 <varname>pam.authtok.<replaceable>pamservice</replaceable></varname>, where
805 <replaceable>pamservice</replaceable> is replaced by the PAM service name as configured with
806 <varname>PAMName=</varname>. (Note that the credential remains accessible for the runtime of the
807 service!) If no matching credential is set, the user is prompted for it interactively via the <ulink
808 url="https://systemd.io/PASSWORD_AGENTS">Password Agent</ulink> logic.</para>
809 </listitem>
810 </varlistentry>
811
812 </variablelist>
813 </refsect1>
814
815 <refsect1>
816 <title>Capabilities</title>
817
818 <xi:include href="system-or-user-ns.xml" xpointer="plural"/>
819
820 <variablelist class='unit-directives'>
821
822 <varlistentry>
823 <term><varname>CapabilityBoundingSet=</varname></term>
824
825 <listitem><para>Controls which capabilities to include in the capability bounding set for the
826 executed process. See <citerefentry
827 project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>
828 for details. Takes a whitespace-separated list of capability names,
829 e.g. <constant>CAP_SYS_ADMIN</constant>, <constant>CAP_DAC_OVERRIDE</constant>,
830 <constant>CAP_SYS_PTRACE</constant>. Capabilities listed will be included in the bounding set, all
831 others are removed. If the list of capabilities is prefixed with <literal>~</literal>, all but the
832 listed capabilities will be included, the effect of the assignment inverted. Note that this option
833 also affects the respective capabilities in the effective, permitted and inheritable capability
834 sets. If this option is not used, the capability bounding set is not modified on process execution,
835 hence no limits on the capabilities of the process are enforced. This option may appear more than
836 once, in which case the bounding sets are merged by <constant>OR</constant>, or by
837 <constant>AND</constant> if the lines are prefixed with <literal>~</literal> (see below). If the
838 empty string is assigned to this option, the bounding set is reset to the empty capability set, and
839 all prior settings have no effect. If set to <literal>~</literal> (without any further argument),
840 the bounding set is reset to the full set of available capabilities, also undoing any previous
841 settings. This does not affect commands prefixed with <literal>+</literal>.</para>
842
843 <para>Use
844 <citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
845 <command>capability</command> command to retrieve a list of capabilities defined on the local
846 system.</para>
847
848 <para>Example: if a unit has the following,
849 <programlisting>CapabilityBoundingSet=CAP_A CAP_B
850CapabilityBoundingSet=CAP_B CAP_C</programlisting>
851 then <constant index='false'>CAP_A</constant>, <constant index='false'>CAP_B</constant>, and
852 <constant index='false'>CAP_C</constant> are set. If the second line is prefixed with
853 <literal>~</literal>, e.g.,
854 <programlisting>CapabilityBoundingSet=CAP_A CAP_B
855CapabilityBoundingSet=~CAP_B CAP_C</programlisting>
856 then, only <constant index='false'>CAP_A</constant> is set.</para></listitem>
857 </varlistentry>
858
859 <varlistentry>
860 <term><varname>AmbientCapabilities=</varname></term>
861
862 <listitem><para>Controls which capabilities to include in the ambient capability set for the executed
863 process. Takes a whitespace-separated list of capability names, e.g. <constant>CAP_SYS_ADMIN</constant>,
864 <constant>CAP_DAC_OVERRIDE</constant>, <constant>CAP_SYS_PTRACE</constant>. This option may appear more than
865 once, in which case the ambient capability sets are merged (see the above examples in
866 <varname>CapabilityBoundingSet=</varname>). If the list of capabilities is prefixed with <literal>~</literal>,
867 all but the listed capabilities will be included, the effect of the assignment inverted. If the empty string is
868 assigned to this option, the ambient capability set is reset to the empty capability set, and all prior
869 settings have no effect. If set to <literal>~</literal> (without any further argument), the ambient capability
870 set is reset to the full set of available capabilities, also undoing any previous settings. Note that adding
871 capabilities to the ambient capability set adds them to the process's inherited capability set.</para>
872
873 <para>Ambient capability sets are useful if you want to execute a process as a non-privileged user but
874 still want to give it some capabilities. Note that, in this case, option <constant>keep-caps</constant>
875 is automatically added to <varname>SecureBits=</varname> to retain the capabilities over the user
876 change. <varname>AmbientCapabilities=</varname> does not affect commands prefixed with
877 <literal>+</literal>.</para>
878
879 <xi:include href="version-info.xml" xpointer="v229"/></listitem>
880 </varlistentry>
881
882 </variablelist>
883 </refsect1>
884
885 <refsect1>
886 <title>Security</title>
887
888 <variablelist class='unit-directives'>
889
890 <varlistentry>
891 <term><varname>NoNewPrivileges=</varname></term>
892
893 <listitem><para>Takes a boolean argument. If true, ensures that the service process and all its
894 children can never gain new privileges through <function>execve()</function> (e.g. via setuid or
895 setgid bits, or filesystem capabilities). This is the simplest and most effective way to ensure that
896 a process and its children can never elevate privileges again. Defaults to false. In case the service
897 will be run in a new mount namespace anyway and SELinux is disabled, all file systems are mounted with
898 <constant>MS_NOSUID</constant> flag. Also see <ulink
899 url="https://docs.kernel.org/userspace-api/no_new_privs.html">No New Privileges Flag</ulink>.
900 </para>
901
902 <para>Note that this setting only has an effect on the unit's processes themselves (or any processes
903 directly or indirectly forked off them). It has no effect on processes potentially invoked on request
904 of them through tools such as <citerefentry
905 project='man-pages'><refentrytitle>at</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
906 <citerefentry
907 project='man-pages'><refentrytitle>crontab</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
908 <citerefentry><refentrytitle>systemd-run</refentrytitle><manvolnum>1</manvolnum></citerefentry>, or
909 arbitrary IPC services.</para>
910
911 <xi:include href="version-info.xml" xpointer="v187"/></listitem>
912 </varlistentry>
913
914 <varlistentry>
915 <term><varname>SecureBits=</varname></term>
916
917 <listitem><para>Controls the secure bits set for the executed process. Takes a space-separated combination of
918 options from the following list: <option>keep-caps</option>, <option>keep-caps-locked</option>,
919 <option>no-setuid-fixup</option>, <option>no-setuid-fixup-locked</option>, <option>noroot</option>, and
920 <option>noroot-locked</option>. This option may appear more than once, in which case the secure bits are
921 ORed. If the empty string is assigned to this option, the bits are reset to 0. This does not affect commands
922 prefixed with <literal>+</literal>. See <citerefentry
923 project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
924 details.</para></listitem>
925 </varlistentry>
926
927 </variablelist>
928 </refsect1>
929
930 <refsect1>
931 <title>Mandatory Access Control</title>
932
933 <variablelist class='unit-directives'>
934
935 <varlistentry>
936 <term><varname>SELinuxContext=</varname></term>
937
938 <listitem><para>Set the SELinux security context of the executed process. If set, this will override the
939 automated domain transition. However, the policy still needs to authorize the transition. This directive is
940 ignored if SELinux is disabled. If prefixed by <literal>-</literal>, failing to set the SELinux
941 security context will be ignored, but it is still possible that the subsequent
942 <function>execve()</function> may fail if the policy does not allow the transition for the
943 non-overridden context. This does not affect commands prefixed with <literal>+</literal>. See
944 <citerefentry
945 project='die-net'><refentrytitle>setexeccon</refentrytitle><manvolnum>3</manvolnum></citerefentry>
946 for details.</para>
947
948 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
949 </varlistentry>
950
951 <varlistentry>
952 <term><varname>AppArmorProfile=</varname></term>
953
954 <listitem><para>Takes a profile name as argument. The process executed by the unit will switch to
955 this profile when started. Profiles must already be loaded in the kernel, or the unit will fail. If
956 prefixed by <literal>-</literal>, all errors will be ignored. This setting has no effect if AppArmor
957 is not enabled. This setting does not affect commands prefixed with <literal>+</literal>.</para>
958
959 <xi:include href="system-only.xml" xpointer="singular"/>
960
961 <xi:include href="version-info.xml" xpointer="v210"/>
962 </listitem>
963 </varlistentry>
964
965 <varlistentry>
966 <term><varname>SmackProcessLabel=</varname></term>
967
968 <listitem><para>Takes a <option>SMACK64</option> security label as argument. The process executed by the unit
969 will be started under this label and SMACK will decide whether the process is allowed to run or not, based on
970 it. The process will continue to run under the label specified here unless the executable has its own
971 <option>SMACK64EXEC</option> label, in which case the process will transition to run under that label. When not
972 specified, the label that systemd is running under is used. This directive is ignored if SMACK is
973 disabled.</para>
974
975 <para>The value may be prefixed by <literal>-</literal>, in which case all errors will be ignored. An empty
976 value may be specified to unset previous assignments. This does not affect commands prefixed with
977 <literal>+</literal>.</para>
978
979 <xi:include href="system-only.xml" xpointer="singular"/>
980
981 <xi:include href="version-info.xml" xpointer="v218"/></listitem>
982 </varlistentry>
983
984 </variablelist>
985 </refsect1>
986
987 <refsect1>
988 <title>Process Properties</title>
989
990 <variablelist class='unit-directives'>
991
992 <varlistentry>
993 <term><varname>LimitCPU=</varname></term>
994 <term><varname>LimitFSIZE=</varname></term>
995 <term><varname>LimitDATA=</varname></term>
996 <term><varname>LimitSTACK=</varname></term>
997 <term><varname>LimitCORE=</varname></term>
998 <term><varname>LimitRSS=</varname></term>
999 <term><varname>LimitNOFILE=</varname></term>
1000 <term><varname>LimitAS=</varname></term>
1001 <term><varname>LimitNPROC=</varname></term>
1002 <term><varname>LimitMEMLOCK=</varname></term>
1003 <term><varname>LimitLOCKS=</varname></term>
1004 <term><varname>LimitSIGPENDING=</varname></term>
1005 <term><varname>LimitMSGQUEUE=</varname></term>
1006 <term><varname>LimitNICE=</varname></term>
1007 <term><varname>LimitRTPRIO=</varname></term>
1008 <term><varname>LimitRTTIME=</varname></term>
1009
1010 <listitem><para>Set soft and hard limits on various resources for executed processes. See
1011 <citerefentry><refentrytitle>setrlimit</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
1012 details on the process resource limit concept. Process resource limits may be specified in two formats:
1013 either as single value to set a specific soft and hard limit to the same value, or as colon-separated
1014 pair <option>soft:hard</option> to set both limits individually
1015 (e.g. <literal>LimitAS=4G:16G</literal>). Use the string <option>infinity</option> to configure no
1016 limit on a specific resource. The multiplicative suffixes K, M, G, T, P and E (to the base 1024) may
1017 be used for resource limits measured in bytes (e.g. <literal>LimitAS=16G</literal>). For the limits
1018 referring to time values, the usual time units ms, s, min, h and so on may be used (see
1019 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
1020 details). Note that if no time unit is specified for <varname>LimitCPU=</varname> the default unit of
1021 seconds is implied, while for <varname>LimitRTTIME=</varname> the default unit of microseconds is
1022 implied. Also, note that the effective granularity of the limits might influence their
1023 enforcement. For example, time limits specified for <varname>LimitCPU=</varname> will be rounded up
1024 implicitly to multiples of 1s. For <varname>LimitNICE=</varname> the value may be specified in two
1025 syntaxes: if prefixed with <literal>+</literal> or <literal>-</literal>, the value is understood as
1026 regular Linux nice value in the range -20…19. If not prefixed like this the value is understood as
1027 raw resource limit parameter in the range 0…40 (with 0 being equivalent to 1).</para>
1028
1029 <para>Note that most process resource limits configured with these options are per-process, and
1030 processes may fork in order to acquire a new set of resources that are accounted independently of the
1031 original process, and may thus escape limits set. Also note that <varname>LimitRSS=</varname> is not
1032 implemented on Linux, and setting it has no effect. Often it is advisable to prefer the resource
1033 controls listed in
1034 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1035 over these per-process limits, as they apply to services as a whole, may be altered dynamically at
1036 runtime, and are generally more expressive. For example, <varname>MemoryMax=</varname> is a more
1037 powerful (and working) replacement for <varname>LimitRSS=</varname>.</para>
1038
1039 <para>Note that <varname>LimitNPROC=</varname> will limit the number of processes from one (real) UID and
1040 not the number of processes started (forked) by the service. Therefore the limit is cumulative for all
1041 processes running under the same UID. Please also note that the <varname>LimitNPROC=</varname> will not be
1042 enforced if the service is running as root (and not dropping privileges). Due to these limitations,
1043 <varname>TasksMax=</varname> (see <citerefentry><refentrytitle>systemd.resource-control</refentrytitle>
1044 <manvolnum>5</manvolnum></citerefentry>) is typically a better choice than <varname>LimitNPROC=</varname>.
1045 </para>
1046
1047 <para>Resource limits not configured explicitly for a unit default to the value configured in the various
1048 <varname>DefaultLimitCPU=</varname>, <varname>DefaultLimitFSIZE=</varname>, … options available in
1049 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, and –
1050 if not configured there – the kernel or per-user defaults, as defined by the OS (the latter only for user
1051 services, see below).</para>
1052
1053 <para>For system units these resource limits may be chosen freely. When these settings are configured
1054 in a user service (i.e. a service run by the per-user instance of the service manager) they cannot be
1055 used to raise the limits above those set for the user manager itself when it was first invoked, as
1056 the user's service manager generally lacks the privileges to do so. In user context these
1057 configuration options are hence only useful to lower the limits passed in or to raise the soft limit
1058 to the maximum of the hard limit as configured for the user. To raise the user's limits further, the
1059 available configuration mechanisms differ between operating systems, but typically require
1060 privileges. In most cases it is possible to configure higher per-user resource limits via PAM or by
1061 setting limits on the system service encapsulating the user's service manager, i.e. the user's
1062 instance of <filename>user@.service</filename>. After making such changes, make sure to restart the
1063 user's service manager.</para>
1064
1065 <table>
1066 <title>Resource limit directives, their equivalent <command>ulimit</command> shell commands and the unit used</title>
1067
1068 <tgroup cols='4'>
1069 <colspec colname='directive' />
1070 <colspec colname='equivalent' />
1071 <colspec colname='unit' />
1072 <colspec colname='notes' />
1073 <thead>
1074 <row>
1075 <entry>Directive</entry>
1076 <entry><command>ulimit</command> equivalent</entry>
1077 <entry>Unit</entry>
1078 <entry>Notes</entry>
1079 </row>
1080 </thead>
1081 <tbody>
1082 <row>
1083 <entry>LimitCPU=</entry>
1084 <entry>ulimit -t</entry>
1085 <entry>Seconds</entry>
1086 <entry>-</entry>
1087 </row>
1088 <row>
1089 <entry>LimitFSIZE=</entry>
1090 <entry>ulimit -f</entry>
1091 <entry>Bytes</entry>
1092 <entry>-</entry>
1093 </row>
1094 <row>
1095 <entry>LimitDATA=</entry>
1096 <entry>ulimit -d</entry>
1097 <entry>Bytes</entry>
1098 <entry>Do not use. This limits the allowed address range, not memory use! Defaults to unlimited and should not be lowered. To limit memory use, see <varname>MemoryMax=</varname> in <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</entry>
1099 </row>
1100 <row>
1101 <entry>LimitSTACK=</entry>
1102 <entry>ulimit -s</entry>
1103 <entry>Bytes</entry>
1104 <entry>-</entry>
1105 </row>
1106 <row>
1107 <entry>LimitCORE=</entry>
1108 <entry>ulimit -c</entry>
1109 <entry>Bytes</entry>
1110 <entry>-</entry>
1111 </row>
1112 <row>
1113 <entry>LimitRSS=</entry>
1114 <entry>ulimit -m</entry>
1115 <entry>Bytes</entry>
1116 <entry>Do not use. No effect on Linux.</entry>
1117 </row>
1118 <row>
1119 <entry>LimitNOFILE=</entry>
1120 <entry>ulimit -n</entry>
1121 <entry>Number of File Descriptors</entry>
1122 <entry>Do not use. Be careful when raising the soft limit above 1024, since <citerefentry project='man-pages'><refentrytitle>select</refentrytitle><manvolnum>2</manvolnum></citerefentry> cannot function with file descriptors above 1023 on Linux. Nowadays, the hard limit defaults to 524288, a very high value compared to historical defaults. Typically applications should increase their soft limit to the hard limit on their own, if they are OK with working with file descriptors above 1023, i.e. do not use <citerefentry project='man-pages'><refentrytitle>select</refentrytitle><manvolnum>2</manvolnum></citerefentry>. Note that file descriptors are nowadays accounted like any other form of memory, thus there should not be any need to lower the hard limit. Use <varname>MemoryMax=</varname> to control overall service memory use, including file descriptor memory.</entry>
1123 </row>
1124 <row>
1125 <entry>LimitAS=</entry>
1126 <entry>ulimit -v</entry>
1127 <entry>Bytes</entry>
1128 <entry>Do not use. This limits the allowed address range, not memory use! Defaults to unlimited and should not be lowered. To limit memory use, see <varname>MemoryMax=</varname> in <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</entry>
1129 </row>
1130 <row>
1131 <entry>LimitNPROC=</entry>
1132 <entry>ulimit -u</entry>
1133 <entry>Number of Processes</entry>
1134 <entry>This limit is enforced based on the number of processes belonging to the user. Typically it is better to track processes per service, i.e. use <varname>TasksMax=</varname>, see <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</entry>
1135 </row>
1136 <row>
1137 <entry>LimitMEMLOCK=</entry>
1138 <entry>ulimit -l</entry>
1139 <entry>Bytes</entry>
1140 <entry>-</entry>
1141 </row>
1142 <row>
1143 <entry>LimitLOCKS=</entry>
1144 <entry>ulimit -x</entry>
1145 <entry>Number of Locks</entry>
1146 <entry>-</entry>
1147 </row>
1148 <row>
1149 <entry>LimitSIGPENDING=</entry>
1150 <entry>ulimit -i</entry>
1151 <entry>Number of Queued Signals</entry>
1152 <entry>-</entry>
1153 </row>
1154 <row>
1155 <entry>LimitMSGQUEUE=</entry>
1156 <entry>ulimit -q</entry>
1157 <entry>Bytes</entry>
1158 <entry>-</entry>
1159 </row>
1160 <row>
1161 <entry>LimitNICE=</entry>
1162 <entry>ulimit -e</entry>
1163 <entry>Nice Level</entry>
1164 <entry>-</entry>
1165 </row>
1166 <row>
1167 <entry>LimitRTPRIO=</entry>
1168 <entry>ulimit -r</entry>
1169 <entry>Realtime Priority</entry>
1170 <entry>-</entry>
1171 </row>
1172 <row>
1173 <entry>LimitRTTIME=</entry>
1174 <entry>ulimit -R</entry>
1175 <entry>Microseconds</entry>
1176 <entry>-</entry>
1177 </row>
1178 </tbody>
1179 </tgroup>
1180 </table></listitem>
1181 </varlistentry>
1182
1183 <varlistentry>
1184 <term><varname>UMask=</varname></term>
1185
1186 <listitem><para>Controls the file mode creation mask. Takes an access mode in octal notation. See
1187 <citerefentry><refentrytitle>umask</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
1188 details. Defaults to 0022 for system units. For user units the default value is inherited from the
1189 per-user service manager (whose default is in turn inherited from the system service manager, and
1190 thus typically also is 0022 — unless overridden by a PAM module). In order to change the per-user mask
1191 for all user services, consider setting the <varname>UMask=</varname> setting of the user's
1192 <filename>user@.service</filename> system service instance. The per-user umask may also be set via
1193 the <varname>umask</varname> field of a user's <ulink url="https://systemd.io/USER_RECORD">JSON User
1194 Record</ulink> (for users managed by
1195 <citerefentry><refentrytitle>systemd-homed.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1196 this field may be controlled via <command>homectl --umask=</command>). It may also be set via a PAM
1197 module, such as <citerefentry
1198 project='man-pages'><refentrytitle>pam_umask</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para></listitem>
1199 </varlistentry>
1200
1201 <varlistentry>
1202 <term><varname>CoredumpFilter=</varname></term>
1203
1204 <listitem><para>Controls which types of memory mappings will be saved if the process dumps core
1205 (using the <filename>/proc/<replaceable>pid</replaceable>/coredump_filter</filename> file). Takes a
1206 whitespace-separated combination of mapping type names or numbers (with the default base 16). Mapping
1207 type names are <constant>private-anonymous</constant>, <constant>shared-anonymous</constant>,
1208 <constant>private-file-backed</constant>, <constant>shared-file-backed</constant>,
1209 <constant>elf-headers</constant>, <constant>private-huge</constant>,
1210 <constant>shared-huge</constant>, <constant>private-dax</constant>, <constant>shared-dax</constant>,
1211 and the special values <constant>all</constant> (all types) and <constant>default</constant> (the
1212 kernel default of <literal><constant>private-anonymous</constant>
1213 <constant>shared-anonymous</constant> <constant>elf-headers</constant>
1214 <constant>private-huge</constant></literal>). See
1215 <citerefentry project='man-pages'><refentrytitle>core</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1216 for the meaning of the mapping types. When specified multiple times, all specified masks are
1217 ORed. When not set, or if the empty value is assigned, the inherited value is not changed.</para>
1218
1219 <example>
1220 <title>Add DAX pages to the dump filter</title>
1221
1222 <programlisting>CoredumpFilter=default private-dax shared-dax</programlisting>
1223 </example>
1224
1225 <xi:include href="version-info.xml" xpointer="v246"/>
1226 </listitem>
1227 </varlistentry>
1228
1229 <varlistentry>
1230 <term><varname>KeyringMode=</varname></term>
1231
1232 <listitem><para>Controls how the kernel session keyring is set up for the service (see <citerefentry
1233 project='man-pages'><refentrytitle>session-keyring</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
1234 details on the session keyring). Takes one of <option>inherit</option>, <option>private</option>,
1235 <option>shared</option>. If set to <option>inherit</option> no special keyring setup is done, and the kernel's
1236 default behaviour is applied. If <option>private</option> is used a new session keyring is allocated when a
1237 service process is invoked, and it is not linked up with any user keyring. This is the recommended setting for
1238 system services, as this ensures that multiple services running under the same system user ID (in particular
1239 the root user) do not share their key material among each other. If <option>shared</option> is used a new
1240 session keyring is allocated as for <option>private</option>, but the user keyring of the user configured with
1241 <varname>User=</varname> is linked into it, so that keys assigned to the user may be requested by the unit's
1242 processes. In this mode multiple units running processes under the same user ID may share key material. Unless
1243 <option>inherit</option> is selected the unique invocation ID for the unit (see below) is added as a protected
1244 key by the name <literal>invocation_id</literal> to the newly created session keyring. Defaults to
1245 <option>private</option> for services of the system service manager and to <option>inherit</option> for
1246 non-service units and for services of the user service manager.</para>
1247
1248 <xi:include href="version-info.xml" xpointer="v235"/></listitem>
1249 </varlistentry>
1250
1251 <varlistentry>
1252 <term><varname>OOMScoreAdjust=</varname></term>
1253
1254 <listitem><para>Sets the adjustment value for the Linux kernel's Out-Of-Memory (OOM) killer score for
1255 executed processes. Takes an integer between -1000 (to disable OOM killing of processes of this unit)
1256 and 1000 (to make killing of processes of this unit under memory pressure very likely). See <ulink
1257 url="https://docs.kernel.org/filesystems/proc.html">The /proc Filesystem</ulink> for
1258 details. If not specified, defaults to the OOM score adjustment level of the service manager itself,
1259 which is normally at 0.</para>
1260
1261 <para>Use the <varname>OOMPolicy=</varname> setting of service units to configure how the service
1262 manager shall react to the kernel OOM killer or <command>systemd-oomd</command> terminating a process of the service. See
1263 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1264 for details.</para></listitem>
1265 </varlistentry>
1266
1267 <varlistentry>
1268 <term><varname>TimerSlackNSec=</varname></term>
1269 <listitem><para>Sets the timer slack in nanoseconds for the executed processes. The timer slack controls the
1270 accuracy of wake-ups triggered by timers. See
1271 <citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry> for more
1272 information. Note that in contrast to most other time span definitions this parameter takes an integer value in
1273 nano-seconds if no unit is specified. The usual time units are understood too.</para></listitem>
1274 </varlistentry>
1275
1276 <varlistentry>
1277 <term><varname>Personality=</varname></term>
1278
1279 <listitem><para>Controls which kernel architecture <citerefentry
1280 project='man-pages'><refentrytitle>uname</refentrytitle><manvolnum>2</manvolnum></citerefentry> shall
1281 report, when invoked by unit processes. Takes one of the architecture identifiers
1282 <constant>arm64</constant>, <constant>arm64-be</constant>, <constant>arm</constant>,
1283 <constant>arm-be</constant>, <constant>x86</constant>, <constant>x86-64</constant>,
1284 <constant>ppc</constant>, <constant>ppc-le</constant>, <constant>ppc64</constant>,
1285 <constant>ppc64-le</constant>, <constant>s390</constant> or <constant>s390x</constant>. Which
1286 personality architectures are supported depends on the kernel's native architecture. Usually the
1287 64-bit versions of the various system architectures support their immediate 32-bit personality
1288 architecture counterpart, but no others. For example, <constant>x86-64</constant> systems support the
1289 <constant>x86-64</constant> and <constant>x86</constant> personalities but no others. The personality
1290 feature is useful when running 32-bit services on a 64-bit host system. If not specified, the
1291 personality is left unmodified and thus reflects the personality of the host system's kernel. This
1292 option is not useful on architectures for which only one native word width was ever available, such
1293 as <constant>m68k</constant> (32-bit only) or <constant>alpha</constant> (64-bit only).</para>
1294
1295 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
1296 </varlistentry>
1297
1298 <varlistentry>
1299 <term><varname>IgnoreSIGPIPE=</varname></term>
1300
1301 <listitem><para>Takes a boolean argument. If true, <constant>SIGPIPE</constant> is ignored in the
1302 executed process. Defaults to true since <constant>SIGPIPE</constant> is generally only useful in
1303 shell pipelines.</para></listitem>
1304 </varlistentry>
1305
1306 </variablelist>
1307 </refsect1>
1308
1309 <refsect1>
1310 <title>Scheduling</title>
1311
1312 <variablelist class='unit-directives'>
1313
1314 <varlistentry>
1315 <term><varname>Nice=</varname></term>
1316
1317 <listitem><para>Sets the default nice level (scheduling priority) for executed processes. Takes an
1318 integer between -20 (highest priority) and 19 (lowest priority). In case of resource contention,
1319 smaller values mean more resources will be made available to the unit's processes, larger values mean
1320 less resources will be made available. See
1321 <citerefentry><refentrytitle>setpriority</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
1322 details.</para></listitem>
1323 </varlistentry>
1324
1325 <varlistentry>
1326 <term><varname>CPUSchedulingPolicy=</varname></term>
1327
1328 <listitem><para>Sets the CPU scheduling policy for executed processes. Takes one of <option>other</option>,
1329 <option>batch</option>, <option>idle</option>, <option>fifo</option> or <option>rr</option>. See
1330 <citerefentry project='man-pages'><refentrytitle>sched_setscheduler</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
1331 details.</para></listitem>
1332 </varlistentry>
1333
1334 <varlistentry>
1335 <term><varname>CPUSchedulingPriority=</varname></term>
1336
1337 <listitem><para>Sets the CPU scheduling priority for executed processes. The available priority range
1338 depends on the selected CPU scheduling policy (see above). For real-time scheduling policies an
1339 integer between 1 (lowest priority) and 99 (highest priority) can be used. In case of CPU resource
1340 contention, smaller values mean less CPU time is made available to the service, larger values mean
1341 more. See <citerefentry
1342 project='man-pages'><refentrytitle>sched_setscheduler</refentrytitle><manvolnum>2</manvolnum></citerefentry>
1343 for details. </para></listitem>
1344 </varlistentry>
1345
1346 <varlistentry>
1347 <term><varname>CPUSchedulingResetOnFork=</varname></term>
1348
1349 <listitem><para>Takes a boolean argument. If true, elevated CPU scheduling priorities and policies
1350 will be reset when the executed processes call
1351 <citerefentry project='man-pages'><refentrytitle>fork</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
1352 and can hence not leak into child processes. See
1353 <citerefentry project='man-pages'><refentrytitle>sched_setscheduler</refentrytitle><manvolnum>2</manvolnum></citerefentry>
1354 for details. Defaults to false.</para></listitem>
1355 </varlistentry>
1356
1357 <varlistentry>
1358 <term><varname>CPUAffinity=</varname></term>
1359
1360 <listitem><para>Controls the CPU affinity of the executed processes. Takes a list of CPU indices or ranges
1361 separated by either whitespace or commas. Alternatively, takes a special "numa" value in which case systemd
1362 automatically derives allowed CPU range based on the value of <varname>NUMAMask=</varname> option. CPU ranges
1363 are specified by the lower and upper CPU indices separated by a dash. This option may be specified more than
1364 once, in which case the specified CPU affinity masks are merged. If the empty string is assigned, the mask
1365 is reset, all assignments prior to this will have no effect. See
1366 <citerefentry project='man-pages'><refentrytitle>sched_setaffinity</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
1367 details.</para></listitem>
1368 </varlistentry>
1369
1370 <varlistentry>
1371 <term><varname>NUMAPolicy=</varname></term>
1372
1373 <listitem><para>Controls the NUMA memory policy of the executed processes. Takes a policy type, one of:
1374 <option>default</option>, <option>preferred</option>, <option>bind</option>, <option>interleave</option> and
1375 <option>local</option>. A list of NUMA nodes that should be associated with the policy must be specified
1376 in <varname>NUMAMask=</varname>. For more details on each policy please see,
1377 <citerefentry><refentrytitle>set_mempolicy</refentrytitle><manvolnum>2</manvolnum></citerefentry>. For overall
1378 overview of NUMA support in Linux see,
1379 <citerefentry project='man-pages'><refentrytitle>numa</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
1380 </para>
1381
1382 <xi:include href="version-info.xml" xpointer="v243"/></listitem>
1383 </varlistentry>
1384
1385 <varlistentry>
1386 <term><varname>NUMAMask=</varname></term>
1387
1388 <listitem><para>Controls the NUMA node list which will be applied alongside with selected NUMA policy.
1389 Takes a list of NUMA nodes and has the same syntax as a list of CPUs for <varname>CPUAffinity=</varname>
1390 option or special "all" value which will include all available NUMA nodes in the mask. Note that the list
1391 of NUMA nodes is not required for <option>default</option> and <option>local</option>
1392 policies and for <option>preferred</option> policy we expect a single NUMA node.</para>
1393
1394 <xi:include href="version-info.xml" xpointer="v243"/></listitem>
1395 </varlistentry>
1396
1397 <varlistentry>
1398 <term><varname>IOSchedulingClass=</varname></term>
1399
1400 <listitem><para>Sets the I/O scheduling class for executed processes. Takes one of the strings
1401 <option>realtime</option>, <option>best-effort</option> or <option>idle</option>. The kernel's
1402 default scheduling class is <option>best-effort</option> at a priority of 4. If the empty string is
1403 assigned to this option, all prior assignments to both <varname>IOSchedulingClass=</varname> and
1404 <varname>IOSchedulingPriority=</varname> have no effect. See
1405 <citerefentry><refentrytitle>ioprio_set</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
1406 details.</para></listitem>
1407 </varlistentry>
1408
1409 <varlistentry>
1410 <term><varname>IOSchedulingPriority=</varname></term>
1411
1412 <listitem><para>Sets the I/O scheduling priority for executed processes. Takes an integer between 0
1413 (highest priority) and 7 (lowest priority). In case of I/O contention, smaller values mean more I/O
1414 bandwidth is made available to the unit's processes, larger values mean less bandwidth. The available
1415 priorities depend on the selected I/O scheduling class (see above). If the empty string is assigned
1416 to this option, all prior assignments to both <varname>IOSchedulingClass=</varname> and
1417 <varname>IOSchedulingPriority=</varname> have no effect. For the kernel's default scheduling class
1418 (<option>best-effort</option>) this defaults to 4. See
1419 <citerefentry><refentrytitle>ioprio_set</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
1420 details.</para></listitem>
1421 </varlistentry>
1422
1423 </variablelist>
1424 </refsect1>
1425
1426 <refsect1>
1427 <title>Sandboxing</title>
1428
1429 <para>The following sandboxing options are an effective way to limit the exposure of the system towards the unit's
1430 processes. It is recommended to turn on as many of these options for each unit as is possible without negatively
1431 affecting the process' ability to operate. Note that many of these sandboxing features are gracefully turned off on
1432 systems where the underlying security mechanism is not available. For example, <varname>ProtectSystem=</varname>
1433 has no effect if the kernel is built without file system namespacing or if the service manager runs in a container
1434 manager that makes file system namespacing unavailable to its payload. Similarly,
1435 <varname>RestrictRealtime=</varname> has no effect on systems that lack support for SECCOMP system call filtering,
1436 or in containers where support for this is turned off.</para>
1437
1438 <para>Also note that some sandboxing functionality is generally not available in user services (i.e. services run
1439 by the per-user service manager). Specifically, the various settings requiring file system namespacing support
1440 (such as <varname>ProtectSystem=</varname>) are not available, as the underlying kernel functionality is only
1441 accessible to privileged processes. However, most namespacing settings, that will not work on their own in user
1442 services, will work when used in conjunction with <varname>PrivateUsers=</varname><option>true</option>.</para>
1443
1444 <para>Note that the various options that turn directories read-only (such as
1445 <varname>ProtectSystem=</varname>, <varname>ReadOnlyPaths=</varname>, …) do not affect the ability for
1446 programs to connect to and communicate with <constant>AF_UNIX</constant> sockets in these
1447 directories. These options cannot be used to lock down access to IPC services hence.</para>
1448
1449 <variablelist class='unit-directives'>
1450
1451 <varlistentry>
1452 <term><varname>ProtectSystem=</varname></term>
1453
1454 <listitem><para>Takes a boolean argument or the special values <literal>full</literal> or
1455 <literal>strict</literal>. If true, mounts the <filename>/usr/</filename> and the boot loader
1456 directories (<filename>/boot</filename> and <filename>/efi</filename>) read-only for processes
1457 invoked by this unit. If set to <literal>full</literal>, the <filename>/etc/</filename> directory is
1458 mounted read-only, too. If set to <literal>strict</literal> the entire file system hierarchy is
1459 mounted read-only, except for the API file system subtrees <filename>/dev/</filename>,
1460 <filename>/proc/</filename> and <filename>/sys/</filename> (protect these directories using
1461 <varname>PrivateDevices=</varname>, <varname>ProtectKernelTunables=</varname>,
1462 <varname>ProtectControlGroups=</varname>). This setting ensures that any modification of the
1463 vendor-supplied operating system (and optionally its configuration, and local mounts) is prohibited
1464 for the service. It is recommended to enable this setting for all long-running services, unless they
1465 are involved with system updates or need to modify the operating system in other ways. If this option
1466 is used, <varname>ReadWritePaths=</varname> may be used to exclude specific directories from being
1467 made read-only. Similar, <varname>StateDirectory=</varname>, <varname>LogsDirectory=</varname>, … and
1468 related directory settings (see below) also exclude the specific directories from the effect of
1469 <varname>ProtectSystem=</varname>. This setting is implied if <varname>DynamicUser=</varname> is
1470 set. This setting cannot ensure protection in all cases. In general it has the same limitations as
1471 <varname>ReadOnlyPaths=</varname>, see below. Defaults to off.</para>
1472
1473 <para>Note that if <varname>ProtectSystem=</varname> is set to <literal>strict</literal> and
1474 <varname>PrivateTmp=</varname> is enabled, then <filename>/tmp/</filename> and
1475 <filename>/var/tmp/</filename> will be writable.</para>
1476
1477 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
1478 </varlistentry>
1479
1480 <varlistentry>
1481 <term><varname>ProtectHome=</varname></term>
1482
1483 <listitem><para>Takes a boolean argument or the special values <literal>read-only</literal> or
1484 <literal>tmpfs</literal>. If true, the directories <filename>/home/</filename>,
1485 <filename>/root</filename>, and <filename>/run/user</filename> are made inaccessible and empty for
1486 processes invoked by this unit. If set to <literal>read-only</literal>, the three directories are
1487 made read-only instead. If set to <literal>tmpfs</literal>, temporary file systems are mounted on the
1488 three directories in read-only mode. The value <literal>tmpfs</literal> is useful to hide home
1489 directories not relevant to the processes invoked by the unit, while still allowing necessary
1490 directories to be made visible when listed in <varname>BindPaths=</varname> or
1491 <varname>BindReadOnlyPaths=</varname>.</para>
1492
1493 <para>Setting this to <literal>yes</literal> is mostly equivalent to setting the three directories in
1494 <varname>InaccessiblePaths=</varname>. Similarly, <literal>read-only</literal> is mostly equivalent to
1495 <varname>ReadOnlyPaths=</varname>, and <literal>tmpfs</literal> is mostly equivalent to
1496 <varname>TemporaryFileSystem=</varname> with <literal>:ro</literal>.</para>
1497
1498 <para>It is recommended to enable this setting for all long-running services (in particular
1499 network-facing ones), to ensure they cannot get access to private user data, unless the services
1500 actually require access to the user's private data. This setting is implied if
1501 <varname>DynamicUser=</varname> is set. This setting cannot ensure protection in all cases. In
1502 general it has the same limitations as <varname>ReadOnlyPaths=</varname>, see below.</para>
1503
1504 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
1505
1506 <xi:include href="version-info.xml" xpointer="v214"/></listitem>
1507 </varlistentry>
1508
1509 <varlistentry>
1510 <term><varname>RuntimeDirectory=</varname></term>
1511 <term><varname>StateDirectory=</varname></term>
1512 <term><varname>CacheDirectory=</varname></term>
1513 <term><varname>LogsDirectory=</varname></term>
1514 <term><varname>ConfigurationDirectory=</varname></term>
1515
1516 <listitem><para>These options take a whitespace-separated list of directory names. The specified
1517 directory names must be relative, and may not include <literal>..</literal>. If set, when the unit is
1518 started, one or more directories by the specified names will be created (including their parents)
1519 below the locations defined in the following table. Also, the corresponding environment variable will
1520 be defined with the full paths of the directories. If multiple directories are set, then in the
1521 environment variable the paths are concatenated with colon (<literal>:</literal>).</para>
1522
1523 <para>If <varname>DynamicUser=</varname> is used, and if the kernel version supports
1524 <ulink url="https://lwn.net/Articles/896255/">id-mapped mounts</ulink>, the specified directories will
1525 be owned by "nobody" in the host namespace and will be mapped to (and will be owned by) the service's
1526 UID/GID in its own namespace. For backward compatibility, existing directories created without id-mapped
1527 mounts will be kept untouched.</para>
1528
1529 <table>
1530 <title>Automatic directory creation and environment variables</title>
1531 <tgroup cols='4'>
1532 <thead>
1533 <row>
1534 <entry>Directory</entry>
1535 <entry>Below path for system units</entry>
1536 <entry>Below path for user units</entry>
1537 <entry>Environment variable set</entry>
1538 </row>
1539 </thead>
1540 <tbody>
1541 <row>
1542 <entry><varname>RuntimeDirectory=</varname></entry>
1543 <entry><filename>/run/</filename></entry>
1544 <entry><varname>$XDG_RUNTIME_DIR</varname></entry>
1545 <entry><varname>$RUNTIME_DIRECTORY</varname></entry>
1546 </row>
1547 <row>
1548 <entry><varname>StateDirectory=</varname></entry>
1549 <entry><filename>/var/lib/</filename></entry>
1550 <entry><varname>$XDG_STATE_HOME</varname></entry>
1551 <entry><varname>$STATE_DIRECTORY</varname></entry>
1552 </row>
1553 <row>
1554 <entry><varname>CacheDirectory=</varname></entry>
1555 <entry><filename>/var/cache/</filename></entry>
1556 <entry><varname>$XDG_CACHE_HOME</varname></entry>
1557 <entry><varname>$CACHE_DIRECTORY</varname></entry>
1558 </row>
1559 <row>
1560 <entry><varname>LogsDirectory=</varname></entry>
1561 <entry><filename>/var/log/</filename></entry>
1562 <entry><varname>$XDG_STATE_HOME</varname><filename>/log/</filename></entry>
1563 <entry><varname>$LOGS_DIRECTORY</varname></entry>
1564 </row>
1565 <row>
1566 <entry><varname>ConfigurationDirectory=</varname></entry>
1567 <entry><filename>/etc/</filename></entry>
1568 <entry><varname>$XDG_CONFIG_HOME</varname></entry>
1569 <entry><varname>$CONFIGURATION_DIRECTORY</varname></entry>
1570 </row>
1571 </tbody>
1572 </tgroup>
1573 </table>
1574
1575 <para>In case of <varname>RuntimeDirectory=</varname> the innermost subdirectories are removed when
1576 the unit is stopped. It is possible to preserve the specified directories in this case if
1577 <varname>RuntimeDirectoryPreserve=</varname> is configured to <option>restart</option> or
1578 <option>yes</option> (see below). The directories specified with <varname>StateDirectory=</varname>,
1579 <varname>CacheDirectory=</varname>, <varname>LogsDirectory=</varname>,
1580 <varname>ConfigurationDirectory=</varname> are not removed when the unit is stopped.</para>
1581
1582 <para>Except in case of <varname>ConfigurationDirectory=</varname>, the innermost specified directories will be
1583 owned by the user and group specified in <varname>User=</varname> and <varname>Group=</varname>. If the
1584 specified directories already exist and their owning user or group do not match the configured ones, all files
1585 and directories below the specified directories as well as the directories themselves will have their file
1586 ownership recursively changed to match what is configured. As an optimization, if the specified directories are
1587 already owned by the right user and group, files and directories below of them are left as-is, even if they do
1588 not match what is requested. The innermost specified directories will have their access mode adjusted to the
1589 what is specified in <varname>RuntimeDirectoryMode=</varname>, <varname>StateDirectoryMode=</varname>,
1590 <varname>CacheDirectoryMode=</varname>, <varname>LogsDirectoryMode=</varname> and
1591 <varname>ConfigurationDirectoryMode=</varname>.</para>
1592
1593 <para>These options imply <varname>BindPaths=</varname> for the specified paths. When combined with
1594 <varname>RootDirectory=</varname> or <varname>RootImage=</varname> these paths always reside on the host and
1595 are mounted from there into the unit's file system namespace.</para>
1596
1597 <para>If <varname>DynamicUser=</varname> is used, the logic for <varname>CacheDirectory=</varname>,
1598 <varname>LogsDirectory=</varname> and <varname>StateDirectory=</varname> is slightly altered: the directories are created below
1599 <filename>/var/cache/private</filename>, <filename>/var/log/private</filename> and <filename>/var/lib/private</filename>,
1600 respectively, which are host directories made inaccessible to
1601 unprivileged users, which ensures that access to these directories cannot be gained through dynamic
1602 user ID recycling. Symbolic links are created to hide this difference in behaviour. Both from
1603 perspective of the host and from inside the unit, the relevant directories hence always appear
1604 directly below <filename>/var/cache</filename>, <filename>/var/log</filename> and
1605 <filename>/var/lib</filename>.</para>
1606
1607 <para>Use <varname>RuntimeDirectory=</varname> to manage one or more runtime directories for the unit and bind
1608 their lifetime to the daemon runtime. This is particularly useful for unprivileged daemons that cannot create
1609 runtime directories in <filename>/run/</filename> due to lack of privileges, and to make sure the runtime
1610 directory is cleaned up automatically after use. For runtime directories that require more complex or different
1611 configuration or lifetime guarantees, please consider using
1612 <citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
1613
1614 <para><varname>RuntimeDirectory=</varname>, <varname>StateDirectory=</varname>,
1615 <varname>CacheDirectory=</varname> and <varname>LogsDirectory=</varname> optionally support two
1616 more parameters, separated by <literal>:</literal>. The second parameter will be interpreted as a
1617 destination path that will be created as a symlink to the directory. The symlinks will be created
1618 after any <varname>BindPaths=</varname> or <varname>TemporaryFileSystem=</varname> options have been
1619 set up, to make ephemeral symlinking possible. The same source can have multiple symlinks, by using
1620 the same first parameter, but a different second parameter. The third parameter is a flags field,
1621 and since v257 can take a value of <constant>ro</constant> to make the directory read only for the
1622 service. This is also supported for <varname>ConfigurationDirectory=</varname>. If multiple symlinks
1623 are set up, the directory will be read only if at least one is configured to be read only. To pass a
1624 flag without a destination symlink, the second parameter can be empty, for example:
1625 <programlisting>ConfigurationDirectory=foo::ro</programlisting></para>
1626
1627 <para>The directories defined by these options are always created under the standard paths used by systemd
1628 (<filename>/var/</filename>, <filename>/run/</filename>, <filename>/etc/</filename>, …). If the service needs
1629 directories in a different location, a different mechanism has to be used to create them.</para>
1630
1631 <para><citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> provides
1632 functionality that overlaps with these options. Using these options is recommended, because the lifetime of
1633 the directories is tied directly to the lifetime of the unit, and it is not necessary to ensure that the
1634 <filename>tmpfiles.d</filename> configuration is executed before the unit is started.</para>
1635
1636 <para>To remove any of the directories created by these settings, use the <command>systemctl clean
1637 …</command> command on the relevant units, see
1638 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
1639 details.</para>
1640
1641 <para>Example: if a system service unit has the following,
1642 <programlisting>RuntimeDirectory=foo/bar baz</programlisting>
1643 the service manager creates <filename index='false'>/run/foo</filename> (if it does not exist),
1644
1645 <filename index='false'>/run/foo/bar</filename>, and <filename index='false'>/run/baz</filename>. The
1646 directories <filename index='false'>/run/foo/bar</filename> and
1647 <filename index='false'>/run/baz</filename> except <filename index='false'>/run/foo</filename> are
1648 owned by the user and group specified in <varname>User=</varname> and <varname>Group=</varname>, and removed
1649 when the service is stopped.</para>
1650
1651 <para>Example: if a system service unit has the following,
1652 <programlisting>RuntimeDirectory=foo/bar
1653StateDirectory=aaa/bbb ccc</programlisting>
1654 then the environment variable <literal>RUNTIME_DIRECTORY</literal> is set with <literal>/run/foo/bar</literal>, and
1655 <literal>STATE_DIRECTORY</literal> is set with <literal>/var/lib/aaa/bbb:/var/lib/ccc</literal>.</para>
1656
1657 <para>Example: if a system service unit has the following,
1658 <programlisting>RuntimeDirectory=foo:bar foo:baz</programlisting>
1659 the service manager creates <filename index='false'>/run/foo</filename> (if it does not exist), and
1660 <filename index='false'>/run/bar</filename> plus <filename index='false'>/run/baz</filename> as symlinks to
1661 <filename index='false'>/run/foo</filename>.</para>
1662
1663 <xi:include href="version-info.xml" xpointer="v211"/></listitem>
1664 </varlistentry>
1665
1666 <varlistentry>
1667 <term><varname>RuntimeDirectoryMode=</varname></term>
1668 <term><varname>StateDirectoryMode=</varname></term>
1669 <term><varname>CacheDirectoryMode=</varname></term>
1670 <term><varname>LogsDirectoryMode=</varname></term>
1671 <term><varname>ConfigurationDirectoryMode=</varname></term>
1672
1673 <listitem><para>Specifies the access mode of the directories specified in <varname>RuntimeDirectory=</varname>,
1674 <varname>StateDirectory=</varname>, <varname>CacheDirectory=</varname>, <varname>LogsDirectory=</varname>, or
1675 <varname>ConfigurationDirectory=</varname>, respectively, as an octal number. Defaults to
1676 <constant>0755</constant>. See "Permissions" in <citerefentry
1677 project='man-pages'><refentrytitle>path_resolution</refentrytitle><manvolnum>7</manvolnum></citerefentry> for a
1678 discussion of the meaning of permission bits.</para>
1679
1680 <xi:include href="version-info.xml" xpointer="v234"/></listitem>
1681 </varlistentry>
1682
1683 <varlistentry>
1684 <term><varname>StateDirectoryQuota=</varname></term>
1685 <term><varname>CacheDirectoryQuota=</varname></term>
1686 <term><varname>LogsDirectoryQuota=</varname></term>
1687
1688 <listitem><para>Specifies the storage limits for the directories specified in <varname>StateDirectory=</varname>,
1689 <varname>CacheDirectory=</varname>, or <varname>LogsDirectory=</varname> respectively.</para>
1690
1691 <para>The storage quota is defined in terms of disk blocks and inodes, as per
1692 <ulink url="https://man7.org/linux/man-pages/man2/quotactl.2.html">quotactl</ulink>. Takes an absolute size limit
1693 in bytes. If the value is suffixed with K, M, G or T, the specified size is parsed as Kilobytes, Megabytes, Gigabytes,
1694 or Terabytes (with the base 1024), respectively. If an absolute size limit is specified, only the block quota is set
1695 (rounded up to the nearest block). Alternatively, a percentage value may be specified, which applies the same percent
1696 quota to both blocks and inodes. Defaults to <constant>off</constant>, in which case no storage limits will be set.</para>
1697
1698 <para>Only hard limits are set, not soft limits. If the underlying filesystem for the specified directories does not
1699 support project quotas, the specified storage limits will not be set. In addition to enabling per-unit quotas with
1700 these settings, it is necessary to enable <constant>prjquota</constant> on the file system level as well
1701 (i.e. <command>tune2fs -Q prjquota</command>). Quotas must also be turned on with
1702 <ulink url="https://linux.die.net/man/8/quotaon">quotaon.</ulink></para>
1703
1704 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
1705 </varlistentry>
1706
1707 <varlistentry>
1708 <term><varname>StateDirectoryAccounting=</varname></term>
1709 <term><varname>CacheDirectoryAccounting=</varname></term>
1710 <term><varname>LogsDirectoryAccounting=</varname></term>
1711
1712 <listitem><para>Takes a boolean argument. If true, a project ID is assigned to the directories specified in
1713 <varname>StateDirectory=</varname>, <varname>CacheDirectory=</varname>, or <varname>LogsDirectory=</varname>
1714 respectively, which is used for tracking disk usage when disk quotas are turned on
1715 (see <ulink url="https://man7.org/linux/man-pages/man8/repquota.8.html">repquota</ulink>). Defaults to false.</para>
1716
1717 <para>To set and enforce disk quotas, <varname>StateDirectoryQuota=</varname>, <varname>CacheDirectoryQuota=</varname>,
1718 or <varname>LogsDirectoryQuota=</varname> must be specified.</para>
1719
1720 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
1721 </varlistentry>
1722
1723 <varlistentry>
1724 <term><varname>RuntimeDirectoryPreserve=</varname></term>
1725
1726 <listitem><para>Takes a boolean argument or <option>restart</option>. If set to <option>no</option> (the
1727 default), the directories specified in <varname>RuntimeDirectory=</varname> are always removed when the service
1728 stops. If set to <option>restart</option> the directories are preserved when the service is both automatically
1729 and manually restarted. Here, the automatic restart means the operation specified in
1730 <varname>Restart=</varname>, and manual restart means the one triggered by <command>systemctl restart
1731 foo.service</command>. If set to <option>yes</option>, then the directories are not removed when the service is
1732 stopped. Note that since the runtime directory <filename>/run/</filename> is a mount point of
1733 <literal>tmpfs</literal>, then for system services the directories specified in
1734 <varname>RuntimeDirectory=</varname> are removed when the system is rebooted.</para>
1735
1736 <xi:include href="version-info.xml" xpointer="v235"/></listitem>
1737 </varlistentry>
1738
1739 <varlistentry>
1740 <term><varname>TimeoutCleanSec=</varname></term>
1741 <listitem><para>Configures a timeout on the clean-up operation requested through <command>systemctl
1742 clean …</command>, see
1743 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
1744 details. Takes the usual time values and defaults to <constant>infinity</constant>, i.e. by default
1745 no timeout is applied. If a timeout is configured the clean operation will be aborted forcibly when
1746 the timeout is reached, potentially leaving resources on disk.</para>
1747
1748 <xi:include href="version-info.xml" xpointer="v244"/></listitem>
1749 </varlistentry>
1750
1751 <varlistentry>
1752 <term><varname>ReadWritePaths=</varname></term>
1753 <term><varname>ReadOnlyPaths=</varname></term>
1754 <term><varname>InaccessiblePaths=</varname></term>
1755 <term><varname>ExecPaths=</varname></term>
1756 <term><varname>NoExecPaths=</varname></term>
1757
1758 <listitem><para>Sets up a new file system namespace for executed processes. These options may be used
1759 to limit access a process has to the file system. Each setting takes a space-separated list of paths
1760 relative to the host's root directory (i.e. the system running the service manager). Note that if
1761 paths contain symlinks, they are resolved relative to the root directory set with
1762 <varname>RootDirectory=</varname>/<varname>RootImage=</varname>.</para>
1763
1764 <para>Paths listed in <varname>ReadWritePaths=</varname> are accessible from within the namespace
1765 with the same access modes as from outside of it. Paths listed in <varname>ReadOnlyPaths=</varname>
1766 are accessible for reading only, writing will be refused even if the usual file access controls would
1767 permit this. Nest <varname>ReadWritePaths=</varname> inside of <varname>ReadOnlyPaths=</varname> in
1768 order to provide writable subdirectories within read-only directories. Use
1769 <varname>ReadWritePaths=</varname> in order to allow-list specific paths for write access if
1770 <varname>ProtectSystem=strict</varname> is used. Note that <varname>ReadWritePaths=</varname> cannot
1771 be used to gain write access to a file system whose superblock is mounted read-only. On Linux, for
1772 each mount point write access is granted only if the mount point itself <emphasis>and</emphasis> the
1773 file system superblock backing it are not marked read-only. <varname>ReadWritePaths=</varname> only
1774 controls the former, not the latter, hence a read-only file system superblock remains
1775 protected.</para>
1776
1777 <para>Paths listed in <varname>InaccessiblePaths=</varname> will be made inaccessible for processes inside
1778 the namespace along with everything below them in the file system hierarchy. This may be more restrictive than
1779 desired, because it is not possible to nest <varname>ReadWritePaths=</varname>, <varname>ReadOnlyPaths=</varname>,
1780 <varname>BindPaths=</varname>, or <varname>BindReadOnlyPaths=</varname> inside it. For a more flexible option,
1781 see <varname>TemporaryFileSystem=</varname>.</para>
1782
1783 <para>Content in paths listed in <varname>NoExecPaths=</varname> are not executable even if the usual
1784 file access controls would permit this. Nest <varname>ExecPaths=</varname> inside of
1785 <varname>NoExecPaths=</varname> in order to provide executable content within non-executable
1786 directories.</para>
1787
1788 <para>Non-directory paths may be specified as well. These options may be specified more than once,
1789 in which case all paths listed will have limited access from within the namespace. If the empty string is
1790 assigned to this option, the specific list is reset, and all prior assignments have no effect.</para>
1791
1792 <para>Paths in <varname>ReadWritePaths=</varname>, <varname>ReadOnlyPaths=</varname>,
1793 <varname>InaccessiblePaths=</varname>, <varname>ExecPaths=</varname> and
1794 <varname>NoExecPaths=</varname> may be prefixed with <literal>-</literal>, in which case they will be
1795 ignored when they do not exist. If prefixed with <literal>+</literal> the paths are taken relative to the root
1796 directory of the unit, as configured with <varname>RootDirectory=</varname>/<varname>RootImage=</varname>,
1797 instead of relative to the root directory of the host (see above). When combining <literal>-</literal> and
1798 <literal>+</literal> on the same path make sure to specify <literal>-</literal> first, and <literal>+</literal>
1799 second.</para>
1800
1801 <para>Note that these settings will disconnect propagation of mounts from the unit's processes to the
1802 host. This means that this setting may not be used for services which shall be able to install mount points in
1803 the main mount namespace. For <varname>ReadWritePaths=</varname> and <varname>ReadOnlyPaths=</varname>,
1804 propagation in the other direction is not affected, i.e. mounts created on the host generally appear in the
1805 unit processes' namespace, and mounts removed on the host also disappear there too. In particular, note that
1806 mount propagation from host to unit will result in unmodified mounts to be created in the unit's namespace,
1807 i.e. writable mounts appearing on the host will be writable in the unit's namespace too, even when propagated
1808 below a path marked with <varname>ReadOnlyPaths=</varname>! Restricting access with these options hence does
1809 not extend to submounts of a directory that are created later on. This means the lock-down offered by that
1810 setting is not complete, and does not offer full protection.</para>
1811
1812 <para>Note that the effect of these settings may be undone by privileged processes. In order to set up an
1813 effective sandboxed environment for a unit it is thus recommended to combine these settings with either
1814 <varname>CapabilityBoundingSet=~CAP_SYS_ADMIN</varname> or <varname>SystemCallFilter=~@mount</varname>.</para>
1815
1816 <para>Please be extra careful when applying these options to API file systems (a list of them could be
1817 found in <varname>MountAPIVPS=</varname>), since they may be required for basic system functionalities.
1818 Moreover, <filename>/run/</filename> needs to be writable for setting up mount namespace and propagation.</para>
1819
1820 <para>Simple allow-list example using these directives:
1821 <programlisting>[Service]
1822ReadOnlyPaths=/
1823ReadWritePaths=/var /run
1824InaccessiblePaths=-/lost+found
1825NoExecPaths=/
1826ExecPaths=/usr/sbin/my_daemon /usr/lib /usr/lib64
1827</programlisting></para>
1828
1829 <xi:include href="system-or-user-ns.xml" xpointer="plural"/>
1830
1831 <xi:include href="version-info.xml" xpointer="v231"/></listitem>
1832 </varlistentry>
1833
1834 <varlistentry>
1835 <term><varname>TemporaryFileSystem=</varname></term>
1836
1837 <listitem><para>Takes a space-separated list of mount points for temporary file systems (tmpfs). If set, a new file
1838 system namespace is set up for executed processes, and a temporary file system is mounted on each mount point.
1839 This option may be specified more than once, in which case temporary file systems are mounted on all listed mount
1840 points. If the empty string is assigned to this option, the list is reset, and all prior assignments have no effect.
1841 Each mount point may optionally be suffixed with a colon (<literal>:</literal>) and mount options such as
1842 <literal>size=10%</literal> or <literal>ro</literal>. By default, each temporary file system is mounted
1843 with <literal>nodev,strictatime,mode=0755</literal>. These can be disabled by explicitly specifying the corresponding
1844 mount options, e.g., <literal>dev</literal> or <literal>nostrictatime</literal>.</para>
1845
1846 <para>This is useful to hide files or directories not relevant to the processes invoked by the unit, while necessary
1847 files or directories can be still accessed by combining with <varname>BindPaths=</varname> or
1848 <varname>BindReadOnlyPaths=</varname>:</para>
1849
1850 <para>Example: if a unit has the following,
1851 <programlisting>TemporaryFileSystem=/var:ro
1852BindReadOnlyPaths=/var/lib/systemd</programlisting>
1853 then the invoked processes by the unit cannot see any files or directories under <filename>/var/</filename> except for
1854 <filename>/var/lib/systemd</filename> or its contents.</para>
1855
1856 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
1857
1858 <xi:include href="version-info.xml" xpointer="v238"/></listitem>
1859 </varlistentry>
1860
1861 <varlistentry>
1862 <term><varname>PrivateTmp=</varname></term>
1863
1864 <listitem><para>Takes a boolean argument, or <literal>disconnected</literal>. If enabled, a new
1865 file system namespace will be set up for the executed processes, and <filename>/tmp/</filename>
1866 and <filename>/var/tmp/</filename> directories inside it are not shared with processes outside of
1867 the namespace, plus all temporary files created by a service in these directories will be removed
1868 after the service is stopped. For this setting, the same restrictions regarding mount propagation
1869 and privileges apply as for <varname>ReadOnlyPaths=</varname> and related calls, see above. This
1870 setting is useful to secure access to temporary files of the process, but makes sharing between
1871 processes via <filename>/tmp/</filename> or <filename>/var/tmp/</filename> impossible. If
1872 <varname>DynamicUser=</varname> is enabled, <literal>disconnected</literal> is implied. Otherwise,
1873 defaults to false.</para>
1874
1875 <para>If <literal>true</literal>, the backing storage of the private temporary directories will
1876 remain on the host's <filename>/tmp/</filename> and <filename>/var/tmp/</filename> directories. It is
1877 possible to run two or more units within the same private <filename>/tmp/</filename> and
1878 <filename>/var/tmp/</filename> namespace by using the <varname>JoinsNamespaceOf=</varname> directive,
1879 see <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1880 for details. This has the side effect of adding <varname>Wants=</varname> and
1881 <varname>After=</varname> dependencies on all mount units necessary to access
1882 <filename>/tmp/</filename> and <filename>/var/tmp/</filename> on the host. Moreover, an implicit
1883 <varname>After=</varname> ordering on
1884 <citerefentry><refentrytitle>systemd-tmpfiles-setup.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1885 is added.</para>
1886
1887 <para>If <literal>disconnected</literal>, the directories will be backed by a completely new tmpfs
1888 instance, meaning that the storage is fully disconnected from the host namespace. The tmpfs instance
1889 does not shared with other units even if the <varname>JoinsNamespaceOf=</varname> directive is used.
1890 If <varname>DefaultDependencies=no</varname> is specified,
1891 <varname>RequiresMountsFor=/WantsMountsFor=</varname> for <filename>/var/</filename> is not
1892 specified, and <varname>RootDirectory=/RootImage=</varname> is not specified, then a new tmpfs is
1893 mounted <emphasis>only</emphasis> on <filename>/tmp/</filename>, hence the host's
1894 <filename>/var/tmp</filename> is still accessible from the unit. In that case,
1895 <varname>$TMPDIR</varname> environment variable is set to <literal>/tmp</literal> to suggest the
1896 processes in the unit to use <filename>/tmp/</filename>. This automatically adds
1897 <varname>WantsMountsFor=/var/</varname> dependency, unless <varname>DefaultDependencies=no</varname>
1898 and/or <varname>RootDirectory=/RootImage=</varname> are specified.</para>
1899
1900 <table>
1901 <title>Summary for <varname>PrivateTmp=disconnected</varname></title>
1902 <tgroup cols='4' align='left' colsep='1' rowsep='1'>
1903 <colspec colname="other settings" />
1904 <colspec colname="tmpfs instance on /var/tmp/" />
1905 <colspec colname="$TMPVAR" />
1906 <colspec colname="implied dependencies" />
1907 <thead>
1908 <row>
1909 <entry>Other Settings</entry>
1910 <entry>tmpfs on /var/tmp/</entry>
1911 <entry>$TMPVAR</entry>
1912 <entry>implied dependencies</entry>
1913 </row>
1914 </thead>
1915 <tbody>
1916 <row>
1917 <entry>(none)</entry>
1918 <entry>yes</entry>
1919 <entry>(unset)</entry>
1920 <entry><varname>WantsMountsFor=/var/</varname></entry>
1921 </row>
1922 <row>
1923 <entry><varname>RootDirectory=/RootImage=</varname></entry>
1924 <entry>yes</entry>
1925 <entry>(unset)</entry>
1926 <entry>(none)</entry>
1927 </row>
1928 <row>
1929 <entry><varname>DefaultDependency=no</varname>, <varname>RequiresMountsFor=/var/</varname></entry>
1930 <entry>yes</entry>
1931 <entry>(unset)</entry>
1932 <entry>(none)</entry>
1933 </row>
1934 <row>
1935 <entry><varname>DefaultDependency=no</varname>, <varname>WantsMountsFor=/var/</varname></entry>
1936 <entry>yes</entry>
1937 <entry>(unset)</entry>
1938 <entry>(none)</entry>
1939 </row>
1940 <row>
1941 <entry><varname>DefaultDependency=no</varname></entry>
1942 <entry>no</entry>
1943 <entry><varname>$TMPDIR=/tmp</varname></entry>
1944 <entry>(none)</entry>
1945 </row>
1946 </tbody>
1947 </tgroup>
1948 </table>
1949
1950 <para>Note that the implementation of this setting might be impossible (for example if mount namespaces are not
1951 available), and the unit should be written in a way that does not solely rely on this setting for
1952 security.</para>
1953
1954 <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
1955 </varlistentry>
1956
1957 <varlistentry>
1958 <term><varname>PrivateDevices=</varname></term>
1959
1960 <listitem><para>Takes a boolean argument. If true, sets up a new <filename>/dev/</filename> mount for
1961 the executed processes and only adds API pseudo devices such as <filename>/dev/null</filename>,
1962 <filename>/dev/zero</filename> or <filename>/dev/random</filename> (as well as the pseudo TTY
1963 subsystem) to it, but no physical devices such as <filename>/dev/sda</filename>, system memory
1964 <filename>/dev/mem</filename>, system ports <filename>/dev/port</filename> and others. This is useful
1965 to turn off physical device access by the executed process. Defaults to false.</para>
1966
1967 <para>Enabling this option will install a system call filter to block low-level I/O system calls that
1968 are grouped in the <varname>@raw-io</varname> set, remove <constant>CAP_MKNOD</constant> and
1969 <constant>CAP_SYS_RAWIO</constant> from the capability bounding set for the unit, and set
1970 <varname>DevicePolicy=closed</varname> (see
1971 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1972 for details). Note that using this setting will disconnect propagation of mounts from the service to
1973 the host (propagation in the opposite direction continues to work). This means that this setting may
1974 not be used for services which shall be able to install mount points in the main mount namespace. The
1975 new <filename>/dev/</filename> will be mounted read-only and 'noexec'. The latter may break old
1976 programs which try to set up executable memory by using
1977 <citerefentry><refentrytitle>mmap</refentrytitle><manvolnum>2</manvolnum></citerefentry> of
1978 <filename>/dev/zero</filename> instead of using <constant>MAP_ANON</constant>. For this setting the
1979 same restrictions regarding mount propagation and privileges apply as for
1980 <varname>ReadOnlyPaths=</varname> and related calls, see above.</para>
1981
1982 <para>Note that the implementation of this setting might be impossible (for example if mount
1983 namespaces are not available), and the unit should be written in a way that does not solely rely on
1984 this setting for security.</para>
1985
1986 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
1987
1988 <para>When access to some but not all devices must be possible, the <varname>DeviceAllow=</varname>
1989 setting might be used instead. See
1990 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
1991 </para>
1992
1993 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
1994 </varlistentry>
1995
1996 <varlistentry>
1997 <term><varname>PrivateNetwork=</varname></term>
1998
1999 <listitem><para>Takes a boolean argument. If true, sets up a new network namespace for the executed processes
2000 and configures only the loopback network device <literal>lo</literal> inside it. No other network devices will
2001 be available to the executed process. This is useful to turn off network access by the executed process.
2002 Defaults to false. It is possible to run two or more units within the same private network namespace by using
2003 the <varname>JoinsNamespaceOf=</varname> directive, see
2004 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
2005 details. Note that this option will disconnect all socket families from the host, including
2006 <constant>AF_NETLINK</constant> and <constant>AF_UNIX</constant>. Effectively, for
2007 <constant>AF_NETLINK</constant> this means that device configuration events received from
2008 <citerefentry><refentrytitle>systemd-udevd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> are
2009 not delivered to the unit's processes. And for <constant>AF_UNIX</constant> this has the effect that
2010 <constant>AF_UNIX</constant> sockets in the abstract socket namespace of the host will become unavailable to
2011 the unit's processes (however, those located in the file system will continue to be accessible).</para>
2012
2013 <para>Note that the implementation of this setting might be impossible (for example if network namespaces are
2014 not available), and the unit should be written in a way that does not solely rely on this setting for
2015 security.</para>
2016
2017 <para>When this option is enabled, <varname>PrivateMounts=</varname> is implied unless it is
2018 explicitly disabled, and <filename>/sys</filename> will be remounted to associate it with the new
2019 network namespace.</para>
2020
2021 <para>When this option is used on a socket unit any sockets bound on behalf of this unit will be
2022 bound within a private network namespace. This may be combined with
2023 <varname>JoinsNamespaceOf=</varname> to listen on sockets inside of network namespaces of other
2024 services.</para>
2025
2026 <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
2027 </varlistentry>
2028
2029 <varlistentry>
2030 <term><varname>NetworkNamespacePath=</varname></term>
2031
2032 <listitem><para>Takes an absolute file system path referring to a Linux network namespace
2033 pseudo-file (i.e. a file like <filename>/proc/$PID/ns/net</filename> or a bind mount or symlink to
2034 one). When set the invoked processes are added to the network namespace referenced by that path. The
2035 path has to point to a valid namespace file at the moment the processes are forked off. If this
2036 option is used <varname>PrivateNetwork=</varname> has no effect. If this option is used together with
2037 <varname>JoinsNamespaceOf=</varname> then it only has an effect if this unit is started before any of
2038 the listed units that have <varname>PrivateNetwork=</varname> or
2039 <varname>NetworkNamespacePath=</varname> configured, as otherwise the network namespace of those
2040 units is reused.</para>
2041
2042 <para>When this option is enabled, <varname>PrivateMounts=</varname> is implied unless it is
2043 explicitly disabled, and <filename>/sys</filename> will be remounted to associate it with the new
2044 network namespace.</para>
2045
2046 <para>When this option is used on a socket unit any sockets bound on behalf of this unit will be
2047 bound within the specified network namespace.</para>
2048
2049 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2050
2051 <xi:include href="version-info.xml" xpointer="v242"/></listitem>
2052 </varlistentry>
2053
2054 <varlistentry>
2055 <term><varname>PrivateIPC=</varname></term>
2056
2057 <listitem><para>Takes a boolean argument. If true, sets up a new IPC namespace for the executed processes.
2058 Each IPC namespace has its own set of System V IPC identifiers and its own POSIX message queue file system.
2059 This is useful to avoid name clash of IPC identifiers. Defaults to false. It is possible to run two or
2060 more units within the same private IPC namespace by using the <varname>JoinsNamespaceOf=</varname> directive,
2061 see <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
2062 details.</para>
2063
2064 <para>Note that IPC namespacing does not have an effect on
2065 <constant>AF_UNIX</constant> sockets, which are the most common
2066 form of IPC used on Linux. Instead, <constant>AF_UNIX</constant>
2067 sockets in the file system are subject to mount namespacing, and
2068 those in the abstract namespace are subject to network namespacing.
2069 IPC namespacing only has an effect on SysV IPC (which is mostly
2070 legacy) as well as POSIX message queues (for which
2071 <constant>AF_UNIX</constant>/<constant>SOCK_SEQPACKET</constant>
2072 sockets are typically a better replacement). IPC namespacing also
2073 has no effect on POSIX shared memory (which is subject to mount
2074 namespacing) either. See
2075 <citerefentry project='man-pages'><refentrytitle>ipc_namespaces</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
2076 the details.</para>
2077
2078 <para>Note that the implementation of this setting might be impossible (for example if IPC namespaces are
2079 not available), and the unit should be written in a way that does not solely rely on this setting for
2080 security.</para>
2081
2082 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2083
2084 <xi:include href="version-info.xml" xpointer="v248"/></listitem>
2085 </varlistentry>
2086
2087 <varlistentry>
2088 <term><varname>IPCNamespacePath=</varname></term>
2089
2090 <listitem><para>Takes an absolute file system path referring to a Linux IPC namespace
2091 pseudo-file (i.e. a file like <filename>/proc/$PID/ns/ipc</filename> or a bind mount or symlink to
2092 one). When set the invoked processes are added to the network namespace referenced by that path. The
2093 path has to point to a valid namespace file at the moment the processes are forked off. If this
2094 option is used <varname>PrivateIPC=</varname> has no effect. If this option is used together with
2095 <varname>JoinsNamespaceOf=</varname> then it only has an effect if this unit is started before any of
2096 the listed units that have <varname>PrivateIPC=</varname> or
2097 <varname>IPCNamespacePath=</varname> configured, as otherwise the network namespace of those
2098 units is reused.</para>
2099
2100 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2101
2102 <xi:include href="version-info.xml" xpointer="v248"/></listitem>
2103 </varlistentry>
2104
2105 <varlistentry>
2106 <term><varname>MemoryKSM=</varname></term>
2107
2108 <listitem><para>Takes a boolean argument. When set, it enables KSM (kernel samepage merging) for
2109 the processes. KSM is a memory-saving de-duplication feature. Anonymous memory pages with identical
2110 content can be replaced by a single write-protected page. This feature should only be enabled for
2111 jobs that share the same security domain. For details, see
2112 <ulink url="https://docs.kernel.org/admin-guide/mm/ksm.html">Kernel Samepage Merging</ulink> in the
2113 kernel documentation.</para>
2114
2115 <para>Note that this functionality might not be available, for example if KSM is disabled in the
2116 kernel, or the kernel does not support controlling KSM at the process level through
2117 <citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
2118
2119 <xi:include href="version-info.xml" xpointer="v254"/>
2120 </listitem>
2121 </varlistentry>
2122
2123 <varlistentry>
2124 <term><varname>PrivatePIDs=</varname></term>
2125
2126 <listitem><para>Takes a boolean argument. Defaults to false. If enabled, sets up a new PID namespace
2127 for the executed processes. Each executed process is now PID 1 - the init process - in the new namespace.
2128 <filename>/proc/</filename> is mounted such that only processes in the PID namespace are visible.
2129 If <varname>PrivatePIDs=</varname> is set, <varname>MountAPIVFS=yes</varname> is implied.</para>
2130
2131 <para><varname>PrivatePIDs=</varname> is only supported for service units. This setting is not supported
2132 with <varname>Type=forking</varname> since the kernel will kill all processes in the PID namespace if
2133 the init process terminates.</para>
2134
2135 <para>This setting will be ignored if the kernel does not support PID namespaces.</para>
2136
2137 <para>Note unprivileged user services (i.e. a service run by the per-user instance of the service manager)
2138 will fail with <varname>PrivatePIDs=yes</varname> if <filename>/proc/</filename> is masked
2139 (i.e. <filename>/proc/kmsg</filename> is over-mounted with <constant>tmpfs</constant> like
2140 <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry> does).
2141 This is due to a kernel restriction not allowing unprivileged user namespaces to mount a less restrictive
2142 instance of <filename>/proc/</filename>.</para>
2143
2144 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
2145 </varlistentry>
2146
2147 <varlistentry>
2148 <term><varname>PrivateUsers=</varname></term>
2149
2150 <listitem><para>Takes a boolean argument or one of <literal>self</literal>, <literal>identity</literal>,
2151 or <literal>full</literal>. Defaults to false. If enabled, sets up a new user namespace for the
2152 executed processes and configures a user and group mapping. If set to a true value or
2153 <literal>self</literal>, a minimal user and group mapping is configured that maps the
2154 <literal>root</literal> user and group as well as the unit's own user and group to themselves and
2155 everything else to the <literal>nobody</literal> user and group. This is useful to securely detach
2156 the user and group databases used by the unit from the rest of the system, and thus to create an
2157 effective sandbox environment. All files, directories, processes, IPC objects and other resources
2158 owned by users/groups not equaling <literal>root</literal> or the unit's own will stay visible from
2159 within the unit but appear owned by the <literal>nobody</literal> user and group. </para>
2160
2161 <para>If the parameter is <literal>identity</literal>, user namespacing is set up with an identity
2162 mapping for the first 65536 UIDs/GIDs. Any UIDs/GIDs above 65536 will be mapped to the
2163 <literal>nobody</literal> user and group, respectively. While this does not provide UID/GID isolation,
2164 since all UIDs/GIDs are chosen identically it does provide process capability isolation, and hence is
2165 often a good choice if proper user namespacing with distinct UID maps is not appropriate.</para>
2166
2167 <para>If the parameter is <literal>full</literal>, user namespacing is set up with an identity
2168 mapping for all UIDs/GIDs. In addition, for system services, <literal>full</literal> allows the unit
2169 to call <function>setgroups()</function> system calls (by setting
2170 <filename>/proc/<replaceable>pid</replaceable>/setgroups</filename> to <literal>allow</literal>).
2171 Similar to <literal>identity</literal>, this does not provide UID/GID isolation, but it does provide
2172 process capability isolation.</para>
2173
2174 <para>If this mode is enabled, all unit processes are run without privileges in the host user
2175 namespace (regardless of whether the unit's own user/group is <literal>root</literal> or not). Specifically
2176 this means that the process will have zero process capabilities on the host's user namespace, but
2177 full capabilities within the service's user namespace. Settings such as
2178 <varname>CapabilityBoundingSet=</varname> will affect only the latter, and there's no way to acquire
2179 additional capabilities in the host's user namespace.</para>
2180
2181 <para>When this setting is set up by a per-user instance of the service manager, the mapping of the
2182 <literal>root</literal> user and group to itself is omitted (unless the user manager is root).
2183 Additionally, in the per-user instance manager case, the
2184 user namespace will be set up before most other namespaces. This means that combining
2185 <varname>PrivateUsers=</varname><option>true</option> with other namespaces will enable use of features not
2186 normally supported by the per-user instances of the service manager.</para>
2187
2188 <para>This setting is particularly useful in conjunction with
2189 <varname>RootDirectory=</varname>/<varname>RootImage=</varname>, as the need to synchronize the user and group
2190 databases in the root directory and on the host is reduced, as the only users and groups who need to be matched
2191 are <literal>root</literal>, <literal>nobody</literal> and the unit's own user and group.</para>
2192
2193 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
2194 </varlistentry>
2195
2196 <varlistentry>
2197 <term><varname>ProtectHostname=</varname></term>
2198
2199 <listitem><para>Takes a boolean argument or <literal>private</literal>. If enabled, sets up a new UTS
2200 namespace for the executed processes. If enabled, a hostname can be optionally specified following a
2201 colon (e.g. <literal>yes:foo</literal> or <literal>private:host.example.com</literal>), and the
2202 hostname is set in the new UTS namespace for the unit. If set to a true value, changing hostname or
2203 domainname via <function>sethostname()</function> and <function>setdomainname()</function> system
2204 calls is prevented. If set to <literal>private</literal>, changing hostname or domainname is allowed
2205 but only affects the unit's UTS namespace. Defaults to off.</para>
2206
2207 <para>Note that the implementation of this setting might be impossible (for example if UTS namespaces
2208 are not available), and the unit should be written in a way that does not solely rely on this setting
2209 for security.</para>
2210
2211 <para>Note that when this option is enabled for a service hostname changes no longer propagate from
2212 the system into the service, it is hence not suitable for services that need to take notice of system
2213 hostname changes dynamically.</para>
2214
2215 <para>Note that this option does not prevent changing system hostname via <command>hostnamectl</command>.
2216 However, <varname>User=</varname> and <varname>Group=</varname> may be used to run as an unprivileged user
2217 to disallow changing system hostname. See <function>SetHostname()</function> in
2218 <citerefentry project="man-pages"><refentrytitle>org.freedesktop.hostname1</refentrytitle><manvolnum>5</manvolnum></citerefentry>
2219 for more details.</para>
2220
2221 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2222
2223 <xi:include href="version-info.xml" xpointer="v242"/></listitem>
2224 </varlistentry>
2225
2226 <varlistentry>
2227 <term><varname>ProtectClock=</varname></term>
2228
2229 <listitem><para>Takes a boolean argument. If set, writes to the hardware clock or system clock will
2230 be denied. Defaults to off. Enabling this option removes <constant>CAP_SYS_TIME</constant> and
2231 <constant>CAP_WAKE_ALARM</constant> from the capability bounding set for this unit, installs a system
2232 call filter to block calls that can set the clock, and <varname>DeviceAllow=char-rtc r</varname> is
2233 implied. Note that the system calls are blocked altogether, the filter does not take into account
2234 that some of the calls can be used to read the clock state with some parameter combinations.
2235 Effectively, <filename>/dev/rtc0</filename>, <filename>/dev/rtc1</filename>, etc. are made read-only
2236 to the service. See
2237 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
2238 for the details about <varname>DeviceAllow=</varname>.</para>
2239
2240 <para>It is recommended to turn this on for most services that do not need modify the clock or check
2241 its state.</para>
2242
2243 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2244
2245 <xi:include href="version-info.xml" xpointer="v245"/></listitem>
2246 </varlistentry>
2247
2248 <varlistentry>
2249 <term><varname>ProtectKernelTunables=</varname></term>
2250
2251 <listitem><para>Takes a boolean argument. If true, kernel variables accessible through
2252 <filename>/proc/sys/</filename>, <filename>/sys/</filename>, <filename>/proc/sysrq-trigger</filename>,
2253 <filename>/proc/latency_stats</filename>, <filename>/proc/acpi</filename>,
2254 <filename>/proc/timer_stats</filename>, <filename>/proc/fs</filename> and <filename>/proc/irq</filename> will
2255 be made read-only and <filename>/proc/kallsyms</filename> as well as <filename>/proc/kcore</filename> will be
2256 inaccessible to all processes of the unit.
2257 Usually, tunable kernel variables should be initialized only at boot-time, for example with the
2258 <citerefentry><refentrytitle>sysctl.d</refentrytitle><manvolnum>5</manvolnum></citerefentry> mechanism. Few
2259 services need to write to these at runtime; it is hence recommended to turn this on for most services. For this
2260 setting the same restrictions regarding mount propagation and privileges apply as for
2261 <varname>ReadOnlyPaths=</varname> and related calls, see above. Defaults to off.
2262 Note that this option does not prevent indirect changes to kernel tunables affected by IPC calls to
2263 other processes. However, <varname>InaccessiblePaths=</varname> may be used to make relevant IPC file system
2264 objects inaccessible. If <varname>ProtectKernelTunables=</varname> is set,
2265 <varname>MountAPIVFS=yes</varname> is implied.</para>
2266
2267 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2268
2269 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
2270 </varlistentry>
2271
2272 <varlistentry>
2273 <term><varname>ProtectKernelModules=</varname></term>
2274
2275 <listitem><para>Takes a boolean argument. If true, explicit module loading will be denied. This allows
2276 module load and unload operations to be turned off on modular kernels. It is recommended to turn this on for most services
2277 that do not need special file systems or extra kernel modules to work. Defaults to off. Enabling this option
2278 removes <constant>CAP_SYS_MODULE</constant> from the capability bounding set for the unit, and installs a
2279 system call filter to block module system calls, also <filename>/usr/lib/modules</filename> is made
2280 inaccessible. For this setting the same restrictions regarding mount propagation and privileges apply as for
2281 <varname>ReadOnlyPaths=</varname> and related calls, see above. Note that limited automatic module loading due
2282 to user configuration or kernel mapping tables might still happen as side effect of requested user operations,
2283 both privileged and unprivileged. To disable module auto-load feature please see
2284 <citerefentry><refentrytitle>sysctl.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>
2285 <constant>kernel.modules_disabled</constant> mechanism and
2286 <filename>/proc/sys/kernel/modules_disabled</filename> documentation.</para>
2287
2288 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2289
2290 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
2291 </varlistentry>
2292
2293 <varlistentry>
2294 <term><varname>ProtectKernelLogs=</varname></term>
2295
2296 <listitem><para>Takes a boolean argument. If true, access to the kernel log ring buffer will be denied. It is
2297 recommended to turn this on for most services that do not need to read from or write to the kernel log ring
2298 buffer. Enabling this option removes <constant>CAP_SYSLOG</constant> from the capability bounding set for this
2299 unit, and installs a system call filter to block the
2300 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>2</manvolnum></citerefentry>
2301 system call (not to be confused with the libc API
2302 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
2303 for userspace logging). The kernel exposes its log buffer to userspace via <filename>/dev/kmsg</filename> and
2304 <filename>/proc/kmsg</filename>. If enabled, these are made inaccessible to all the processes in the unit.
2305 </para>
2306
2307 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2308
2309 <xi:include href="version-info.xml" xpointer="v244"/></listitem>
2310 </varlistentry>
2311
2312 <varlistentry>
2313 <term><varname>ProtectControlGroups=</varname></term>
2314
2315 <listitem><para>Takes a boolean argument or the special values <literal>private</literal> or
2316 <literal>strict</literal>. If true, the Linux Control Groups (<citerefentry project='man-pages'>
2317 <refentrytitle>cgroups</refentrytitle><manvolnum>7</manvolnum></citerefentry>) hierarchies
2318 accessible through <filename>/sys/fs/cgroup/</filename> will be made read-only to all processes of the
2319 unit. If set to <literal>private</literal>, the unit will run in a cgroup namespace with a private
2320 writable mount of <filename>/sys/fs/cgroup/</filename>. If set to <literal>strict</literal>, the unit
2321 will run in a cgroup namespace with a private read-only mount of <filename>/sys/fs/cgroup/</filename>.
2322 Defaults to off. If <varname>ProtectControlGroups=</varname> is set, <varname>MountAPIVFS=yes</varname>
2323 is implied. Note <literal>private</literal> and <literal>strict</literal> are downgraded to false and
2324 true respectively unless the system is using the unified control group hierarchy and the kernel supports
2325 cgroup namespaces.</para>
2326
2327 <para>Except for container managers no services should require write access to the control groups hierarchies;
2328 it is hence recommended to set <varname>ProtectControlGroups=</varname> to true or <literal>strict</literal>
2329 for most services. For this setting the same restrictions regarding mount propagation and privileges apply
2330 as for <varname>ReadOnlyPaths=</varname> and related settings, see above.</para>
2331
2332 <xi:include href="system-only.xml" xpointer="singular"/>
2333
2334 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
2335 </varlistentry>
2336
2337 <varlistentry>
2338 <term><varname>RestrictAddressFamilies=</varname></term>
2339
2340 <listitem><para>Restricts the set of socket address families accessible to the processes of this
2341 unit. Takes <literal>none</literal>, or a space-separated list of address family names to
2342 allow-list, such as <constant>AF_UNIX</constant>, <constant>AF_INET</constant> or
2343 <constant>AF_INET6</constant>, see
2344 <citerefentry project='man-pages'><refentrytitle>address_families</refentrytitle><manvolnum>7</manvolnum></citerefentry>
2345 for all possible options. When <literal>none</literal> is specified, then all address
2346 families will be denied. When prefixed with <literal>~</literal> the listed address
2347 families will be applied as deny list, otherwise as allow list.</para>
2348
2349 <para>By default, no restrictions apply, all address families are accessible to processes. If
2350 assigned the empty string, any previous address family restriction changes are undone. This setting
2351 does not affect commands prefixed with <literal>+</literal>.</para>
2352
2353 <para>Use this option to limit exposure of processes to remote access, in particular via exotic and
2354 sensitive network protocols, such as <constant>AF_PACKET</constant>. Note that in most cases, the
2355 local <constant>AF_UNIX</constant> address family should be included in the configured allow list as
2356 it is frequently used for local communication, including for
2357 <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>2</manvolnum></citerefentry>
2358 logging.</para>
2359
2360 <para>Note that this restricts access to the <citerefentry
2361 project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>2</manvolnum></citerefentry>
2362 system call only. Sockets passed into the process by other means (for example, by using socket
2363 activation with socket units, see
2364 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>)
2365 are unaffected. Also, sockets created with <function>socketpair()</function> (which creates connected
2366 AF_UNIX sockets) or the
2367 <citerefentry project='man-pages'><refentrytitle>io_uring</refentrytitle><manvolnum>7</manvolnum></citerefentry>
2368 functions, are not affected. Thus, it is recommended to combined this setting with
2369 <varname>SystemCallFilter=@service</varname>, to only allow a limited subset of system calls.</para>
2370
2371 <para>Note that this option is limited to some ABIs, in particular x86-64, but currently has no
2372 effect on 32-bit x86, s390, s390x, mips, mips-le, ppc, ppc-le, ppc64, or ppc64-le, and is ignored. On
2373 systems supporting multiple ABIs (such as x86/x86-64) it is recommended to turn off alternative ABIs
2374 for services, so that they cannot be used to circumvent the restrictions of this option.
2375 Specifically, it is recommended to combine this option with
2376 <varname>SystemCallArchitectures=native</varname> or similar. </para>
2377
2378 <xi:include href="version-info.xml" xpointer="v211"/></listitem>
2379 </varlistentry>
2380
2381 <varlistentry>
2382 <term><varname>RestrictFileSystems=</varname></term>
2383
2384 <listitem><para>Restricts the set of filesystems processes of this unit can open files on. Takes a space-separated
2385 list of filesystem names. Any filesystem listed is made accessible to the unit's processes, access to filesystem
2386 types not listed is prohibited (allow-listing). If the first character of the list is <literal>~</literal>, the
2387 effect is inverted: access to the filesystems listed is prohibited (deny-listing). If the empty string is assigned,
2388 access to filesystems is not restricted.</para>
2389
2390 <para>If you specify both types of this option (i.e. allow-listing and deny-listing), the first encountered will take
2391 precedence and will dictate the default action (allow access to the filesystem or deny it). Then the next occurrences
2392 of this option will add or delete the listed filesystems from the set of the restricted filesystems, depending on its
2393 type and the default action.</para>
2394
2395 <para>Example: if a unit has the following,
2396 <programlisting>RestrictFileSystems=ext4 tmpfs
2397RestrictFileSystems=ext2 ext4</programlisting>
2398 then access to <constant>ext4</constant>, <constant>tmpfs</constant>, and <constant>ext2</constant> is allowed
2399 and access to other filesystems is denied.</para>
2400
2401 <para>Example: if a unit has the following,
2402 <programlisting>RestrictFileSystems=ext4 tmpfs
2403RestrictFileSystems=~ext4</programlisting>
2404 then only access <constant>tmpfs</constant> is allowed.</para>
2405
2406 <para>Example: if a unit has the following,
2407 <programlisting>RestrictFileSystems=~ext4 tmpfs
2408RestrictFileSystems=ext4</programlisting>
2409 then only access to <constant>tmpfs</constant> is denied.</para>
2410
2411 <para>As the number of possible filesystems is large, predefined sets of filesystems are provided. A set
2412 starts with <literal>@</literal> character, followed by name of the set.</para>
2413
2414 <table>
2415 <title>Currently predefined filesystem sets</title>
2416
2417 <tgroup cols='2'>
2418 <colspec colname='set' />
2419 <colspec colname='description' />
2420 <thead>
2421 <row>
2422 <entry>Set</entry>
2423 <entry>Description</entry>
2424 </row>
2425 </thead>
2426 <tbody>
2427 <row>
2428 <entry>@basic-api</entry>
2429 <entry>Basic filesystem API.</entry>
2430 </row>
2431 <row>
2432 <entry>@auxiliary-api</entry>
2433 <entry>Auxiliary filesystem API.</entry>
2434 </row>
2435 <row>
2436 <entry>@common-block</entry>
2437 <entry>Common block device filesystems.</entry>
2438 </row>
2439 <row>
2440 <entry>@historical-block</entry>
2441 <entry>Historical block device filesystems.</entry>
2442 </row>
2443 <row>
2444 <entry>@network</entry>
2445 <entry>Well-known network filesystems.</entry>
2446 </row>
2447 <row>
2448 <entry>@privileged-api</entry>
2449 <entry>Privileged filesystem API.</entry>
2450 </row>
2451 <row>
2452 <entry>@temporary</entry>
2453 <entry>Temporary filesystems: tmpfs, ramfs.</entry>
2454 </row>
2455 <row>
2456 <entry>@known</entry>
2457 <entry>All known filesystems defined by the kernel. This list is defined statically in systemd based on a kernel version that was available when this systemd version was released. It will become progressively more out-of-date as the kernel is updated.</entry>
2458 </row>
2459 </tbody>
2460 </tgroup>
2461 </table>
2462
2463 <para>Use
2464 <citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
2465 <command>filesystems</command> command to retrieve a list of filesystems defined on the local
2466 system.</para>
2467
2468 <para>Note that this setting might not be supported on some systems (for example if the LSM eBPF hook is
2469 not enabled in the underlying kernel or if not using the unified control group hierarchy). In that case this setting
2470 has no effect.</para>
2471
2472 <xi:include href="cgroup-sandboxing.xml" xpointer="singular"/>
2473
2474 <xi:include href="version-info.xml" xpointer="v250"/></listitem>
2475 </varlistentry>
2476
2477 <varlistentry>
2478 <term><varname>RestrictNamespaces=</varname></term>
2479
2480 <listitem><para>Restricts access to Linux namespace functionality for the processes of this unit. For details
2481 about Linux namespaces, see <citerefentry
2482 project='man-pages'><refentrytitle>namespaces</refentrytitle><manvolnum>7</manvolnum></citerefentry>. Either
2483 takes a boolean argument, or a space-separated list of namespace type identifiers. If false (the default), no
2484 restrictions on namespace creation and switching are made. If true, access to any kind of namespacing is
2485 prohibited. Otherwise, a space-separated list of namespace type identifiers must be specified, consisting of
2486 any combination of: <constant>cgroup</constant>, <constant>ipc</constant>, <constant>net</constant>,
2487 <constant>mnt</constant>, <constant>pid</constant>, <constant>user</constant>, <constant>uts</constant>, and
2488 <constant>time</constant>. Any namespace type listed is made accessible to the unit's processes, access to
2489 namespace types not listed is prohibited (allow-listing). By prepending the list with a single tilde
2490 character (<literal>~</literal>) the effect may be inverted: only the listed namespace types will be made
2491 inaccessible, all unlisted ones are permitted (deny-listing). If the empty string is assigned, the default
2492 namespace restrictions are applied, which is equivalent to false. This option may appear more than once, in
2493 which case the namespace types are merged by <constant>OR</constant>, or by <constant>AND</constant> if the
2494 lines are prefixed with <literal>~</literal> (see examples below). Internally, this setting limits access to
2495 the <citerefentry><refentrytitle>unshare</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
2496 <citerefentry><refentrytitle>clone</refentrytitle><manvolnum>2</manvolnum></citerefentry> and
2497 <citerefentry><refentrytitle>setns</refentrytitle><manvolnum>2</manvolnum></citerefentry> system calls, taking
2498 the specified flags parameters into account. Note that — if this option is used — in addition to restricting
2499 creation and switching of the specified types of namespaces (or all of them, if true) access to the
2500 <function>setns()</function> system call with a zero flags parameter is prohibited. This setting is only
2501 supported on x86, x86-64, mips, mips-le, mips64, mips64-le, mips64-n32, mips64-le-n32, ppc64, ppc64-le, s390
2502 and s390x, and enforces no restrictions on other architectures.</para>
2503
2504 <para>Example: if a unit has the following,
2505 <programlisting>RestrictNamespaces=cgroup ipc
2506RestrictNamespaces=cgroup net</programlisting>
2507 then <constant>cgroup</constant>, <constant>ipc</constant>, and <constant>net</constant> are set.
2508 If the second line is prefixed with <literal>~</literal>, e.g.,
2509 <programlisting>RestrictNamespaces=cgroup ipc
2510RestrictNamespaces=~cgroup net</programlisting>
2511 then, only <constant>ipc</constant> is set.</para>
2512
2513 <xi:include href="version-info.xml" xpointer="v233"/></listitem>
2514 </varlistentry>
2515
2516 <varlistentry>
2517 <term><varname>DelegateNamespaces=</varname></term>
2518
2519 <listitem><para>Delegates ownership of the given namespace types to the user namespace of the
2520 processes of this unit. For details about Linux namespaces, see <citerefentry
2521 project='man-pages'><refentrytitle>namespaces</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
2522 Either takes a boolean argument, or a space-separated list of namespace type identifiers. If false
2523 (the default), the unit's processes' user namespace will not have ownership over any namespaces
2524 created during setup of the unit's sandboxed environment. If true, ownership of all namespace types
2525 (except for user namespaces, where the concept doesn't apply) created during setup of the unit's
2526 sandboxed environment is delegated to the unit's processes' user namespace. Otherwise, a
2527 space-separated list of namespace type identifiers must be specified, consisting of any combination
2528 of: <constant>cgroup</constant>, <constant>ipc</constant>, <constant>net</constant>,
2529 <constant>mnt</constant>, <constant>pid</constant>, and <constant>uts</constant>. All namespaces of
2530 the listed types will be owned by the unit's processes' user namespace if they are created during
2531 setup of the unit's sandboxed environment (allow-listing). By prepending the list with a single tilde
2532 character (<literal>~</literal>) the effect may be inverted: all namespaces of types not listed and
2533 created during setup of the unit's sandboxed environment will be owned by the unit's processes' user
2534 namespace (deny-listing). If the empty string is assigned, the default namespace ownership is
2535 applied, which is equivalent to false. This option may appear more than once, in which case the
2536 namespace types are merged by <constant>OR</constant>, or by <constant>AND</constant> if the lines
2537 are prefixed with <literal>~</literal> (see examples below). Internally, this setting controls the
2538 order in which namespaces are unshared by systemd. Namespace types that should be owned by the unit's
2539 processes' user namespace will be unshared after unsharing the user namespace. Internally, this
2540 setting controls the order in which namespaces are unshared. Delegated namespaces will be unshared
2541 after the user namespace is unshared. Other namespaces will be unshared before the user namespace is
2542 unshared.</para>
2543
2544 <para>Delegating any namespace with <varname>DelegateNamespaces=</varname> implies
2545 <varname>PrivateUsers=self</varname> unless <varname>PrivateUsers=</varname> is explicitly enabled
2546 already by the unit. Delegating a namespace does not imply that the namespace is unshared, that is
2547 done with the namespace specific unit setting such as <varname>PrivateNetwork=</varname> or
2548 <varname>PrivateMounts=</varname>.</para>
2549
2550 <para>Note that some namespace sandboxing options might entail mount namespace for private API VFS instances,
2551 such as <varname>PrivatePIDs=</varname>, <varname>ProtectControlGroups=private/strict</varname>, or
2552 <varname>PrivateNetwork=</varname>. If any of the mentioned options are enabled, mount namespace
2553 is implicitly delegated.</para>
2554
2555 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
2556 </varlistentry>
2557
2558 <varlistentry>
2559 <term><varname>PrivateBPF=</varname></term>
2560
2561 <listitem><para>Takes a boolean argument. If set, mount a private instance of the BPF filesystem
2562 on <filename>/sys/fs/bpf/</filename>, effectively hiding the host bpffs which contains information
2563 about loaded programs and maps. Otherwise, if <varname>ProtectKernelTunables=</varname> is set, the
2564 instance from the host is inherited but mounted read-only. Defaults to false.</para>
2565
2566 <para>This can be used together with the bpffs delegate feature to choose what BPF functions are
2567 available to the unit's processes. When mounting the BPF filesystem with the fsopen() API, four mount
2568 options can be specified to set a list of BPF commands, maps, programs and attachment types that are
2569 allowed to be used. Processes needs to get a file descriptor for the bpffs mountpoint and use that to
2570 get a token which will enable for that user namespace the BPF functionalities chosen upon bpffs mount.
2571 A more detailed explanation of the feature can be found in this
2572 <ulink url="https://lwn.net/Articles/947173/">LWN post</ulink>.</para>
2573
2574
2575 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
2576 </varlistentry>
2577
2578 <varlistentry>
2579 <term><varname>BPFDelegateCommands=</varname></term>
2580
2581 <listitem><para>Accepts a list of BPF commands to allow or <literal>any</literal> to allow everything.
2582 Defaults to none. The accepted values are:
2583 <xi:include href="bpf-delegate.xml" xpointer="bpf_delegate_cmd"/>
2584 This will set the <constant>delegate_cmds</constant> bpffs mount option.</para>
2585
2586 <para>Requires <varname>PrivateBPF=yes</varname> to be effective,
2587 see <varname>PrivateBPF=</varname> more details.</para>
2588
2589 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
2590 </varlistentry>
2591
2592 <varlistentry>
2593 <term><varname>BPFDelegateMaps=</varname></term>
2594
2595 <listitem><para>Accepts a list of BPF maps to allow or <literal>any</literal> to allow everything.
2596 Defaults to none. The accepted values are:
2597 <xi:include href="bpf-delegate.xml" xpointer="bpf_delegate_map_type"/>
2598 This will set the <constant>delegate_maps</constant> bpffs mount option.</para>
2599
2600 <para>Requires <varname>PrivateBPF=yes</varname> to be effective,
2601 see <varname>PrivateBPF=</varname> more details.</para>
2602
2603 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
2604 </varlistentry>
2605
2606 <varlistentry>
2607 <term><varname>BPFDelegatePrograms=</varname></term>
2608
2609 <listitem><para>Accepts a list of BPF programs to allow or <literal>any</literal> to allow everything.
2610 Defaults to none. The accepted values are:
2611 <xi:include href="bpf-delegate.xml" xpointer="bpf_delegate_prog_type"/>
2612 This will set the <constant>delegate_progs</constant> bpffs mount option.</para>
2613
2614 <para>Requires <varname>PrivateBPF=yes</varname> to be effective,
2615 see <varname>PrivateBPF=</varname> more details.</para>
2616
2617 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
2618 </varlistentry>
2619
2620 <varlistentry>
2621 <term><varname>BPFDelegateAttachments=</varname></term>
2622
2623 <listitem><para>Accepts a list of BPF attach points to allow or <literal>any</literal> to allow everything.
2624 Defaults to none. The accepted values are:
2625 <xi:include href="bpf-delegate.xml" xpointer="bpf_delegate_attach_type"/>
2626 This will set the <constant>delegate_attachs</constant> bpffs mount option.</para>
2627
2628 <para>Requires <varname>PrivateBPF=yes</varname> to be effective,
2629 see <varname>PrivateBPF=</varname> more details.</para>
2630
2631 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
2632 </varlistentry>
2633
2634 <varlistentry>
2635 <term><varname>LockPersonality=</varname></term>
2636
2637 <listitem><para>Takes a boolean argument. If set, locks down the <citerefentry
2638 project='man-pages'><refentrytitle>personality</refentrytitle><manvolnum>2</manvolnum></citerefentry> system
2639 call so that the kernel execution domain may not be changed from the default or the personality selected with
2640 <varname>Personality=</varname> directive. This may be useful to improve security, because odd personality
2641 emulations may be poorly tested and source of vulnerabilities.</para>
2642
2643 <xi:include href="version-info.xml" xpointer="v235"/></listitem>
2644 </varlistentry>
2645
2646 <varlistentry>
2647 <term><varname>MemoryDenyWriteExecute=</varname></term>
2648
2649 <listitem><para>Takes a boolean argument. If set, attempts to create memory mappings that are writable and
2650 executable at the same time, or to change existing memory mappings to become executable, or mapping shared
2651 memory segments as executable, are prohibited. Specifically, a system call filter is added (or
2652 preferably, an equivalent kernel check is enabled with
2653 <citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>) that
2654 rejects <citerefentry><refentrytitle>mmap</refentrytitle><manvolnum>2</manvolnum></citerefentry>
2655 system calls with both <constant>PROT_EXEC</constant> and <constant>PROT_WRITE</constant> set,
2656 <citerefentry><refentrytitle>mprotect</refentrytitle><manvolnum>2</manvolnum></citerefentry> or
2657 <citerefentry><refentrytitle>pkey_mprotect</refentrytitle><manvolnum>2</manvolnum></citerefentry> system calls
2658 with <constant>PROT_EXEC</constant> set and
2659 <citerefentry><refentrytitle>shmat</refentrytitle><manvolnum>2</manvolnum></citerefentry> system calls with
2660 <constant>SHM_EXEC</constant> set. Note that this option is incompatible with programs and libraries that
2661 generate program code dynamically at runtime, including JIT execution engines, executable stacks, and code
2662 "trampoline" feature of various C compilers. This option improves service security, as it makes harder for
2663 software exploits to change running code dynamically. However, the protection can be circumvented, if
2664 the service can write to a filesystem, which is not mounted with <constant>noexec</constant> (such as
2665 <filename>/dev/shm</filename>), or it can use <function>memfd_create()</function>. This can be
2666 prevented by making such file systems inaccessible to the service
2667 (e.g. <varname>InaccessiblePaths=/dev/shm</varname>) and installing further system call filters
2668 (<varname>SystemCallFilter=~memfd_create</varname>). Note that this feature is fully available on
2669 x86-64, and partially on x86. Specifically, the <function>shmat()</function> protection is not
2670 available on x86. Note that on systems supporting multiple ABIs (such as x86/x86-64) it is
2671 recommended to turn off alternative ABIs for services, so that they cannot be used to circumvent the
2672 restrictions of this option. Specifically, it is recommended to combine this option with
2673 <varname>SystemCallArchitectures=native</varname> or similar.</para>
2674
2675 <xi:include href="version-info.xml" xpointer="v231"/></listitem>
2676 </varlistentry>
2677
2678 <varlistentry>
2679 <term><varname>RestrictRealtime=</varname></term>
2680
2681 <listitem><para>Takes a boolean argument. If set, any attempts to enable realtime scheduling in a process of
2682 the unit are refused. This restricts access to realtime task scheduling policies such as
2683 <constant>SCHED_FIFO</constant>, <constant>SCHED_RR</constant> or <constant>SCHED_DEADLINE</constant>. See
2684 <citerefentry project='man-pages'><refentrytitle>sched</refentrytitle><manvolnum>7</manvolnum></citerefentry>
2685 for details about these scheduling policies. Realtime scheduling policies may be used to monopolize CPU
2686 time for longer periods of time, and may hence be used to lock up or otherwise trigger Denial-of-Service
2687 situations on the system. It is hence recommended to restrict access to realtime scheduling to the few programs
2688 that actually require them. Defaults to off.</para>
2689
2690 <xi:include href="version-info.xml" xpointer="v231"/></listitem>
2691 </varlistentry>
2692
2693 <varlistentry>
2694 <term><varname>RestrictSUIDSGID=</varname></term>
2695
2696 <listitem><para>Takes a boolean argument. If set, any attempts to set the set-user-ID (SUID) or
2697 set-group-ID (SGID) bits on files or directories will be denied (for details on these bits see
2698 <citerefentry
2699 project='man-pages'><refentrytitle>inode</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
2700 As the SUID/SGID bits are mechanisms to elevate privileges, and allow users to acquire the
2701 identity of other users, it is recommended to restrict creation of SUID/SGID files to the few
2702 programs that actually require them. Note that this restricts marking of any type of file system
2703 object with these bits, including both regular files and directories (where the SGID is a different
2704 meaning than for files, see documentation). This option is implied if <varname>DynamicUser=</varname>
2705 is enabled.</para>
2706
2707 <para>In other cases, this setting defaults to the value set with <varname>DefaultRestrictSUIDSGID=</varname> in
2708 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, which
2709 defaults to off.</para>
2710
2711 <xi:include href="version-info.xml" xpointer="v242"/></listitem>
2712 </varlistentry>
2713
2714 <varlistentry>
2715 <term><varname>RemoveIPC=</varname></term>
2716
2717 <listitem><para>Takes a boolean parameter. If set, all System V and POSIX IPC objects owned by the user and
2718 group the processes of this unit are run as are removed when the unit is stopped. This setting only has an
2719 effect if at least one of <varname>User=</varname>, <varname>Group=</varname> and
2720 <varname>DynamicUser=</varname> are used. It has no effect on IPC objects owned by the root user. Specifically,
2721 this removes System V semaphores, as well as System V and POSIX shared memory segments and message queues. If
2722 multiple units use the same user or group the IPC objects are removed when the last of these units is
2723 stopped. This setting is implied if <varname>DynamicUser=</varname> is set.</para>
2724
2725 <xi:include href="system-only.xml" xpointer="singular"/>
2726
2727 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
2728 </varlistentry>
2729
2730 <varlistentry>
2731 <term><varname>PrivateMounts=</varname></term>
2732
2733 <listitem><para>Takes a boolean parameter. If set, the processes of this unit will be run in their own private
2734 file system (mount) namespace with all mount propagation from the processes towards the host's main file system
2735 namespace turned off. This means any file system mount points established or removed by the unit's processes
2736 will be private to them and not be visible to the host. However, file system mount points established or
2737 removed on the host will be propagated to the unit's processes. See <citerefentry
2738 project='man-pages'><refentrytitle>mount_namespaces</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
2739 details on file system namespaces. Defaults to off.</para>
2740
2741 <para>When turned on, this executes three operations for each invoked process: a new
2742 <constant>CLONE_NEWNS</constant> namespace is created, after which all existing mounts are remounted to
2743 <constant>MS_SLAVE</constant> to disable propagation from the unit's processes to the host (but leaving
2744 propagation in the opposite direction in effect). Finally, the mounts are remounted again to the propagation
2745 mode configured with <varname>MountFlags=</varname>, see below.</para>
2746
2747 <para>File system namespaces are set up individually for each process forked off by the service manager. Mounts
2748 established in the namespace of the process created by <varname>ExecStartPre=</varname> will hence be cleaned
2749 up automatically as soon as that process exits and will not be available to subsequent processes forked off for
2750 <varname>ExecStart=</varname> (and similar applies to the various other commands configured for
2751 units). Similarly, <varname>JoinsNamespaceOf=</varname> does not permit sharing kernel mount namespaces between
2752 units, it only enables sharing of the <filename>/tmp/</filename> and <filename>/var/tmp/</filename>
2753 directories.</para>
2754
2755 <para>Other file system namespace unit settings — <varname>PrivateTmp=</varname>,
2756 <varname>PrivateDevices=</varname>, <varname>ProtectSystem=</varname>,
2757 <varname>ProtectHome=</varname>, <varname>ReadOnlyPaths=</varname>,
2758 <varname>InaccessiblePaths=</varname>, <varname>ReadWritePaths=</varname>,
2759 <varname>BindPaths=</varname>, <varname>BindReadOnlyPaths=</varname>, … — also enable file system
2760 namespacing in a fashion equivalent to this option. Hence it is primarily useful to explicitly
2761 request this behaviour if none of the other settings are used.</para>
2762
2763 <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
2764
2765 <xi:include href="version-info.xml" xpointer="v239"/></listitem>
2766 </varlistentry>
2767
2768 <varlistentry>
2769 <term><varname>MountFlags=</varname></term>
2770
2771 <listitem><para>Takes a mount propagation setting: <option>shared</option>, <option>slave</option> or
2772 <option>private</option>, which controls whether file system mount points in the file system namespaces set up
2773 for this unit's processes will receive or propagate mounts and unmounts from other file system namespaces. See
2774 <citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>2</manvolnum></citerefentry>
2775 for details on mount propagation, and the three propagation flags in particular.</para>
2776
2777 <para>This setting only controls the <emphasis>final</emphasis> propagation setting in effect on all mount
2778 points of the file system namespace created for each process of this unit. Other file system namespacing unit
2779 settings (see the discussion in <varname>PrivateMounts=</varname> above) will implicitly disable mount and
2780 unmount propagation from the unit's processes towards the host by changing the propagation setting of all mount
2781 points in the unit's file system namespace to <option>slave</option> first. Setting this option to
2782 <option>shared</option> does not reestablish propagation in that case.</para>
2783
2784 <para>If not set – but file system namespaces are enabled through another file system namespace unit setting –
2785 <option>shared</option> mount propagation is used, but — as mentioned — as <option>slave</option> is applied
2786 first, propagation from the unit's processes to the host is still turned off.</para>
2787
2788 <para>It is not recommended to use <option>private</option> mount propagation for units, as this means
2789 temporary mounts (such as removable media) of the host will stay mounted and thus indefinitely busy in forked
2790 off processes, as unmount propagation events will not be received by the file system namespace of the unit.</para>
2791
2792 <para>Usually, it is best to leave this setting unmodified, and use higher level file system namespacing
2793 options instead, in particular <varname>PrivateMounts=</varname>, see above.</para>
2794
2795 <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
2796 </varlistentry>
2797
2798 </variablelist>
2799 </refsect1>
2800
2801 <refsect1>
2802 <title>System Call Filtering</title>
2803 <variablelist class='unit-directives'>
2804
2805 <varlistentry>
2806 <term><varname>SystemCallFilter=</varname></term>
2807
2808 <listitem><para>Takes a space-separated list of system call names or system call groups. If this
2809 setting is used, system calls executed by the unit processes except for the listed ones will result
2810 in the system call being denied (allow-listing). If the first character of the list is
2811 <literal>~</literal>, the effect is inverted: only the listed system calls will be denied
2812 (deny-listing). This option may be specified more than once, in which case the filter masks are
2813 merged. If the empty string is assigned, the filter is reset, all prior assignments will have no
2814 effect.</para>
2815
2816 <para>Commands prefixed with <literal>+</literal> are not subject to filtering. The
2817 <function>execve()</function>, <function>exit()</function>, <function>exit_group()</function>,
2818 <function>getrlimit()</function>, <function>rt_sigreturn()</function>,
2819 <function>sigreturn()</function> system calls and the system calls for querying time and sleeping are
2820 implicitly allow-listed and do not need to be listed explicitly.</para>
2821
2822 <para>The default action when a system call is denied is to terminate the processes with a
2823 <constant>SIGSYS</constant> signal. This can changed using <varname>SystemCallErrorNumber=</varname>,
2824 see below. In addition, deny-listed system calls and system call groups may optionally be suffixed
2825 with a colon (<literal>:</literal>) and an argument in the same format as
2826 <varname>SystemCallErrorNumber=</varname>, to take this action when the matching system call is made.
2827 This takes precedence over the action specified in <varname>SystemCallErrorNumber=</varname>.</para>
2828
2829 <para>This feature makes use of the Secure Computing Mode 2 interfaces of the kernel ('seccomp
2830 filtering') and is useful for enforcing a minimal sandboxing environment.</para>
2831
2832 <para>Note that on systems supporting multiple ABIs (such as x86/x86-64) it is recommended to turn
2833 off alternative ABIs for services, so that they cannot be used to circumvent the restrictions of this
2834 option. Specifically, it is recommended to combine this option with
2835 <varname>SystemCallArchitectures=native</varname> or similar.</para>
2836
2837 <para>Note that strict system call filters may impact execution and error handling code paths of the
2838 service invocation. Specifically, access to the <function>execve()</function> system call is required
2839 for the execution of the service binary — if it is blocked service invocation will necessarily fail.
2840 Also, if execution of the service binary fails for some reason (for example: missing service
2841 executable), the error handling logic might require access to an additional set of system calls in
2842 order to process and log this failure correctly. It might be necessary to temporarily disable system
2843 call filters in order to allow debugging of such failures.</para>
2844
2845 <para>If you specify both types of this option (i.e. allow-listing and deny-listing), the first
2846 encountered will take precedence and will dictate the default action (termination or approval of a
2847 system call). Then the next occurrences of this option will add or delete the listed system calls
2848 from the set of the filtered system calls, depending of its type and the default action. (For
2849 example, if you have started with an allow list rule for <function>read()</function> and
2850 <function>write()</function>, and right after it add a deny list rule for <function>write()</function>,
2851 then <function>write()</function> will be removed from the set.)</para>
2852
2853 <para>As the number of possible system calls is large, predefined groups of system calls are
2854 provided. A group starts with <literal>@</literal> character, followed by name of the set.
2855
2856 <table>
2857 <title>Currently predefined system call sets</title>
2858
2859 <tgroup cols='2'>
2860 <colspec colname='set' />
2861 <colspec colname='description' />
2862 <thead>
2863 <row>
2864 <entry>Set</entry>
2865 <entry>Description</entry>
2866 </row>
2867 </thead>
2868 <tbody>
2869 <row>
2870 <entry>@aio</entry>
2871 <entry>Asynchronous I/O (<citerefentry project='man-pages'><refentrytitle>io_setup</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>io_submit</refentrytitle><manvolnum>2</manvolnum></citerefentry>, and related calls)</entry>
2872 </row>
2873 <row>
2874 <entry>@basic-io</entry>
2875 <entry>System calls for basic I/O: reading, writing, seeking, file descriptor duplication and closing (<citerefentry project='man-pages'><refentrytitle>read</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>write</refentrytitle><manvolnum>2</manvolnum></citerefentry>, and related calls)</entry>
2876 </row>
2877 <row>
2878 <entry>@chown</entry>
2879 <entry>Changing file ownership (<citerefentry project='man-pages'><refentrytitle>chown</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>fchownat</refentrytitle><manvolnum>2</manvolnum></citerefentry>, and related calls)</entry>
2880 </row>
2881 <row>
2882 <entry>@clock</entry>
2883 <entry>System calls for changing the system clock (<citerefentry project='man-pages'><refentrytitle>adjtimex</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>settimeofday</refentrytitle><manvolnum>2</manvolnum></citerefentry>, and related calls)</entry>
2884 </row>
2885 <row>
2886 <entry>@cpu-emulation</entry>
2887 <entry>System calls for CPU emulation functionality (<citerefentry project='man-pages'><refentrytitle>vm86</refentrytitle><manvolnum>2</manvolnum></citerefentry> and related calls)</entry>
2888 </row>
2889 <row>
2890 <entry>@debug</entry>
2891 <entry>Debugging, performance monitoring and tracing functionality (<citerefentry project='man-pages'><refentrytitle>ptrace</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>perf_event_open</refentrytitle><manvolnum>2</manvolnum></citerefentry> and related calls)</entry>
2892 </row>
2893 <row>
2894 <entry>@file-system</entry>
2895 <entry>File system operations: opening, creating files and directories for read and write, renaming and removing them, reading file properties, or creating hard and symbolic links</entry>
2896 </row>
2897 <row>
2898 <entry>@io-event</entry>
2899 <entry>Event loop system calls (<citerefentry project='man-pages'><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>select</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>epoll</refentrytitle><manvolnum>7</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>eventfd</refentrytitle><manvolnum>2</manvolnum></citerefentry> and related calls)</entry>
2900 </row>
2901 <row>
2902 <entry>@ipc</entry>
2903 <entry>Pipes, SysV IPC, POSIX Message Queues and other IPC (<citerefentry project='man-pages'><refentrytitle>mq_overview</refentrytitle><manvolnum>7</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>svipc</refentrytitle><manvolnum>7</manvolnum></citerefentry>)</entry>
2904 </row>
2905 <row>
2906 <entry>@keyring</entry>
2907 <entry>Kernel keyring access (<citerefentry project='man-pages'><refentrytitle>keyctl</refentrytitle><manvolnum>2</manvolnum></citerefentry> and related calls)</entry>
2908 </row>
2909 <row>
2910 <entry>@memlock</entry>
2911 <entry>Locking of memory in RAM (<citerefentry project='man-pages'><refentrytitle>mlock</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>mlockall</refentrytitle><manvolnum>2</manvolnum></citerefentry> and related calls)</entry>
2912 </row>
2913 <row>
2914 <entry>@module</entry>
2915 <entry>Loading and unloading of kernel modules (<citerefentry project='man-pages'><refentrytitle>init_module</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>delete_module</refentrytitle><manvolnum>2</manvolnum></citerefentry> and related calls)</entry>
2916 </row>
2917 <row>
2918 <entry>@mount</entry>
2919 <entry>Mounting and unmounting of file systems (<citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>2</manvolnum></citerefentry>, and related calls)</entry>
2920 </row>
2921 <row>
2922 <entry>@network-io</entry>
2923 <entry>Socket I/O (including local AF_UNIX): <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>unix</refentrytitle><manvolnum>7</manvolnum></citerefentry></entry>
2924 </row>
2925 <row>
2926 <entry>@obsolete</entry>
2927 <entry>Unusual, obsolete or unimplemented (<citerefentry project='man-pages'><refentrytitle>create_module</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>gtty</refentrytitle><manvolnum>2</manvolnum></citerefentry>, …)</entry>
2928 </row>
2929 <row>
2930 <entry>@pkey</entry>
2931 <entry>System calls that deal with memory protection keys (<citerefentry project='man-pages'><refentrytitle>pkeys</refentrytitle><manvolnum>7</manvolnum></citerefentry>)</entry>
2932 </row>
2933 <row>
2934 <entry>@privileged</entry>
2935 <entry>All system calls which need super-user capabilities (<citerefentry project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>)</entry>
2936 </row>
2937 <row>
2938 <entry>@process</entry>
2939 <entry>Process control, execution, namespacing operations (<citerefentry project='man-pages'><refentrytitle>clone</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>kill</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>namespaces</refentrytitle><manvolnum>7</manvolnum></citerefentry>, …)</entry>
2940 </row>
2941 <row>
2942 <entry>@raw-io</entry>
2943 <entry>Raw I/O port access (<citerefentry project='man-pages'><refentrytitle>ioperm</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>iopl</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <function>pciconfig_read()</function>, …)</entry>
2944 </row>
2945 <row>
2946 <entry>@reboot</entry>
2947 <entry>System calls for rebooting and reboot preparation (<citerefentry project='man-pages'><refentrytitle>reboot</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <function>kexec()</function>, …)</entry>
2948 </row>
2949 <row>
2950 <entry>@resources</entry>
2951 <entry>System calls for changing resource limits, memory and scheduling parameters (<citerefentry project='man-pages'><refentrytitle>setrlimit</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>setpriority</refentrytitle><manvolnum>2</manvolnum></citerefentry>, …)</entry>
2952 </row>
2953 <row>
2954 <entry>@sandbox</entry>
2955 <entry>System calls for sandboxing programs (<citerefentry project='man-pages'><refentrytitle>seccomp</refentrytitle><manvolnum>2</manvolnum></citerefentry>, Landlock system calls, …)</entry>
2956 </row>
2957 <row>
2958 <entry>@setuid</entry>
2959 <entry>System calls for changing user ID and group ID credentials, (<citerefentry project='man-pages'><refentrytitle>setuid</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>setgid</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>setresuid</refentrytitle><manvolnum>2</manvolnum></citerefentry>, …)</entry>
2960 </row>
2961 <row>
2962 <entry>@signal</entry>
2963 <entry>System calls for manipulating and handling process signals (<citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>sigprocmask</refentrytitle><manvolnum>2</manvolnum></citerefentry>, …)</entry>
2964 </row>
2965 <row>
2966 <entry>@swap</entry>
2967 <entry>System calls for enabling/disabling swap devices (<citerefentry project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>swapoff</refentrytitle><manvolnum>2</manvolnum></citerefentry>)</entry>
2968 </row>
2969 <row>
2970 <entry>@sync</entry>
2971 <entry>Synchronizing files and memory to disk (<citerefentry project='man-pages'><refentrytitle>fsync</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>msync</refentrytitle><manvolnum>2</manvolnum></citerefentry>, and related calls)</entry>
2972 </row>
2973 <row>
2974 <entry>@system-service</entry>
2975 <entry>A reasonable set of system calls used by common system services, excluding any special purpose calls. This is the recommended starting point for allow-listing system calls for system services, as it contains what is typically needed by system services, but excludes overly specific interfaces. For example, the following APIs are excluded: <literal>@clock</literal>, <literal>@mount</literal>, <literal>@swap</literal>, <literal>@reboot</literal>.</entry>
2976 </row>
2977 <row>
2978 <entry>@timer</entry>
2979 <entry>System calls for scheduling operations by time (<citerefentry project='man-pages'><refentrytitle>alarm</refentrytitle><manvolnum>2</manvolnum></citerefentry>, <citerefentry project='man-pages'><refentrytitle>timer_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>, …)</entry>
2980 </row>
2981 <row>
2982 <entry>@known</entry>
2983 <entry>All system calls defined by the kernel. This list is defined statically in systemd based on a kernel version that was available when this systemd version was released. It will become progressively more out-of-date as the kernel is updated.</entry>
2984 </row>
2985 </tbody>
2986 </tgroup>
2987 </table>
2988
2989 Note, that as new system calls are added to the kernel, additional system calls might be added to the groups
2990 above. Contents of the sets may also change between systemd versions. In addition, the list of system calls
2991 depends on the kernel version and architecture for which systemd was compiled. Use
2992 <command>systemd-analyze syscall-filter</command> to list the actual list of system calls in each
2993 filter.</para>
2994
2995 <para>Generally, allow-listing system calls (rather than deny-listing) is the safer mode of
2996 operation. It is recommended to enforce system call allow lists for all long-running system
2997 services. Specifically, the following lines are a relatively safe basic choice for the majority of
2998 system services:</para>
2999
3000 <programlisting>[Service]
3001SystemCallFilter=@system-service
3002SystemCallErrorNumber=EPERM</programlisting>
3003
3004 <para>Note that various kernel system calls are defined redundantly: there are multiple system calls
3005 for executing the same operation. For example, the <function>pidfd_send_signal()</function> system
3006 call may be used to execute operations similar to what can be done with the older
3007 <function>kill()</function> system call, hence blocking the latter without the former only provides
3008 weak protection. Since new system calls are added regularly to the kernel as development progresses,
3009 keeping system call deny lists comprehensive requires constant work. It is thus recommended to use
3010 allow-listing instead, which offers the benefit that new system calls are by default implicitly
3011 blocked until the allow list is updated.</para>
3012
3013 <para>Also note that a number of system calls are required to be accessible for the dynamic linker to
3014 work. The dynamic linker is required for running most regular programs (specifically: all dynamic ELF
3015 binaries, which is how most distributions build packaged programs). This means that blocking these
3016 system calls (which include <function>open()</function>, <function>openat()</function> or
3017 <function>mmap()</function>) will make most programs typically shipped with generic distributions
3018 unusable.</para>
3019
3020 <para>It is recommended to combine the file system namespacing related options with
3021 <varname>SystemCallFilter=~@mount</varname>, in order to prohibit the unit's processes to undo the
3022 mappings. Specifically these are the options <varname>PrivateTmp=</varname>,
3023 <varname>PrivateDevices=</varname>, <varname>ProtectSystem=</varname>, <varname>ProtectHome=</varname>,
3024 <varname>ProtectKernelTunables=</varname>, <varname>ProtectControlGroups=</varname>,
3025 <varname>ProtectKernelLogs=</varname>, <varname>ProtectClock=</varname>, <varname>ReadOnlyPaths=</varname>,
3026 <varname>InaccessiblePaths=</varname> and <varname>ReadWritePaths=</varname>.</para>
3027
3028 <xi:include href="version-info.xml" xpointer="v187"/></listitem>
3029 </varlistentry>
3030
3031 <varlistentry>
3032 <term><varname>SystemCallErrorNumber=</varname></term>
3033
3034 <listitem><para>Takes an <literal>errno</literal> error number (between 1 and 4095) or errno name
3035 such as <constant>EPERM</constant>, <constant>EACCES</constant> or <constant>EUCLEAN</constant>, to
3036 return when the system call filter configured with <varname>SystemCallFilter=</varname> is triggered,
3037 instead of terminating the process immediately. See <citerefentry
3038 project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry> for a
3039 full list of error codes. When this setting is not used, or when the empty string or the special
3040 setting <literal>kill</literal> is assigned, the process will be terminated immediately when the
3041 filter is triggered.</para>
3042
3043 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
3044 </varlistentry>
3045
3046 <varlistentry>
3047 <term><varname>SystemCallArchitectures=</varname></term>
3048
3049 <listitem><para>Takes a space-separated list of architecture identifiers to include in the system call
3050 filter. The known architecture identifiers are the same as for <varname>ConditionArchitecture=</varname>
3051 described in <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
3052 as well as <constant>x32</constant>, <constant>mips64-n32</constant>, <constant>mips64-le-n32</constant>, and
3053 the special identifier <constant>native</constant>. The special identifier <constant>native</constant>
3054 implicitly maps to the native architecture of the system (or more precisely: to the architecture the system
3055 manager is compiled for). By default, this option is set to the empty list, i.e. no filtering is applied.</para>
3056
3057 <para>If this setting is used, processes of this unit will only be permitted to call native system calls, and
3058 system calls of the specified architectures. For the purposes of this option, the x32 architecture is treated
3059 as including x86-64 system calls. However, this setting still fulfills its purpose, as explained below, on
3060 x32.</para>
3061
3062 <para>System call filtering is not equally effective on all architectures. For example, on x86
3063 filtering of network socket-related calls is not possible, due to ABI limitations — a limitation that x86-64
3064 does not have, however. On systems supporting multiple ABIs at the same time — such as x86/x86-64 — it is hence
3065 recommended to limit the set of permitted system call architectures so that secondary ABIs may not be used to
3066 circumvent the restrictions applied to the native ABI of the system. In particular, setting
3067 <varname>SystemCallArchitectures=native</varname> is a good choice for disabling non-native ABIs.</para>
3068
3069 <para>System call architectures may also be restricted system-wide via the
3070 <varname>SystemCallArchitectures=</varname> option in the global configuration. See
3071 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
3072 details.</para>
3073
3074 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
3075 </varlistentry>
3076
3077 <varlistentry>
3078 <term><varname>SystemCallLog=</varname></term>
3079
3080 <listitem><para>Takes a space-separated list of system call names. If this setting is used, all
3081 system calls executed by the unit processes for the listed ones will be logged. If the first
3082 character of the list is <literal>~</literal>, the effect is inverted: all system calls except the
3083 listed system calls will be logged. This feature makes use of the Secure Computing Mode 2 interfaces
3084 of the kernel ('seccomp filtering') and is useful for auditing or setting up a minimal sandboxing
3085 environment. This option may be specified more than once, in which case the filter masks are merged.
3086 If the empty string is assigned, the filter is reset, all prior assignments will have no effect.
3087 This does not affect commands prefixed with <literal>+</literal>.</para>
3088
3089 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
3090 </varlistentry>
3091
3092 </variablelist>
3093 </refsect1>
3094
3095 <refsect1>
3096 <title>Environment</title>
3097
3098 <variablelist class='unit-directives'>
3099
3100 <varlistentry>
3101 <term><varname>Environment=</varname></term>
3102
3103 <listitem><para>Sets environment variables for executed processes. Each line is unquoted using the
3104 rules described in "Quoting" section in
3105 <citerefentry><refentrytitle>systemd.syntax</refentrytitle><manvolnum>7</manvolnum></citerefentry>
3106 and becomes a list of variable assignments. If you need to assign a value containing spaces or the
3107 equals sign to a variable, put quotes around the whole assignment. Variable expansion is not
3108 performed inside the strings and the <literal>$</literal> character has no special meaning. Specifier
3109 expansion is performed, see the "Specifiers" section in
3110 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
3111 </para>
3112
3113 <para>This option may be specified more than once, in which case all listed variables will be set. If
3114 the same variable is listed twice, the later setting will override the earlier setting. If the empty
3115 string is assigned to this option, the list of environment variables is reset, all prior assignments
3116 have no effect.</para>
3117
3118 <para>The names of the variables can contain ASCII letters, digits, and the underscore character.
3119 Variable names cannot be empty or start with a digit. In variable values, most characters are
3120 allowed, but non-printable characters are currently rejected.</para>
3121
3122 <para>Example:
3123 <programlisting>Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"</programlisting>
3124 gives three variables <literal>VAR1</literal>,
3125 <literal>VAR2</literal>, <literal>VAR3</literal>
3126 with the values <literal>word1 word2</literal>,
3127 <literal>word3</literal>, <literal>$word 5 6</literal>.
3128 </para>
3129
3130 <para>See <citerefentry
3131 project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
3132 details about environment variables.</para>
3133
3134 <para>Note that environment variables are not suitable for passing secrets (such as passwords, key
3135 material, …) to service processes. Environment variables set for a unit are exposed to unprivileged
3136 clients via D-Bus IPC, and generally not understood as being data that requires protection. Moreover,
3137 environment variables are propagated down the process tree, including across security boundaries
3138 (such as setuid/setgid executables), and hence might leak to processes that should not have access to
3139 the secret data. Use <varname>LoadCredential=</varname>, <varname>LoadCredentialEncrypted=</varname>
3140 or <varname>SetCredentialEncrypted=</varname> (see below) to pass data to unit processes
3141 securely.</para></listitem>
3142 </varlistentry>
3143
3144 <varlistentry>
3145 <term><varname>EnvironmentFile=</varname></term>
3146
3147 <listitem><para>Similar to <varname>Environment=</varname>, but reads the environment variables from
3148 a text file. The text file should contain newline-separated variable assignments. Empty lines, lines
3149 without an <literal>=</literal> separator, or lines starting with <literal>;</literal> or
3150 <literal>#</literal> will be ignored, which may be used for commenting. The file must be encoded with
3151 UTF-8. Valid characters are
3152 <ulink url="https://www.unicode.org/glossary/#unicode_scalar_value">unicode scalar values</ulink>
3153 other than
3154 <ulink url="https://www.unicode.org/glossary/#noncharacter">unicode noncharacters</ulink>,
3155 <constant>U+0000</constant> <constant>NUL</constant>, and <constant>U+FEFF</constant>
3156 <ulink url="https://www.unicode.org/glossary/#byte_order_mark">unicode byte order mark</ulink>.
3157 Control codes other than <constant>NUL</constant> are allowed.</para>
3158
3159 <para>In the file, an unquoted value after the <literal>=</literal> is parsed with the same backslash-escape
3160 rules as <ulink
3161 url="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_01">POSIX shell unquoted
3162 text</ulink>, but unlike in a shell, interior whitespace is preserved and quotes after the
3163 first non-whitespace character are preserved. Leading and trailing whitespace (space, tab, carriage return) is
3164 discarded, but interior whitespace within the line is preserved verbatim. A line ending with a backslash will be
3165 continued to the following one, with the newline itself discarded. A backslash
3166 <literal>\</literal> followed by any character other than newline will preserve the following character, so that
3167 <literal>\\</literal> will become the value <literal>\</literal>.</para>
3168
3169 <para>In the file, a <literal>'</literal>-quoted value after the <literal>=</literal> can span
3170 multiple lines and contain any character verbatim other than single quote, like <ulink
3171 url="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02">POSIX
3172 shell single-quoted text</ulink>. No backslash-escape sequences are recognized. Leading and trailing
3173 whitespace outside of the single quotes is discarded.</para>
3174
3175 <para>In the file, a <literal>"</literal>-quoted value after the <literal>=</literal> can span
3176 multiple lines, and the same escape sequences are recognized as in <ulink
3177 url="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_03">POSIX
3178 shell double-quoted text</ulink>. Backslash (<literal>\</literal>) followed by any of
3179 <literal>"\`$</literal> will preserve that character. A backslash followed by newline is a line
3180 continuation, and the newline itself is discarded. A backslash followed by any other character is
3181 ignored; both the backslash and the following character are preserved verbatim. Leading and trailing
3182 whitespace outside of the double quotes is discarded.</para>
3183
3184 <para>The argument passed should be an absolute filename or wildcard expression, optionally prefixed with
3185 <literal>-</literal>, which indicates that if the file does not exist, it will not be read and no error or
3186 warning message is logged. This option may be specified more than once in which case all specified files are
3187 read. If the empty string is assigned to this option, the list of file to read is reset, all prior assignments
3188 have no effect.</para>
3189
3190 <para>The files listed with this directive will be read shortly before the process is executed (more
3191 specifically, after all processes from a previous unit state terminated. This means you can generate these
3192 files in one unit state, and read it with this option in the next. The files are read from the file
3193 system of the service manager, before any file system changes like bind mounts take place).</para>
3194
3195 <para>Settings from these files override settings made with <varname>Environment=</varname>. If the same
3196 variable is set twice from these files, the files will be read in the order they are specified and the later
3197 setting will override the earlier setting.</para></listitem>
3198 </varlistentry>
3199
3200 <varlistentry>
3201 <term><varname>PassEnvironment=</varname></term>
3202
3203 <listitem><para>Pass environment variables set for the system service manager to executed processes. Takes a
3204 space-separated list of variable names. This option may be specified more than once, in which case all listed
3205 variables will be passed. If the empty string is assigned to this option, the list of environment variables to
3206 pass is reset, all prior assignments have no effect. Variables specified that are not set for the system
3207 manager will not be passed and will be silently ignored. Note that this option is only relevant for the system
3208 service manager, as system services by default do not automatically inherit any environment variables set for
3209 the service manager itself. However, in case of the user service manager all environment variables are passed
3210 to the executed processes anyway, hence this option is without effect for the user service manager.</para>
3211
3212 <para>Variables set for invoked processes due to this setting are subject to being overridden by those
3213 configured with <varname>Environment=</varname> or <varname>EnvironmentFile=</varname>.</para>
3214
3215 <para>Example:
3216 <programlisting>PassEnvironment=VAR1 VAR2 VAR3</programlisting>
3217 passes three variables <literal>VAR1</literal>,
3218 <literal>VAR2</literal>, <literal>VAR3</literal>
3219 with the values set for those variables in PID1.</para>
3220
3221 <para>
3222 See <citerefentry
3223 project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry> for details
3224 about environment variables.</para>
3225
3226 <xi:include href="version-info.xml" xpointer="v228"/></listitem>
3227 </varlistentry>
3228
3229 <varlistentry>
3230 <term><varname>UnsetEnvironment=</varname></term>
3231
3232 <listitem><para>Explicitly unset environment variable assignments that would normally be passed from the
3233 service manager to invoked processes of this unit. Takes a space-separated list of variable names or variable
3234 assignments. This option may be specified more than once, in which case all listed variables/assignments will
3235 be unset. If the empty string is assigned to this option, the list of environment variables/assignments to
3236 unset is reset. If a variable assignment is specified (that is: a variable name, followed by
3237 <literal>=</literal>, followed by its value), then any environment variable matching this precise assignment is
3238 removed. If a variable name is specified (that is a variable name without any following <literal>=</literal> or
3239 value), then any assignment matching the variable name, regardless of its value is removed. Note that the
3240 effect of <varname>UnsetEnvironment=</varname> is applied as final step when the environment list passed to
3241 executed processes is compiled. That means it may undo assignments from any configuration source, including
3242 assignments made through <varname>Environment=</varname> or <varname>EnvironmentFile=</varname>, inherited from
3243 the system manager's global set of environment variables, inherited via <varname>PassEnvironment=</varname>,
3244 set by the service manager itself (such as <varname>$NOTIFY_SOCKET</varname> and such), or set by a PAM module
3245 (in case <varname>PAMName=</varname> is used).</para>
3246
3247 <para>See "Environment Variables in Spawned Processes" below for a description of how those
3248 settings combine to form the inherited environment. See <citerefentry
3249 project='man-pages'><refentrytitle>environ</refentrytitle><manvolnum>7</manvolnum></citerefentry> for general
3250 information about environment variables.</para>
3251
3252 <xi:include href="version-info.xml" xpointer="v235"/></listitem>
3253 </varlistentry>
3254
3255 </variablelist>
3256 </refsect1>
3257
3258 <refsect1>
3259 <title>Logging and Standard Input/Output</title>
3260
3261 <variablelist class='unit-directives'>
3262 <varlistentry>
3263
3264 <term><varname>StandardInput=</varname></term>
3265
3266 <listitem><para>Controls where file descriptor 0 (STDIN) of the executed processes is connected to. Takes one
3267 of <option>null</option>, <option>tty</option>, <option>tty-force</option>, <option>tty-fail</option>,
3268 <option>data</option>, <option>file:<replaceable>path</replaceable></option>, <option>socket</option> or
3269 <option>fd:<replaceable>name</replaceable></option>.</para>
3270
3271 <para>If <option>null</option> is selected, standard input will be connected to <filename>/dev/null</filename>,
3272 i.e. all read attempts by the process will result in immediate EOF.</para>
3273
3274 <para>If <option>tty</option> is selected, standard input is connected to a TTY (as configured by
3275 <varname>TTYPath=</varname>, see below) and the executed process becomes the controlling process of the
3276 terminal. If the terminal is already being controlled by another process, the executed process waits until the
3277 current controlling process releases the terminal.</para>
3278
3279 <para><option>tty-force</option> is similar to <option>tty</option>, but the executed process is forcefully and
3280 immediately made the controlling process of the terminal, potentially removing previous controlling processes
3281 from the terminal.</para>
3282
3283 <para><option>tty-fail</option> is similar to <option>tty</option>, but if the terminal already has a
3284 controlling process start-up of the executed process fails.</para>
3285
3286 <para>The <option>data</option> option may be used to configure arbitrary textual or binary data to pass via
3287 standard input to the executed process. The data to pass is configured via
3288 <varname>StandardInputText=</varname>/<varname>StandardInputData=</varname> (see below). Note that the actual
3289 file descriptor type passed (memory file, regular file, UNIX pipe, …) might depend on the kernel and available
3290 privileges. In any case, the file descriptor is read-only, and when read returns the specified data followed by
3291 EOF.</para>
3292
3293 <para>The <option>file:<replaceable>path</replaceable></option> option may be used to connect a specific file
3294 system object to standard input. An absolute path following the <literal>:</literal> character is expected,
3295 which may refer to a regular file, a FIFO or special file. If an <constant>AF_UNIX</constant> socket in the
3296 file system is specified, a stream socket is connected to it. The latter is useful for connecting standard
3297 input of processes to arbitrary system services.</para>
3298
3299 <para>The <option>socket</option> option is valid in socket-activated services only, and requires the relevant
3300 socket unit file (see
3301 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details)
3302 to have <varname>Accept=yes</varname> set, or to specify a single socket only. If this option is set, standard
3303 input will be connected to the socket the service was activated from, which is primarily useful for
3304 compatibility with daemons designed for use with the traditional <citerefentry
3305 project='freebsd'><refentrytitle>inetd</refentrytitle><manvolnum>8</manvolnum></citerefentry> socket activation
3306 daemon (<varname>$LISTEN_FDS</varname> (and related) environment variables are not passed when
3307 <option>socket</option> value is configured).</para>
3308
3309 <para>The <option>fd:<replaceable>name</replaceable></option> option connects standard input to a specific,
3310 named file descriptor provided by a socket unit. The name may be specified as part of this option, following a
3311 <literal>:</literal> character (e.g. <literal>fd:foobar</literal>). If no name is specified, the name
3312 <literal>stdin</literal> is implied (i.e. <literal>fd</literal> is equivalent to <literal>fd:stdin</literal>).
3313 At least one socket unit defining the specified name must be provided via the <varname>Sockets=</varname>
3314 option, and the file descriptor name may differ from the name of its containing socket unit. If multiple
3315 matches are found, the first one will be used. See <varname>FileDescriptorName=</varname> in
3316 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
3317 details about named file descriptors and their ordering.</para>
3318
3319 <para>This setting defaults to <option>null</option>, unless
3320 <varname>StandardInputText=</varname>/<varname>StandardInputData=</varname> are set, in which case it
3321 defaults to <option>data</option>.</para></listitem>
3322 </varlistentry>
3323
3324 <varlistentry>
3325 <term><varname>StandardOutput=</varname></term>
3326
3327 <listitem><para>Controls where file descriptor 1 (stdout) of the executed processes is connected
3328 to. Takes one of <option>inherit</option>, <option>null</option>, <option>tty</option>,
3329 <option>journal</option>, <option>kmsg</option>, <option>journal+console</option>,
3330 <option>kmsg+console</option>, <option>file:<replaceable>path</replaceable></option>,
3331 <option>append:<replaceable>path</replaceable></option>, <option>truncate:<replaceable>path</replaceable></option>,
3332 <option>socket</option> or <option>fd:<replaceable>name</replaceable></option>.</para>
3333
3334 <para><option>inherit</option> duplicates the file descriptor of standard input for standard output.</para>
3335
3336 <para><option>null</option> connects standard output to <filename>/dev/null</filename>, i.e. everything written
3337 to it will be lost.</para>
3338
3339 <para><option>tty</option> connects standard output to a tty (as configured via <varname>TTYPath=</varname>,
3340 see below). If the TTY is used for output only, the executed process will not become the controlling process of
3341 the terminal, and will not fail or wait for other processes to release the terminal. Note: if a unit
3342 tries to print multiple lines to a TTY during bootup or shutdown, then there's a chance that those
3343 lines will be broken up by status messages. <function>SetShowStatus()</function> can be used to
3344 prevent this problem. See
3345 <citerefentry project="man-pages"><refentrytitle>org.freedesktop.systemd1</refentrytitle><manvolnum>5</manvolnum></citerefentry>
3346 for details.</para>
3347
3348 <para><option>journal</option> connects standard output with the journal, which is accessible via
3349 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>. Note
3350 that everything that is written to kmsg (see below) is implicitly stored in the journal as well, the
3351 specific option listed below is hence a superset of this one. (Also note that any external,
3352 additional syslog daemons receive their log data from the journal, too, hence this is the option to
3353 use when logging shall be processed with such a daemon.)</para>
3354
3355 <para><option>kmsg</option> connects standard output with the kernel log buffer which is accessible via
3356 <citerefentry project='man-pages'><refentrytitle>dmesg</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
3357 in addition to the journal. The journal daemon might be configured to send all logs to kmsg anyway, in which
3358 case this option is no different from <option>journal</option>.</para>
3359
3360 <para><option>journal+console</option> and <option>kmsg+console</option> work in a similar way as the
3361 two options above but copy the output to the system console as well.</para>
3362
3363 <para>The <option>file:<replaceable>path</replaceable></option> option may be used to connect a specific file
3364 system object to standard output. The semantics are similar to the same option of
3365 <varname>StandardInput=</varname>, see above. If <replaceable>path</replaceable> refers to a regular file
3366 on the filesystem, it is opened (created if it does not exist yet using privileges of the user executing the
3367 systemd process) for writing at the beginning of the file, but without truncating it.
3368 If standard input and output are directed to the same file path, it is opened only once — for reading as well
3369 as writing — and duplicated. This is particularly useful when the specified path refers to an
3370 <constant>AF_UNIX</constant> socket in the file system, as in that case only a
3371 single stream connection is created for both input and output.</para>
3372
3373 <para><option>append:<replaceable>path</replaceable></option> is similar to
3374 <option>file:<replaceable>path</replaceable></option> above, but it opens the file in append mode.
3375 </para>
3376
3377 <para><option>truncate:<replaceable>path</replaceable></option> is similar to
3378 <option>file:<replaceable>path</replaceable></option> above, but it truncates the file when opening
3379 it. For units with multiple command lines, e.g. <varname>Type=oneshot</varname> services with
3380 multiple <varname>ExecStart=</varname>, or services with <varname>ExecCondition=</varname>,
3381 <varname>ExecStartPre=</varname> or <varname>ExecStartPost=</varname>, the output file is reopened
3382 and therefore re-truncated for each command line. If the output file is truncated while another
3383 process still has the file open, e.g. by an <varname>ExecReload=</varname> running concurrently with
3384 an <varname>ExecStart=</varname>, and the other process continues writing to the file without
3385 adjusting its offset, then the space between the file pointers of the two processes may be filled
3386 with <constant>NUL</constant> bytes, producing a sparse file. Thus,
3387 <option>truncate:<replaceable>path</replaceable></option> is typically only useful for units where
3388 only one process runs at a time, such as services with a single <varname>ExecStart=</varname> and no
3389 <varname>ExecStartPost=</varname>, <varname>ExecReload=</varname>, <varname>ExecStop=</varname> or
3390 similar.</para>
3391
3392 <para><option>socket</option> connects standard output to a socket acquired via socket activation. The
3393 semantics are similar to the same option of <varname>StandardInput=</varname>, see above.</para>
3394
3395 <para>The <option>fd:<replaceable>name</replaceable></option> option connects standard output to a
3396 specific, named file descriptor provided by a socket unit. A name may be specified as part of this
3397 option, following a <literal>:</literal> character
3398 (e.g. <literal>fd:<replaceable>foobar</replaceable></literal>). If no name is specified, the name
3399 <literal>stdout</literal> is implied (i.e. <literal>fd</literal> is equivalent to
3400 <literal>fd:stdout</literal>). At least one socket unit defining the specified name must be provided
3401 via the <varname>Sockets=</varname> option, and the file descriptor name may differ from the name of
3402 its containing socket unit. If multiple matches are found, the first one will be used. See
3403 <varname>FileDescriptorName=</varname> in
3404 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>
3405 for more details about named descriptors and their ordering.</para>
3406
3407 <para>If the standard output (or error output, see below) of a unit is connected to the journal or
3408 the kernel log buffer, the unit will implicitly gain a dependency of type <varname>After=</varname>
3409 on <filename>systemd-journald.socket</filename> (also see the "Implicit Dependencies" section
3410 above). Also note that, in this case, stdout (or stderr, see below) will be an
3411 <constant>AF_UNIX</constant> stream socket, and not a pipe or FIFO that can be reopened. This means
3412 when executing shell scripts the construct <command>echo "hello" &gt; /dev/stderr</command> for
3413 writing text to stderr will not work. To mitigate this use the construct <command>echo "hello"
3414 >&amp;2</command> instead, which is mostly equivalent and avoids this pitfall.</para>
3415
3416 <para>If <varname>StandardInput=</varname> is set to one of <option>tty</option>, <option>tty-force</option>,
3417 <option>tty-fail</option>, <option>socket</option>, or <option>fd:<replaceable>name</replaceable></option>, this
3418 setting defaults to <option>inherit</option>.</para>
3419
3420 <para>In other cases, this setting defaults to the value set with <varname>DefaultStandardOutput=</varname> in
3421 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, which
3422 defaults to <option>journal</option>. Note that setting this parameter might result in additional dependencies
3423 to be added to the unit (see above).</para></listitem>
3424 </varlistentry>
3425
3426 <varlistentry>
3427 <term><varname>StandardError=</varname></term>
3428
3429 <listitem><para>Controls where file descriptor 2 (stderr) of the executed processes is connected to. The
3430 available options are identical to those of <varname>StandardOutput=</varname>, with some exceptions: if set to
3431 <option>inherit</option> the file descriptor used for standard output is duplicated for standard error, while
3432 <option>fd:<replaceable>name</replaceable></option> will use a default file descriptor name of
3433 <literal>stderr</literal>.</para>
3434
3435 <para>This setting defaults to the value set with <varname>DefaultStandardError=</varname> in
3436 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>, which
3437 defaults to <option>inherit</option>. Note that setting this parameter might result in additional dependencies
3438 to be added to the unit (see above).</para></listitem>
3439 </varlistentry>
3440
3441 <varlistentry>
3442 <term><varname>StandardInputText=</varname></term>
3443 <term><varname>StandardInputData=</varname></term>
3444
3445 <listitem><para>Configures arbitrary textual or binary data to pass via file descriptor 0 (STDIN) to
3446 the executed processes. These settings have no effect unless <varname>StandardInput=</varname> is set
3447 to <option>data</option> (which is the default if <varname>StandardInput=</varname> is not set
3448 otherwise, but <varname>StandardInputText=</varname>/<varname>StandardInputData=</varname> is). Use
3449 this option to embed process input data directly in the unit file.</para>
3450
3451 <para><varname>StandardInputText=</varname> accepts arbitrary textual data. C-style escapes for special
3452 characters as well as the usual <literal>%</literal>-specifiers are resolved. Each time this setting is used
3453 the specified text is appended to the per-unit data buffer, followed by a newline character (thus every use
3454 appends a new line to the end of the buffer). Note that leading and trailing whitespace of lines configured
3455 with this option is removed. If an empty line is specified the buffer is cleared (hence, in order to insert an
3456 empty line, add an additional <literal>\n</literal> to the end or beginning of a line).</para>
3457
3458 <para><varname>StandardInputData=</varname> accepts arbitrary binary data, encoded in <ulink
3459 url="https://tools.ietf.org/html/rfc2045#section-6.8">Base64</ulink>. No escape sequences or specifiers are
3460 resolved. Any whitespace in the encoded version is ignored during decoding.</para>
3461
3462 <para>Note that <varname>StandardInputText=</varname> and <varname>StandardInputData=</varname> operate on the
3463 same data buffer, and may be mixed in order to configure both binary and textual data for the same input
3464 stream. The textual or binary data is joined strictly in the order the settings appear in the unit
3465 file. Assigning an empty string to either will reset the data buffer.</para>
3466
3467 <para>Please keep in mind that in order to maintain readability long unit file settings may be split into
3468 multiple lines, by suffixing each line (except for the last) with a <literal>\</literal> character (see
3469 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
3470 details). This is particularly useful for large data configured with these two options. Example:</para>
3471
3472 <programlisting>…
3473StandardInput=data
3474StandardInputData=V2XigLJyZSBubyBzdHJhbmdlcnMgdG8gbG92ZQpZb3Uga25vdyB0aGUgcnVsZXMgYW5kIHNvIGRv \
3475 IEkKQSBmdWxsIGNvbW1pdG1lbnQncyB3aGF0IEnigLJtIHRoaW5raW5nIG9mCllvdSB3b3VsZG4n \
3476 dCBnZXQgdGhpcyBmcm9tIGFueSBvdGhlciBndXkKSSBqdXN0IHdhbm5hIHRlbGwgeW91IGhvdyBJ \
3477 J20gZmVlbGluZwpHb3R0YSBtYWtlIHlvdSB1bmRlcnN0YW5kCgpOZXZlciBnb25uYSBnaXZlIHlv \
3478 dSB1cApOZXZlciBnb25uYSBsZXQgeW91IGRvd24KTmV2ZXIgZ29ubmEgcnVuIGFyb3VuZCBhbmQg \
3479 ZGVzZXJ0IHlvdQpOZXZlciBnb25uYSBtYWtlIHlvdSBjcnkKTmV2ZXIgZ29ubmEgc2F5IGdvb2Ri \
3480 eWUKTmV2ZXIgZ29ubmEgdGVsbCBhIGxpZSBhbmQgaHVydCB5b3UK
3481…</programlisting>
3482
3483 <xi:include href="version-info.xml" xpointer="v236"/></listitem>
3484 </varlistentry>
3485
3486 <varlistentry>
3487 <term><varname>LogLevelMax=</varname></term>
3488
3489 <listitem><para>Sets the maximum log level for log messages generated by this unit. Takes a
3490 <command>syslog</command> log level, one of <option>emerg</option> (lowest log level, only highest
3491 priority messages), <option>alert</option>, <option>crit</option>, <option>err</option>,
3492 <option>warning</option>, <option>notice</option>, <option>info</option>, <option>debug</option>
3493 (highest log level, also lowest priority messages). See <citerefentry
3494 project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
3495 details. By default, the maximum log level is not overridden.</para>
3496
3497 <para>This option can be used to configure the logging system to drop log messages of a specific
3498 service above the specified level. For example, set
3499 <varname>LogLevelMax=</varname><option>info</option> in order to turn off debug logging of a
3500 particularly chatty unit. Alternatively, this option can be used to enable extra logging about a
3501 specific unit by the system or user manager processes without changing the global log level for the
3502 system or user manager processes by setting <varname>LogLevelMax=</varname><option>debug</option>.
3503 </para>
3504
3505 <para>Note that the configured level is applied to any log messages written by any of the processes
3506 belonging to this unit, as well as any log messages written by the system or user manager processes
3507 in reference to this unit, sent via any supported logging protocol. The override is applied early in
3508 the logging pipeline, before any kind of further processing is done. Moreover, messages which pass
3509 through this filter successfully might still be dropped by filters applied at a later stage in the
3510 logging subsystem. For example, <varname>MaxLevelStore=</varname> configured in
3511 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
3512 might prohibit messages of higher log levels to be stored on disk, even though the per-unit
3513 <varname>LogLevelMax=</varname> permitted it to be processed.</para>
3514
3515 <xi:include href="version-info.xml" xpointer="v236"/></listitem>
3516 </varlistentry>
3517
3518 <varlistentry>
3519 <term><varname>LogExtraFields=</varname></term>
3520
3521 <listitem><para>Configures additional log metadata fields to include in all log records generated by
3522 processes associated with this unit, including systemd. This setting takes one or more journal field
3523 assignments in the format <literal>FIELD=VALUE</literal> separated by whitespace. See
3524 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
3525 for details on the journal field concept. Even though the underlying journal implementation permits
3526 binary field values, this setting accepts only valid UTF-8 values. To include space characters in a
3527 journal field value, enclose the assignment in double quotes ("). <!-- " fake closing quote for emacs-->
3528 The usual specifiers are expanded in all assignments (see below). Note that this setting is not only
3529 useful for attaching additional metadata to log records of a unit, but given that all fields and
3530 values are indexed may also be used to implement cross-unit log record matching. Assign an empty
3531 string to reset the list.</para>
3532
3533 <para>Note that this functionality is currently only available in system services, not in per-user
3534 services.</para>
3535
3536 <xi:include href="version-info.xml" xpointer="v236"/></listitem>
3537 </varlistentry>
3538
3539 <varlistentry>
3540 <term><varname>LogRateLimitIntervalSec=</varname></term>
3541 <term><varname>LogRateLimitBurst=</varname></term>
3542
3543 <listitem><para>Configures the rate limiting that is applied to log messages generated by this unit.
3544 If, in the time interval defined by <varname>LogRateLimitIntervalSec=</varname>, more messages than
3545 specified in <varname>LogRateLimitBurst=</varname> are logged by a service, all further messages
3546 within the interval are dropped until the interval is over. A message about the number of dropped
3547 messages is generated. The time specification for <varname>LogRateLimitIntervalSec=</varname> may be
3548 specified in the following units: "s", "min", "h", "ms", "us". See
3549 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
3550 details. The default settings are set by <varname>RateLimitIntervalSec=</varname> and
3551 <varname>RateLimitBurst=</varname> configured in
3552 <citerefentry><refentrytitle>journald.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
3553 Note that this only applies to log messages that are processed by the logging subsystem, i.e. by
3554 <citerefentry><refentrytitle>systemd-journald.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
3555 This means that if you connect a service's stderr directly to a file via
3556 <varname>StandardOutput=file:…</varname> or a similar setting, the rate limiting will not be applied
3557 to messages written that way (but it will be enforced for messages generated via
3558 <citerefentry project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
3559 and similar functions).</para>
3560
3561 <xi:include href="version-info.xml" xpointer="v240"/></listitem>
3562 </varlistentry>
3563
3564 <varlistentry>
3565 <term><varname>LogFilterPatterns=</varname></term>
3566
3567 <listitem><para>Define an extended regular expression to filter log messages based on the
3568 <varname>MESSAGE=</varname> field of the structured message. If the first character of the pattern is
3569 <literal>~</literal>, log entries matching the pattern should be discarded. This option takes a single
3570 pattern as an argument but can be used multiple times to create a list of allowed and denied patterns.
3571 If the empty string is assigned, the filter is reset, and all prior assignments will have no effect.</para>
3572
3573 <para>Because the <literal>~</literal> character is used to define denied patterns, it must be replaced
3574 with <literal>\x7e</literal> to allow a message starting with <literal>~</literal>. For example,
3575 <literal>~foobar</literal> would add a pattern matching <literal>foobar</literal> to the deny list, while
3576 <literal>\x7efoobar</literal> would add a pattern matching <literal>~foobar</literal> to the allow list.</para>
3577
3578 <para>Log messages are tested against denied patterns (if any), then against allowed patterns
3579 (if any). If a log message matches any of the denied patterns, it is discarded immediately without considering
3580 allowed patterns. Remaining log messages are tested against allowed patterns. Messages matching
3581 against none of the allowed pattern are discarded. If no allowed patterns are defined, then all
3582 messages are processed directly after going through denied filters.</para>
3583
3584 <para>Filtering is based on the unit for which <varname>LogFilterPatterns=</varname> is defined, meaning log
3585 messages coming from
3586 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> about the
3587 unit are not taken into account. Filtered log messages will not be forwarded to traditional syslog daemons,
3588 the kernel log buffer (kmsg), the systemd console, or sent as wall messages to all logged-in
3589 users.</para>
3590
3591 <para>Note that this functionality is currently only available in system services, not in per-user
3592 services.</para>
3593
3594 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
3595 </varlistentry>
3596
3597 <varlistentry>
3598 <term><varname>LogNamespace=</varname></term>
3599
3600 <listitem><para>Run the unit's processes in the specified journal namespace. Expects a short
3601 user-defined string identifying the namespace. If not used the processes of the service are run in
3602 the default journal namespace, i.e. their log stream is collected and processed by
3603 <filename>systemd-journald.service</filename>. If this option is used any log data generated by
3604 processes of this unit (regardless of whether via the <function>syslog()</function>, journal native logging
3605 or stdout/stderr logging) is collected and processed by an instance of the
3606 <filename>systemd-journald@.service</filename> template unit, which manages the specified
3607 namespace. The log data is stored in a data store independent from the default log namespace's data
3608 store. See
3609 <citerefentry><refentrytitle>systemd-journald.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
3610 for details about journal namespaces.</para>
3611
3612 <para>Internally, journal namespaces are implemented through Linux mount namespacing and
3613 over-mounting the directory that contains the relevant <constant>AF_UNIX</constant> sockets used for
3614 logging in the unit's mount namespace. Since mount namespaces are used this setting disconnects
3615 propagation of mounts from the unit's processes to the host, similarly to how
3616 <varname>ReadOnlyPaths=</varname> and similar settings describe above work. Journal namespaces may hence
3617 not be used for services that need to establish mount points on the host.</para>
3618
3619 <para>When this option is used the unit will automatically gain ordering and requirement dependencies
3620 on the two socket units associated with the <filename>systemd-journald@.service</filename> instance
3621 so that they are automatically established prior to the unit starting up. Note that when this option
3622 is used log output of this service does not appear in the regular
3623 <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
3624 output, unless the <option>--namespace=</option> option is used.</para>
3625
3626 <xi:include href="system-only.xml" xpointer="singular"/>
3627
3628 <xi:include href="version-info.xml" xpointer="v245"/></listitem>
3629 </varlistentry>
3630
3631 <varlistentry>
3632 <term><varname>SyslogIdentifier=</varname></term>
3633
3634 <listitem><para>Sets the process name ("<command>syslog</command> tag") to prefix log lines sent to
3635 the logging system or the kernel log buffer with. If not set, defaults to the process name of the
3636 executed process. This option is only useful when <varname>StandardOutput=</varname> or
3637 <varname>StandardError=</varname> are set to <option>journal</option> or <option>kmsg</option> (or to
3638 the same settings in combination with <option>+console</option>) and only applies to log messages
3639 written to stdout or stderr.</para></listitem>
3640 </varlistentry>
3641
3642 <varlistentry>
3643 <term><varname>SyslogFacility=</varname></term>
3644
3645 <listitem><para>Sets the <command>syslog</command> facility identifier to use when logging. One of
3646 <option>kern</option>, <option>user</option>, <option>mail</option>, <option>daemon</option>,
3647 <option>auth</option>, <option>syslog</option>, <option>lpr</option>, <option>news</option>,
3648 <option>uucp</option>, <option>cron</option>, <option>authpriv</option>, <option>ftp</option>,
3649 <option>local0</option>, <option>local1</option>, <option>local2</option>, <option>local3</option>,
3650 <option>local4</option>, <option>local5</option>, <option>local6</option> or
3651 <option>local7</option>. See <citerefentry
3652 project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
3653 details. This option is only useful when <varname>StandardOutput=</varname> or
3654 <varname>StandardError=</varname> are set to <option>journal</option> or <option>kmsg</option> (or to
3655 the same settings in combination with <option>+console</option>), and only applies to log messages
3656 written to stdout or stderr. Defaults to <option>daemon</option>.</para></listitem>
3657 </varlistentry>
3658
3659 <varlistentry>
3660 <term><varname>SyslogLevel=</varname></term>
3661
3662 <listitem><para>The default <command>syslog</command> log level to use when logging to the logging system or
3663 the kernel log buffer. One of <option>emerg</option>, <option>alert</option>, <option>crit</option>,
3664 <option>err</option>, <option>warning</option>, <option>notice</option>, <option>info</option>,
3665 <option>debug</option>. See <citerefentry
3666 project='man-pages'><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
3667 details. This option is only useful when <varname>StandardOutput=</varname> or
3668 <varname>StandardError=</varname> are set to <option>journal</option> or
3669 <option>kmsg</option> (or to the same settings in combination with <option>+console</option>), and only applies
3670 to log messages written to stdout or stderr. Note that individual lines output by executed processes may be
3671 prefixed with a different log level which can be used to override the default log level specified here. The
3672 interpretation of these prefixes may be disabled with <varname>SyslogLevelPrefix=</varname>, see below. For
3673 details, see <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
3674 Defaults to <option>info</option>.</para></listitem>
3675 </varlistentry>
3676
3677 <varlistentry>
3678 <term><varname>SyslogLevelPrefix=</varname></term>
3679
3680 <listitem><para>Takes a boolean argument. If true and <varname>StandardOutput=</varname> or
3681 <varname>StandardError=</varname> are set to <option>journal</option> or <option>kmsg</option> (or to
3682 the same settings in combination with <option>+console</option>), log lines written by the executed
3683 process that are prefixed with a log level will be processed with this log level set but the prefix
3684 removed. If set to false, the interpretation of these prefixes is disabled and the logged lines are
3685 passed on as-is. This only applies to log messages written to stdout or stderr. For details about
3686 this prefixing see
3687 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
3688 Defaults to true.</para></listitem>
3689 </varlistentry>
3690
3691 <varlistentry>
3692 <term><varname>TTYPath=</varname></term>
3693
3694 <listitem><para>Sets the terminal device node to use if standard input, output, or error are connected to a TTY
3695 (see above). Defaults to <filename>/dev/console</filename>.</para></listitem>
3696 </varlistentry>
3697
3698 <varlistentry>
3699 <term><varname>TTYReset=</varname></term>
3700
3701 <listitem><para>Reset the terminal device specified with <varname>TTYPath=</varname> before and after
3702 execution. This does not erase the screen (see <varname>TTYVTDisallocate=</varname> below for
3703 that). Defaults to <literal>no</literal>.</para></listitem>
3704 </varlistentry>
3705
3706 <varlistentry>
3707 <term><varname>TTYVHangup=</varname></term>
3708
3709 <listitem><para>Disconnect all clients which have opened the terminal device specified with
3710 <varname>TTYPath=</varname> before and after execution. Defaults to <literal>no</literal>.</para></listitem>
3711 </varlistentry>
3712
3713 <varlistentry>
3714 <term><varname>TTYColumns=</varname></term>
3715 <term><varname>TTYRows=</varname></term>
3716
3717 <listitem><para>Configure the size of the TTY specified with <varname>TTYPath=</varname>. If unset or
3718 set to the empty string, it is attempted to retrieve the dimensions of the terminal screen via ANSI
3719 sequences, and if that fails the kernel defaults (typically 80x24) are used.</para>
3720
3721 <xi:include href="version-info.xml" xpointer="v250"/></listitem>
3722 </varlistentry>
3723
3724 <varlistentry>
3725 <term><varname>TTYVTDisallocate=</varname></term>
3726
3727 <listitem><para>If the terminal device specified with <varname>TTYPath=</varname> is a virtual
3728 console terminal, try to deallocate the TTY before and after execution. This ensures that the screen
3729 and scrollback buffer is cleared. If the terminal device is of any other type of TTY an attempt is
3730 made to clear the screen via ANSI sequences. Defaults to <literal>no</literal>.</para></listitem>
3731 </varlistentry>
3732 </variablelist>
3733 </refsect1>
3734
3735 <refsect1>
3736 <title>Credentials</title>
3737
3738 <variablelist class='unit-directives'>
3739
3740 <varlistentry>
3741 <term><varname>LoadCredential=</varname><replaceable>ID</replaceable><optional>:<replaceable>PATH</replaceable></optional></term>
3742 <term><varname>LoadCredentialEncrypted=</varname><replaceable>ID</replaceable><optional>:<replaceable>PATH</replaceable></optional></term>
3743
3744 <listitem><para>Pass a credential to the unit. Credentials are limited-size binary or textual objects
3745 that may be passed to unit processes. They are primarily intended for passing cryptographic keys
3746 (both public and private) or certificates, user account information or identity information from host
3747 to services, but can be freely used to pass any kind of limited-size information to a service. The
3748 data is accessible from the unit's processes via the file system, at a read-only location that (if
3749 possible and permitted) is backed by non-swappable memory. The data is only accessible to the user
3750 associated with the unit, via the <varname>User=</varname>/<varname>DynamicUser=</varname> settings
3751 (as well as the superuser). When available, the location of credentials is exported as the
3752 <varname>$CREDENTIALS_DIRECTORY</varname> environment variable to the unit's processes.</para>
3753
3754 <para>The <varname>LoadCredential=</varname> setting takes a textual ID to use as name for a
3755 credential plus a file system path, separated by a colon. The ID must be a short ASCII string
3756 suitable as filename in the filesystem, and may be chosen freely by the user. If the specified path
3757 is absolute it is opened as regular file and the credential data is read from it. If the absolute
3758 path refers to an <constant>AF_UNIX</constant> stream socket in the file system a connection is made
3759 to it (once at process invocation) and the credential data read from the connection, providing an
3760 easy IPC integration point for dynamically transferring credentials from other services.</para>
3761
3762 <para>If the specified path is not absolute and itself qualifies as valid credential identifier it is
3763 attempted to find a credential that the service manager itself received under the specified name —
3764 which may be used to propagate credentials from an invoking environment (e.g. a container manager
3765 that invoked the service manager) into a service. If no matching passed credential is found, the
3766 system service manager will search the directories <filename>/etc/credstore/</filename>,
3767 <filename>/run/credstore/</filename> and <filename>/usr/lib/credstore/</filename> for files under the
3768 credential's name — which hence are recommended locations for credential data on disk. If
3769 <varname>LoadCredentialEncrypted=</varname> is used <filename>/run/credstore.encrypted/</filename>,
3770 <filename>/etc/credstore.encrypted/</filename>, and
3771 <filename>/usr/lib/credstore.encrypted/</filename> are searched as well. The per-user service manager
3772 will search <filename>$XDG_CONFIG_HOME/credstore/</filename>,
3773 <filename>$XDG_RUNTIME_DIR/credstore/</filename>, <filename>$HOME/.local/lib/credstore/</filename>
3774 (and the counterparts ending with <filename>…/credstore.encrypted/</filename>) instead. The
3775 <citerefentry><refentrytitle>systemd-path</refentrytitle><manvolnum>1</manvolnum></citerefentry> tool
3776 may be used to query the precise credential store search path.</para>
3777
3778 <para>If the file system path is omitted it is chosen identical to the credential name, i.e. this is
3779 a terse way to declare credentials to inherit from the service manager or credstore directories into
3780 a service. This option may be used multiple times, each time defining an additional credential to
3781 pass to the unit.</para>
3782
3783 <para>Note that if the path is not specified or a valid credential identifier is given, i.e.
3784 in the above two cases, a missing credential is not considered fatal.</para>
3785
3786 <para>If an absolute path referring to a directory is specified, every file in that directory
3787 (recursively) will be loaded as a separate credential. The ID for each credential will be the
3788 provided ID suffixed with <literal>_$FILENAME</literal> (e.g., <literal>Key_file1</literal>). When
3789 loading from a directory, symlinks will be ignored.</para>
3790
3791 <para>The contents of the file/socket may be arbitrary binary or textual data, including newline
3792 characters and <constant>NUL</constant> bytes.</para>
3793
3794 <para>The <varname>LoadCredentialEncrypted=</varname> setting is identical to
3795 <varname>LoadCredential=</varname>, except that the credential data is decrypted and authenticated
3796 before being passed on to the executed processes. Specifically, the referenced path should refer to a
3797 file or socket with an encrypted credential, as implemented by
3798 <citerefentry><refentrytitle>systemd-creds</refentrytitle><manvolnum>1</manvolnum></citerefentry>. This
3799 credential is loaded, decrypted, authenticated and then passed to the application in plaintext form,
3800 in the same way a regular credential specified via <varname>LoadCredential=</varname> would be. A
3801 credential configured this way may be symmetrically encrypted/authenticated with a secret key derived
3802 from the system's TPM2 security chip, or with a secret key stored in
3803 <filename>/var/lib/systemd/credential.secret</filename>, or with both. Using encrypted and
3804 authenticated credentials improves security as credentials are not stored in plaintext and only
3805 authenticated and decrypted into plaintext the moment a service requiring them is started. Moreover,
3806 credentials may be bound to the local hardware and installations, so that they cannot easily be
3807 analyzed offline, or be generated externally. See
3808 <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
3809 for the details about <varname>DevicePolicy=</varname> or <varname>DeviceAllow=</varname>.</para>
3810
3811 <para>Note that encrypted credentials targeted for services of the per-user service manager must be
3812 encrypted with <command>systemd-creds encrypt --user</command>, and those for the system service
3813 manager without the <option>--user</option> switch. Encrypted credentials are always targeted to a
3814 specific user or the system as a whole, and it is ensured that per-user service managers cannot
3815 decrypt secrets intended for the system or for other users.</para>
3816
3817 <para>The credential files/IPC sockets must be accessible to the service manager, but do not have to
3818 be directly accessible to the unit's processes: the credential data is read and copied into separate,
3819 read-only copies for the unit that are accessible to appropriately privileged processes. This is
3820 particularly useful in combination with <varname>DynamicUser=</varname> as this way privileged data
3821 can be made available to processes running under a dynamic UID (i.e. not a previously known one)
3822 without having to open up access to all users.</para>
3823
3824 <para>In order to reference the path a credential may be read from within a
3825 <varname>ExecStart=</varname> command line use <literal>${CREDENTIALS_DIRECTORY}/mycred</literal>,
3826 e.g. <literal>ExecStart=cat ${CREDENTIALS_DIRECTORY}/mycred</literal>. In order to reference the path
3827 a credential may be read from within a <varname>Environment=</varname> line use
3828 <literal>%d/mycred</literal>, e.g. <literal>Environment=MYCREDPATH=%d/mycred</literal>. For system
3829 services the path may also be referenced as
3830 <literal>/run/credentials/<replaceable>UNITNAME</replaceable></literal> in cases where no
3831 interpolation is possible, e.g. configuration files of software that does not yet support credentials
3832 natively. <varname>$CREDENTIALS_DIRECTORY</varname> is considered the primary interface to look for
3833 credentials, though, since it also works for user services.</para>
3834
3835 <para>Currently, an accumulated credential size limit of 1 MB per unit is enforced.</para>
3836
3837 <para>The service manager itself may receive system credentials that can be propagated to services
3838 from a hosting container manager or VM hypervisor. See the <ulink
3839 url="https://systemd.io/CONTAINER_INTERFACE">Container Interface</ulink> documentation for details
3840 about the former. For the latter, pass <ulink
3841 url="https://www.dmtf.org/standards/smbios">DMI/SMBIOS</ulink> OEM string table entries (field type
3842 11) with a prefix of <literal>io.systemd.credential:</literal> or
3843 <literal>io.systemd.credential.binary:</literal>. In both cases a key/value pair separated by
3844 <literal>=</literal> is expected. In the latter case, the right-hand side is Base64 decoded when
3845 parsed (thus permitting binary data to be passed in). Example <ulink
3846 url="https://www.qemu.org/docs/master/system/index.html">qemu</ulink> switch: <literal>-smbios
3847 type=11,value=io.systemd.credential:xx=yy</literal>, or <literal>-smbios
3848 type=11,value=io.systemd.credential.binary:rick=TmV2ZXIgR29ubmEgR2l2ZSBZb3UgVXA=</literal>. Alternatively,
3849 use the <command>qemu</command> <literal>fw_cfg</literal> node
3850 <literal>opt/io.systemd.credentials/</literal>. Example <command>qemu</command> switch:
3851 <literal>-fw_cfg name=opt/io.systemd.credentials/mycred,string=supersecret</literal>. They may also
3852 be passed from the UEFI firmware environment via
3853 <citerefentry><refentrytitle>systemd-stub</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
3854 from the initrd (see
3855 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>), or be
3856 specified on the kernel command line using the <literal>systemd.set_credential=</literal> and
3857 <literal>systemd.set_credential_binary=</literal> switches (see
3858 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> – this is
3859 not recommended since unprivileged userspace can read the kernel command line). </para>
3860
3861 <para>If referencing an <constant>AF_UNIX</constant> stream socket to connect to, the connection will
3862 originate from an abstract namespace socket, that includes information about the unit and the
3863 credential ID in its socket name. Use <citerefentry
3864 project='man-pages'><refentrytitle>getpeername</refentrytitle><manvolnum>2</manvolnum></citerefentry>
3865 to query this information. The returned socket name is formatted as <constant>NUL</constant>
3866 <replaceable>RANDOM</replaceable> <literal>/unit/</literal> <replaceable>UNIT</replaceable>
3867 <literal>/</literal> <replaceable>ID</replaceable>, i.e. a <constant>NUL</constant> byte (as required
3868 for abstract namespace socket names), followed by a random string (consisting of alphadecimal
3869 characters), followed by the literal string <literal>/unit/</literal>, followed by the requesting
3870 unit name, followed by the literal character <literal>/</literal>, followed by the textual credential
3871 ID requested. Example: <literal>\0adf9d86b6eda275e/unit/foobar.service/credx</literal> in case the
3872 credential <literal>credx</literal> is requested for a unit <literal>foobar.service</literal>. This
3873 functionality is useful for using a single listening socket to serve credentials to multiple
3874 consumers.</para>
3875
3876 <para>For further information see <ulink url="https://systemd.io/CREDENTIALS">System and Service
3877 Credentials</ulink> documentation.</para>
3878
3879 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
3880 </varlistentry>
3881
3882 <varlistentry>
3883 <term><varname>ImportCredential=</varname><replaceable>GLOB</replaceable></term>
3884
3885 <listitem><para>Pass one or more credentials to the unit. Takes a credential name for which we will
3886 attempt to find a credential that the service manager itself received under the specified name —
3887 which may be used to propagate credentials from an invoking environment (e.g. a container manager
3888 that invoked the service manager) into a service. If the credential name is a glob, all credentials
3889 matching the glob are passed to the unit. Matching credentials are searched for in the system
3890 credentials, the encrypted system credentials, and under <filename>/etc/credstore/</filename>,
3891 <filename>/run/credstore/</filename>, <filename>/usr/lib/credstore/</filename>,
3892 <filename>/run/credstore.encrypted/</filename>, <filename>/etc/credstore.encrypted/</filename>, and
3893 <filename>/usr/lib/credstore.encrypted/</filename> in that order. When multiple credentials of the
3894 same name are found, the first one found is used.</para>
3895
3896 <para>The globbing expression implements a restrictive subset of <citerefentry
3897 project='man-pages'><refentrytitle>glob</refentrytitle><manvolnum>7</manvolnum></citerefentry>: only
3898 a single trailing <literal>*</literal> wildcard may be specified. Both <literal>?</literal> and
3899 <literal>[]</literal> wildcards are not permitted, nor are <literal>*</literal> wildcards anywhere
3900 except at the end of the glob expression.</para>
3901
3902 <para>Optionally, the credential name or glob may be followed by a colon followed by a rename pattern.
3903 If specified, all credentials matching the credential name or glob are renamed according to the given
3904 pattern. For example, if <literal>ImportCredential=my.original.cred:my.renamed.cred</literal> is
3905 specified, the service manager will read the <literal>my.original.cred</literal> credential and make
3906 it available as the <literal>my.renamed.cred</literal> credential to the service. Similarly, if
3907 <literal>ImportCredential=my.original.*:my.renamed.</literal> is specified, the service manager will
3908 read all credentials starting with <literal>my.original.</literal> and make them available as
3909 <literal>my.renamed.xxx</literal> to the service.</para>
3910
3911 <para>If <varname>ImportCredential=</varname> is specified multiple times and multiple credentials
3912 end up with the same name after renaming, the first one is kept and later ones are dropped.</para>
3913
3914 <para>When multiple credentials of the same name are found, credentials found by
3915 <varname>LoadCredential=</varname> and <varname>LoadCredentialEncrypted=</varname> take priority over
3916 credentials found by <varname>ImportCredential=</varname>.</para>
3917
3918 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
3919 </varlistentry>
3920
3921 <varlistentry>
3922 <term><varname>SetCredential=</varname><replaceable>ID</replaceable>:<replaceable>VALUE</replaceable></term>
3923 <term><varname>SetCredentialEncrypted=</varname><replaceable>ID</replaceable>:<replaceable>VALUE</replaceable></term>
3924
3925 <listitem><para>The <varname>SetCredential=</varname> setting is similar to
3926 <varname>LoadCredential=</varname> but accepts a literal value to use as data for the credential,
3927 instead of a file system path to read the data from. Do not use this option for data that is supposed
3928 to be secret, as it is accessible to unprivileged processes via IPC. It's only safe to use this for
3929 user IDs, public key material and similar non-sensitive data. For everything else use
3930 <varname>LoadCredential=</varname>. In order to embed binary data into the credential data use
3931 C-style escaping (i.e. <literal>\n</literal> to embed a newline, or <literal>\x00</literal> to embed
3932 a <constant>NUL</constant> byte).</para>
3933
3934 <para>The <varname>SetCredentialEncrypted=</varname> setting is identical to
3935 <varname>SetCredential=</varname> but expects an encrypted credential in literal form as value. This
3936 allows embedding confidential credentials securely directly in unit files. Use
3937 <citerefentry><refentrytitle>systemd-creds</refentrytitle><manvolnum>1</manvolnum></citerefentry>'
3938 <option>-p</option> switch to generate suitable <varname>SetCredentialEncrypted=</varname> lines
3939 directly from plaintext credentials. For further details see
3940 <varname>LoadCredentialEncrypted=</varname> above.</para>
3941
3942 <para>When multiple credentials of the same name are found, credentials found by
3943 <varname>LoadCredential=</varname>, <varname>LoadCredentialEncrypted=</varname> and
3944 <varname>ImportCredential=</varname> take priority over credentials found by
3945 <varname>SetCredential=</varname>. As such, <varname>SetCredential=</varname> will act as default if
3946 no credentials are found by any of the former. In this case, not being able to retrieve the credential
3947 from the path specified in <varname>LoadCredential=</varname> or
3948 <varname>LoadCredentialEncrypted=</varname> is not considered fatal.</para>
3949
3950 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
3951 </varlistentry>
3952 </variablelist>
3953 </refsect1>
3954
3955 <refsect1>
3956 <title>System V Compatibility</title>
3957 <variablelist class='unit-directives'>
3958
3959 <varlistentry>
3960 <term><varname>UtmpIdentifier=</varname></term>
3961
3962 <listitem><para>Takes a four character identifier string for an <citerefentry
3963 project='man-pages'><refentrytitle>utmp</refentrytitle><manvolnum>5</manvolnum></citerefentry> and wtmp entry
3964 for this service. This should only be set for services such as <command>getty</command> implementations (such
3965 as <citerefentry
3966 project='die-net'><refentrytitle>agetty</refentrytitle><manvolnum>8</manvolnum></citerefentry>) where utmp/wtmp
3967 entries must be created and cleared before and after execution, or for services that shall be executed as if
3968 they were run by a <command>getty</command> process (see below). If the configured string is longer than four
3969 characters, it is truncated and the terminal four characters are used. This setting interprets %I style string
3970 replacements. This setting is unset by default, i.e. no utmp/wtmp entries are created or cleaned up for this
3971 service.</para></listitem>
3972 </varlistentry>
3973
3974 <varlistentry>
3975 <term><varname>UtmpMode=</varname></term>
3976
3977 <listitem><para>Takes one of <literal>init</literal>, <literal>login</literal> or <literal>user</literal>. If
3978 <varname>UtmpIdentifier=</varname> is set, controls which type of <citerefentry
3979 project='man-pages'><refentrytitle>utmp</refentrytitle><manvolnum>5</manvolnum></citerefentry>/wtmp entries
3980 for this service are generated. This setting has no effect unless <varname>UtmpIdentifier=</varname> is set
3981 too. If <literal>init</literal> is set, only an <constant>INIT_PROCESS</constant> entry is generated and the
3982 invoked process must implement a <command>getty</command>-compatible utmp/wtmp logic. If
3983 <literal>login</literal> is set, first an <constant>INIT_PROCESS</constant> entry, followed by a
3984 <constant>LOGIN_PROCESS</constant> entry is generated. In this case, the invoked process must implement a
3985 <citerefentry
3986 project='die-net'><refentrytitle>login</refentrytitle><manvolnum>1</manvolnum></citerefentry>-compatible
3987 utmp/wtmp logic. If <literal>user</literal> is set, first an <constant>INIT_PROCESS</constant> entry, then a
3988 <constant>LOGIN_PROCESS</constant> entry and finally a <constant>USER_PROCESS</constant> entry is
3989 generated. In this case, the invoked process may be any process that is suitable to be run as session
3990 leader. Defaults to <literal>init</literal>.</para>
3991
3992 <xi:include href="version-info.xml" xpointer="v225"/></listitem>
3993 </varlistentry>
3994
3995 </variablelist>
3996 </refsect1>
3997
3998 <refsect1>
3999 <title>Environment Variables in Spawned Processes</title>
4000
4001 <para>Processes started by the service manager are executed with an environment variable block assembled from
4002 multiple sources. Processes started by the system service manager generally do not inherit environment variables
4003 set for the service manager itself (but this may be altered via <varname>PassEnvironment=</varname>), but processes
4004 started by the user service manager instances generally do inherit all environment variables set for the service
4005 manager itself.</para>
4006
4007 <para>For each invoked process the list of environment variables set is compiled from the following sources:</para>
4008
4009 <itemizedlist>
4010 <listitem><para>Variables globally configured for the service manager, using the
4011 <varname>DefaultEnvironment=</varname> setting in
4012 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
4013 the kernel command line option <varname>systemd.setenv=</varname> understood by
4014 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, or via
4015 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
4016 <command>set-environment</command> verb.</para></listitem>
4017
4018 <listitem><para>Variables defined by the service manager itself (see the list below).</para></listitem>
4019
4020 <listitem><para>Variables set in the service manager's own environment variable block (subject to
4021 <varname>PassEnvironment=</varname> for the system service manager).</para></listitem>
4022
4023 <listitem><para>Variables set via <varname>Environment=</varname> in the unit file.</para></listitem>
4024
4025 <listitem><para>Variables read from files specified via <varname>EnvironmentFile=</varname> in the unit
4026 file.</para></listitem>
4027
4028 <listitem><para>Variables set by any PAM modules in case <varname>PAMName=</varname> is in effect,
4029 cf. <citerefentry
4030 project='man-pages'><refentrytitle>pam_env</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
4031 </para></listitem>
4032 </itemizedlist>
4033
4034 <para>If the same environment variable is set by multiple of these sources, the later source — according
4035 to the order of the list above — wins. Note that as the final step all variables listed in
4036 <varname>UnsetEnvironment=</varname> are removed from the compiled environment variable list, immediately
4037 before it is passed to the executed process.</para>
4038
4039 <para>The general philosophy is to expose a small curated list of environment variables to processes.
4040 Services started by the system manager (PID 1) will be started, without additional service-specific
4041 configuration, with just a few environment variables. The user manager inherits environment variables as
4042 any other system service, but in addition may receive additional environment variables from PAM, and,
4043 typically, additional imported variables when the user starts a graphical session. It is recommended to
4044 keep the environment blocks in both the system and user managers lean. Importing all variables
4045 inherited by the graphical session or by one of the user shells is strongly discouraged.</para>
4046
4047 <para>Hint: <command>systemd-run -P env</command> and <command>systemd-run --user -P env</command> print
4048 the effective system and user service environment blocks.</para>
4049
4050 <refsect2>
4051 <title>Environment Variables Set or Propagated by the Service Manager</title>
4052
4053 <para>The following environment variables are propagated by the service manager or generated internally
4054 for each invoked process:</para>
4055
4056 <variablelist class='environment-variables'>
4057 <varlistentry>
4058 <term><varname>$PATH</varname></term>
4059
4060 <listitem><para>Colon-separated list of directories to use when launching
4061 executables. <command>systemd</command> uses a fixed value of
4062 <literal><filename>/usr/local/sbin</filename>:<filename>/usr/local/bin</filename>:<filename>/usr/sbin</filename>:<filename>/usr/bin</filename></literal>
4063 in the system manager. In case of the user manager, a different path may be configured by the
4064 distribution. It is recommended to not rely on the order of entries, and have only one program
4065 with a given name in <varname>$PATH</varname>.</para>
4066
4067 <xi:include href="version-info.xml" xpointer="v208"/></listitem>
4068 </varlistentry>
4069
4070 <varlistentry>
4071 <term><varname>$LANG</varname></term>
4072
4073 <listitem><para>Locale. Can be set in <citerefentry
4074 project='man-pages'><refentrytitle>locale.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
4075 or on the kernel command line (see
4076 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> and
4077 <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
4078 </para>
4079
4080 <xi:include href="version-info.xml" xpointer="v208"/></listitem>
4081 </varlistentry>
4082
4083 <varlistentry>
4084 <term><varname>$USER</varname></term>
4085 <term><varname>$LOGNAME</varname></term>
4086 <term><varname>$HOME</varname></term>
4087 <term><varname>$SHELL</varname></term>
4088
4089 <listitem><para>User name (twice), home directory, and the login shell. <varname>$USER</varname> is
4090 set unconditionally, while <varname>$HOME</varname>, <varname>$LOGNAME</varname>, and <varname>$SHELL</varname>
4091 are only set for the units that have <varname>User=</varname> set and <varname>SetLoginEnvironment=</varname>
4092 unset or set to true. For user services, these variables are typically inherited from the user manager itself. See
4093 <citerefentry project='die-net'><refentrytitle>passwd</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
4094 </para>
4095
4096 <xi:include href="version-info.xml" xpointer="v208"/></listitem>
4097 </varlistentry>
4098
4099 <varlistentry>
4100 <term><varname>$INVOCATION_ID</varname></term>
4101
4102 <listitem><para>Contains a randomized, unique 128-bit ID identifying each runtime cycle of the unit, formatted
4103 as 32 character hexadecimal string. A new ID is assigned each time the unit changes from an inactive state into
4104 an activating or active state, and may be used to identify this specific runtime cycle, in particular in data
4105 stored offline, such as the journal. The same ID is passed to all processes run as part of the
4106 unit.</para>
4107
4108 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
4109 </varlistentry>
4110
4111 <varlistentry>
4112 <term><varname>$XDG_RUNTIME_DIR</varname></term>
4113
4114 <listitem><para>The directory to use for runtime objects (such as IPC objects) and volatile state. Set for all
4115 services run by the user <command>systemd</command> instance, as well as any system services that use
4116 <varname>PAMName=</varname> with a PAM stack that includes <command>pam_systemd</command>. See below and
4117 <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> for more
4118 information.</para>
4119
4120 <xi:include href="version-info.xml" xpointer="v208"/></listitem>
4121 </varlistentry>
4122
4123 <varlistentry>
4124 <term><varname>$RUNTIME_DIRECTORY</varname></term>
4125 <term><varname>$STATE_DIRECTORY</varname></term>
4126 <term><varname>$CACHE_DIRECTORY</varname></term>
4127 <term><varname>$LOGS_DIRECTORY</varname></term>
4128 <term><varname>$CONFIGURATION_DIRECTORY</varname></term>
4129
4130 <listitem><para>Absolute paths to the directories defined with
4131 <varname>RuntimeDirectory=</varname>, <varname>StateDirectory=</varname>,
4132 <varname>CacheDirectory=</varname>, <varname>LogsDirectory=</varname>, and
4133 <varname>ConfigurationDirectory=</varname> when those settings are used.</para>
4134
4135 <xi:include href="version-info.xml" xpointer="v244"/>
4136 </listitem>
4137 </varlistentry>
4138
4139 <varlistentry>
4140 <term><varname>$CREDENTIALS_DIRECTORY</varname></term>
4141
4142 <listitem><para>An absolute path to the per-unit directory with credentials configured via
4143 <varname>ImportCredential=</varname>/<varname>LoadCredential=</varname>/<varname>SetCredential=</varname>.
4144 The directory is marked read-only and is placed in unswappable memory (if supported and permitted),
4145 and is only accessible to the UID associated with the unit via <varname>User=</varname> or
4146 <varname>DynamicUser=</varname> (and the superuser).</para>
4147
4148 <xi:include href="version-info.xml" xpointer="v247"/></listitem>
4149 </varlistentry>
4150
4151 <varlistentry>
4152 <term><varname>$TMPDIR</varname></term>
4153
4154 <listitem><para>The environment variable is set to <literal>/tmp</literal> when
4155 <varname>PrivateTmp=disconnected</varname> specified with <varname>DefaultDependencies=no</varname>
4156 and without <varname>RootDirectory=/RootImage=</varname> and
4157 <varname>RequiresMountsFor=/WantsMountsFor=</varname> for <filename>/var/</filename>.
4158 See explanation for <varname>PrivateTmp=</varname> above.</para>
4159
4160 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
4161 </varlistentry>
4162
4163 <varlistentry>
4164 <term><varname>$MAINPID</varname></term>
4165
4166 <listitem><para>The UNIX process ID (PID) of the unit's main process if it is known. This is only
4167 set for control processes as invoked by <varname>ExecReload=</varname> and similar.</para>
4168
4169 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
4170 </varlistentry>
4171
4172 <varlistentry>
4173 <term><varname>$MAINPIDFDID</varname></term>
4174
4175 <listitem><para>The 64bit inode ID of the file descriptor returned by <citerefentry
4176 project='man-pages'><refentrytitle>pidfd_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>
4177 for the main process (if supported). This is only set for control processes as invoked by
4178 <varname>ExecReload=</varname> and similar.</para>
4179
4180 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
4181 </varlistentry>
4182
4183 <varlistentry>
4184 <term><varname>$MANAGERPID</varname></term>
4185
4186 <listitem><para>The PID of the per-user <command>systemd</command> service manager instance, set
4187 for processes spawned by it.</para>
4188 <xi:include href="version-info.xml" xpointer="v208"/></listitem>
4189 </varlistentry>
4190
4191 <varlistentry>
4192 <term><varname>$MANAGERPIDFDID</varname></term>
4193
4194 <listitem><para>The <function>pidfd_open()</function> inode ID (see above) of the per-user
4195 <command>systemd</command> service manager instance, set for processes spawned by it.</para>
4196
4197 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
4198 </varlistentry>
4199
4200 <varlistentry>
4201 <term><varname>$LISTEN_FDS</varname></term>
4202 <term><varname>$LISTEN_PID</varname></term>
4203 <term><varname>$LISTEN_FDNAMES</varname></term>
4204
4205 <listitem><para>Information about file descriptors passed to a
4206 service for socket activation. See
4207 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
4208 </para>
4209
4210 <xi:include href="version-info.xml" xpointer="v208"/></listitem>
4211 </varlistentry>
4212
4213 <varlistentry>
4214 <term><varname>$NOTIFY_SOCKET</varname></term>
4215
4216 <listitem><para>The socket <function>sd_notify()</function> talks to. See
4217 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
4218 </para>
4219
4220 <xi:include href="version-info.xml" xpointer="v229"/></listitem>
4221 </varlistentry>
4222
4223 <varlistentry>
4224 <term><varname>$WATCHDOG_PID</varname></term>
4225 <term><varname>$WATCHDOG_USEC</varname></term>
4226
4227 <listitem><para>Information about watchdog keep-alive notifications. See
4228 <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
4229 </para>
4230
4231 <xi:include href="version-info.xml" xpointer="v229"/></listitem>
4232 </varlistentry>
4233
4234 <varlistentry>
4235 <term><varname>$SYSTEMD_EXEC_PID</varname></term>
4236
4237 <listitem><para>The PID of the unit process (e.g. process invoked by
4238 <varname>ExecStart=</varname>). The child process can use this information to determine
4239 whether the process is directly invoked by the service manager or indirectly as a child of
4240 another process by comparing this value with the current PID (similarly to the scheme used in
4241 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
4242 with <varname>$LISTEN_PID</varname> and <varname>$LISTEN_FDS</varname>).</para>
4243
4244 <xi:include href="version-info.xml" xpointer="v248"/></listitem>
4245 </varlistentry>
4246
4247 <varlistentry>
4248 <term><varname>$TERM</varname></term>
4249
4250 <listitem><para>Terminal type, set only for units connected to
4251 a terminal (<varname>StandardInput=tty</varname>,
4252 <varname>StandardOutput=tty</varname>, or
4253 <varname>StandardError=tty</varname>). See
4254 <citerefentry project='man-pages'><refentrytitle>termcap</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
4255 </para>
4256
4257 <xi:include href="version-info.xml" xpointer="v209"/></listitem>
4258 </varlistentry>
4259
4260 <varlistentry>
4261 <term><varname>$LOG_NAMESPACE</varname></term>
4262
4263 <listitem><para>Contains the name of the selected logging namespace when the
4264 <varname>LogNamespace=</varname> service setting is used.</para>
4265
4266 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
4267 </varlistentry>
4268
4269 <varlistentry>
4270 <term><varname>$JOURNAL_STREAM</varname></term>
4271
4272 <listitem><para>If the standard output or standard error output of the executed processes are connected to the
4273 journal (for example, by setting <varname>StandardError=journal</varname>) <varname>$JOURNAL_STREAM</varname>
4274 contains the device and inode numbers of the connection file descriptor, formatted in decimal, separated by a
4275 colon (<literal>:</literal>). This permits invoked processes to safely detect whether their standard output or
4276 standard error output are connected to the journal. The device and inode numbers of the file descriptors should
4277 be compared with the values set in the environment variable to determine whether the process output is still
4278 connected to the journal. Note that it is generally not sufficient to only check whether
4279 <varname>$JOURNAL_STREAM</varname> is set at all as services might invoke external processes replacing their
4280 standard output or standard error output, without unsetting the environment variable.</para>
4281
4282 <para>If both standard output and standard error of the executed processes are connected to the journal via a
4283 stream socket, this environment variable will contain information about the standard error stream, as that's
4284 usually the preferred destination for log data. (Note that typically the same stream is used for both standard
4285 output and standard error, hence very likely the environment variable contains device and inode information
4286 matching both stream file descriptors.)</para>
4287
4288 <para>This environment variable is primarily useful to allow services to optionally upgrade their used log
4289 protocol to the native journal protocol (using
4290 <citerefentry><refentrytitle>sd_journal_print</refentrytitle><manvolnum>3</manvolnum></citerefentry> and other
4291 functions) if their standard output or standard error output is connected to the journal anyway, thus enabling
4292 delivery of structured metadata along with logged messages.</para>
4293
4294 <xi:include href="version-info.xml" xpointer="v231"/></listitem>
4295 </varlistentry>
4296
4297 <varlistentry>
4298 <term><varname>$SERVICE_RESULT</varname></term>
4299
4300 <listitem><para>Only used for the service unit type. This environment variable is passed to all
4301 <varname>ExecStop=</varname> and <varname>ExecStopPost=</varname> processes, and encodes the service
4302 "result". Currently, the following values are defined:</para>
4303
4304 <table>
4305 <title>Defined <varname>$SERVICE_RESULT</varname> values</title>
4306 <tgroup cols='2'>
4307 <colspec colname='result'/>
4308 <colspec colname='meaning'/>
4309 <thead>
4310 <row>
4311 <entry>Value</entry>
4312 <entry>Meaning</entry>
4313 </row>
4314 </thead>
4315
4316 <tbody>
4317 <row>
4318 <entry><literal>success</literal></entry>
4319 <entry>The service ran successfully and exited cleanly.</entry>
4320 </row>
4321 <row>
4322 <entry><literal>protocol</literal></entry>
4323 <entry>A protocol violation occurred: the service did not take the steps required by its unit configuration (specifically what is configured in its <varname>Type=</varname> setting).</entry>
4324 </row>
4325 <row>
4326 <entry><literal>timeout</literal></entry>
4327 <entry>One of the steps timed out.</entry>
4328 </row>
4329 <row>
4330 <entry><literal>exit-code</literal></entry>
4331 <entry>Service process exited with a non-zero exit code; see <varname>$EXIT_CODE</varname> below for the actual exit code returned.</entry>
4332 </row>
4333 <row>
4334 <entry><literal>signal</literal></entry>
4335 <entry>A service process was terminated abnormally by a signal, without dumping core. See <varname>$EXIT_CODE</varname> below for the actual signal causing the termination.</entry>
4336 </row>
4337 <row>
4338 <entry><literal>core-dump</literal></entry>
4339 <entry>A service process terminated abnormally with a signal and dumped core. See <varname>$EXIT_CODE</varname> below for the signal causing the termination.</entry>
4340 </row>
4341 <row>
4342 <entry><literal>watchdog</literal></entry>
4343 <entry>Watchdog keep-alive ping was enabled for the service, but the deadline was missed.</entry>
4344 </row>
4345 <row>
4346 <entry><literal>exec-condition</literal></entry>
4347 <entry>Service did not run because <varname>ExecCondition=</varname> failed.</entry>
4348 </row>
4349 <row>
4350 <entry><literal>oom-kill</literal></entry>
4351 <entry>A service process was terminated by the Out-Of-Memory (OOM) killer.</entry>
4352 </row>
4353 <row>
4354 <entry><literal>start-limit-hit</literal></entry>
4355 <entry>A start limit was defined for the unit and it was hit, causing the unit to fail to start. See <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>'s <varname>StartLimitIntervalSec=</varname> and <varname>StartLimitBurst=</varname> for details.</entry>
4356 </row>
4357 <row>
4358 <entry><literal>resources</literal></entry>
4359 <entry>A catch-all condition in case a system operation failed.</entry>
4360 </row>
4361 </tbody>
4362 </tgroup>
4363 </table>
4364
4365 <para>This environment variable is useful to monitor failure or successful termination of a service. Even
4366 though this variable is available in both <varname>ExecStop=</varname> and <varname>ExecStopPost=</varname>, it
4367 is usually a better choice to place monitoring tools in the latter, as the former is only invoked for services
4368 that managed to start up correctly, and the latter covers both services that failed during their start-up and
4369 those which failed during their runtime.</para>
4370
4371 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
4372 </varlistentry>
4373
4374 <varlistentry>
4375 <term><varname>$EXIT_CODE</varname></term>
4376 <term><varname>$EXIT_STATUS</varname></term>
4377
4378 <listitem><para>Only defined for the service unit type. These environment variables are passed to all
4379 <varname>ExecStop=</varname>, <varname>ExecStopPost=</varname> processes and contain exit status/code
4380 information of the main process of the service. For the precise definition of the exit code and status, see
4381 <citerefentry><refentrytitle>wait</refentrytitle><manvolnum>2</manvolnum></citerefentry>. <varname>$EXIT_CODE</varname>
4382 is one of <literal>exited</literal>, <literal>killed</literal>,
4383 <literal>dumped</literal>. <varname>$EXIT_STATUS</varname> contains the numeric exit code formatted as string
4384 if <varname>$EXIT_CODE</varname> is <literal>exited</literal>, and the signal name in all other cases. Note
4385 that these environment variables are only set if the service manager succeeded to start and identify the main
4386 process of the service.</para>
4387
4388 <table>
4389 <title>Summary of possible service result variable values</title>
4390 <tgroup cols='3'>
4391 <colspec colname='result' />
4392 <colspec colname='code' />
4393 <colspec colname='status' />
4394 <thead>
4395 <row>
4396 <entry><varname>$SERVICE_RESULT</varname></entry>
4397 <entry><varname>$EXIT_CODE</varname></entry>
4398 <entry><varname>$EXIT_STATUS</varname></entry>
4399 </row>
4400 </thead>
4401
4402 <tbody>
4403 <row>
4404 <entry morerows="1" valign="top"><literal>success</literal></entry>
4405 <entry valign="top"><literal>killed</literal></entry>
4406 <entry><literal>HUP</literal>, <literal>INT</literal>, <literal>TERM</literal>, <literal>PIPE</literal></entry>
4407 </row>
4408 <row>
4409 <entry valign="top"><literal>exited</literal></entry>
4410 <entry><literal>0</literal></entry>
4411 </row>
4412 <row>
4413 <entry morerows="1" valign="top"><literal>protocol</literal></entry>
4414 <entry valign="top">not set</entry>
4415 <entry>not set</entry>
4416 </row>
4417 <row>
4418 <entry><literal>exited</literal></entry>
4419 <entry><literal>0</literal></entry>
4420 </row>
4421 <row>
4422 <entry morerows="1" valign="top"><literal>timeout</literal></entry>
4423 <entry valign="top"><literal>killed</literal></entry>
4424 <entry><literal>TERM</literal>, <literal>KILL</literal></entry>
4425 </row>
4426 <row>
4427 <entry valign="top"><literal>exited</literal></entry>
4428 <entry><literal>0</literal>, <literal>1</literal>, <literal>2</literal>, <literal
4429 >3</literal>, …, <literal>255</literal></entry>
4430 </row>
4431 <row>
4432 <entry valign="top"><literal>exit-code</literal></entry>
4433 <entry valign="top"><literal>exited</literal></entry>
4434 <entry><literal>1</literal>, <literal>2</literal>, <literal
4435 >3</literal>, …, <literal>255</literal></entry>
4436 </row>
4437 <row>
4438 <entry valign="top"><literal>signal</literal></entry>
4439 <entry valign="top"><literal>killed</literal></entry>
4440 <entry><literal>HUP</literal>, <literal>INT</literal>, <literal>KILL</literal>, …</entry>
4441 </row>
4442 <row>
4443 <entry valign="top"><literal>core-dump</literal></entry>
4444 <entry valign="top"><literal>dumped</literal></entry>
4445 <entry><literal>ABRT</literal>, <literal>SEGV</literal>, <literal>QUIT</literal>, …</entry>
4446 </row>
4447 <row>
4448 <entry morerows="2" valign="top"><literal>watchdog</literal></entry>
4449 <entry><literal>dumped</literal></entry>
4450 <entry><literal>ABRT</literal></entry>
4451 </row>
4452 <row>
4453 <entry><literal>killed</literal></entry>
4454 <entry><literal>TERM</literal>, <literal>KILL</literal></entry>
4455 </row>
4456 <row>
4457 <entry><literal>exited</literal></entry>
4458 <entry><literal>0</literal>, <literal>1</literal>, <literal>2</literal>, <literal
4459 >3</literal>, …, <literal>255</literal></entry>
4460 </row>
4461 <row>
4462 <entry valign="top"><literal>exec-condition</literal></entry>
4463 <entry><literal>exited</literal></entry>
4464 <entry><literal>1</literal>, <literal>2</literal>, <literal>3</literal>, <literal
4465 >4</literal>, …, <literal>254</literal></entry>
4466 </row>
4467 <row>
4468 <entry valign="top"><literal>oom-kill</literal></entry>
4469 <entry valign="top"><literal>killed</literal></entry>
4470 <entry><literal>TERM</literal>, <literal>KILL</literal></entry>
4471 </row>
4472 <row>
4473 <entry><literal>start-limit-hit</literal></entry>
4474 <entry>not set</entry>
4475 <entry>not set</entry>
4476 </row>
4477 <row>
4478 <entry><literal>resources</literal></entry>
4479 <entry>any of the above</entry>
4480 <entry>any of the above</entry>
4481 </row>
4482 <row>
4483 <entry namest="results" nameend="status">Note: the process may be also terminated by a signal not sent by systemd. In particular the process may send an arbitrary signal to itself in a handler for any of the non-maskable signals. Nevertheless, in the <literal>timeout</literal> and <literal>watchdog</literal> rows above only the signals that systemd sends have been included. Moreover, using <varname>SuccessExitStatus=</varname> additional exit statuses may be declared to indicate clean termination, which is not reflected by this table.</entry>
4484 </row>
4485 </tbody>
4486 </tgroup>
4487 </table>
4488
4489 <xi:include href="version-info.xml" xpointer="v232"/></listitem>
4490 </varlistentry>
4491
4492 <varlistentry>
4493 <term><varname>$MONITOR_SERVICE_RESULT</varname></term>
4494 <term><varname>$MONITOR_EXIT_CODE</varname></term>
4495 <term><varname>$MONITOR_EXIT_STATUS</varname></term>
4496 <term><varname>$MONITOR_INVOCATION_ID</varname></term>
4497 <term><varname>$MONITOR_UNIT</varname></term>
4498
4499 <listitem><para>Only defined for the service unit type. Those environment variables are passed to
4500 all <varname>ExecStart=</varname> and <varname>ExecStartPre=</varname> processes which run in
4501 services triggered by <varname>OnFailure=</varname> or <varname>OnSuccess=</varname> dependencies.
4502 </para>
4503
4504 <para>Variables <varname>$MONITOR_SERVICE_RESULT</varname>, <varname>$MONITOR_EXIT_CODE</varname>
4505 and <varname>$MONITOR_EXIT_STATUS</varname> take the same values as for
4506 <varname>ExecStop=</varname> and <varname>ExecStopPost=</varname> processes. Variables
4507 <varname>$MONITOR_INVOCATION_ID</varname> and <varname>$MONITOR_UNIT</varname> are set to the
4508 invocation id and unit name of the service which triggered the dependency.</para>
4509
4510 <para>Note that when multiple services specify the same unit as their
4511 <varname>OnFailure=</varname> or <varname>OnSuccess=</varname> handler, those variables will
4512 <emphasis>not</emphasis> be passed. Consider using a template handler unit for that case instead:
4513 <literal>OnFailure=<replaceable>handler</replaceable>@%n.service</literal> for non-templated units,
4514 or <literal>OnFailure=<replaceable>handler</replaceable>@%p-%i.service</literal> for templated
4515 units.</para>
4516
4517 <xi:include href="version-info.xml" xpointer="v251"/></listitem>
4518 </varlistentry>
4519
4520 <varlistentry>
4521 <term><varname>$PIDFILE</varname></term>
4522
4523 <listitem><para>The path to the configured PID file, in case the process is forked off on behalf of
4524 a service that uses the <varname>PIDFile=</varname> setting, see
4525 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
4526 for details. Service code may use this environment variable to automatically generate a PID file at
4527 the location configured in the unit file. This field is set to an absolute path in the file
4528 system.</para>
4529
4530 <xi:include href="version-info.xml" xpointer="v242"/></listitem>
4531 </varlistentry>
4532
4533 <varlistentry>
4534 <term><varname>$REMOTE_ADDR</varname></term>
4535 <term><varname>$REMOTE_PORT</varname></term>
4536
4537 <listitem><para>If this is a unit started via per-connection socket activation (i.e. via a socket
4538 unit with <varname>Accept=yes</varname>), these environment variables contain information about the
4539 remote peer of the socket connection.</para>
4540
4541 <para>For IPv4 and IPv6 connections, <varname>$REMOTE_ADDR</varname> contains the IP address, and
4542 <varname>$REMOTE_PORT</varname> contains the port number of the remote peer.</para>
4543
4544 <para>For <constant>AF_UNIX</constant> socket connections, <varname>$REMOTE_ADDR</varname> contains
4545 either the remote socket's file system path starting with a slash (<literal>/</literal>), its
4546 address in the abstract namespace starting with an at symbol (<literal>@</literal>), or is unset
4547 in case of an unnamed socket. <varname>$REMOTE_PORT</varname> is not set for <constant>AF_UNIX</constant>
4548 sockets.</para>
4549
4550 <xi:include href="version-info.xml" xpointer="v220"/></listitem>
4551 </varlistentry>
4552
4553 <varlistentry>
4554 <term><varname>$SO_COOKIE</varname></term>
4555
4556 <listitem><para>If this is a unit started via per-connection socket activation (i.e. via a socket
4557 unit with <varname>Accept=yes</varname>), this environment variable contains the Linux socket
4558 cookie, formatted as decimal integer. The socket cookie can otherwise be acquired via <citerefentry
4559 project='man-pages'><refentrytitle>getsockopt</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
4560
4561 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
4562 </varlistentry>
4563
4564 <varlistentry>
4565 <term><varname>$TRIGGER_UNIT</varname></term>
4566 <term><varname>$TRIGGER_PATH</varname></term>
4567 <term><varname>$TRIGGER_TIMER_REALTIME_USEC</varname></term>
4568 <term><varname>$TRIGGER_TIMER_MONOTONIC_USEC</varname></term>
4569
4570 <listitem><para>If the unit was activated dynamically (e.g.: a corresponding path unit or timer unit), the
4571 unit that triggered it and other type-dependent information will be passed via these variables. Note that
4572 this information is provided in a best-effort way. For example, multiple triggers happening one after
4573 another will be coalesced and only one will be reported, with no guarantee as to which one it will be.
4574 Because of this, in most cases this variable will be primarily informational, i.e. useful for debugging
4575 purposes, is lossy, and should not be relied upon to propagate a comprehensive reason for activation.
4576 </para>
4577
4578 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
4579 </varlistentry>
4580
4581 <varlistentry>
4582 <term><varname>$MEMORY_PRESSURE_WATCH</varname></term>
4583 <term><varname>$MEMORY_PRESSURE_WRITE</varname></term>
4584
4585 <listitem><para>If memory pressure monitoring is enabled for this service unit, the path to watch
4586 and the data to write into it. See <ulink url="https://systemd.io/MEMORY_PRESSURE">Memory Pressure
4587 Handling</ulink> for details about these variables and the service protocol data they
4588 convey.</para>
4589
4590 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
4591 </varlistentry>
4592
4593 <varlistentry>
4594 <term><varname>$FDSTORE</varname></term>
4595
4596 <listitem><para>The maximum number of file descriptors that may be stored in the manager for the
4597 service. This variable is set when the file descriptor store is enabled for the service, i.e.
4598 <varname>FileDescriptorStoreMax=</varname> is set to a non-zero value (see
4599 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
4600 for details). Applications may check this environment variable before sending file descriptors to
4601 the service manager via
4602 <citerefentry><refentrytitle>sd_pid_notify_with_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
4603 </para>
4604
4605 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
4606 </varlistentry>
4607
4608 <varlistentry>
4609 <term><varname>$DEBUG_INVOCATION</varname></term>
4610
4611 <listitem><para>If <varname>RestartMode=debug</varname> is set, and a previous attempt at starting
4612 the unit failed, this variable will be passed to the service to indicate that additional logging
4613 should be enabled at startup. See
4614 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
4615 for more details.</para>
4616
4617 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
4618 </varlistentry>
4619
4620 </variablelist>
4621
4622 <para>For system services, when <varname>PAMName=</varname> is enabled and <command>pam_systemd</command> is part
4623 of the selected PAM stack, additional environment variables defined by systemd may be set for
4624 services. Specifically, these are <varname>$XDG_SEAT</varname>, <varname>$XDG_VTNR</varname>, see
4625 <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> for details.</para>
4626 </refsect2>
4627
4628 </refsect1>
4629
4630 <refsect1>
4631 <title>Process Exit Codes</title>
4632
4633 <para>When invoking a unit process the service manager possibly fails to apply the execution parameters configured
4634 with the settings above. In that case the already created service process will exit with a non-zero exit code
4635 before the configured command line is executed. (Or in other words, the child process possibly exits with these
4636 error codes, after having been created by the <citerefentry
4637 project='man-pages'><refentrytitle>fork</refentrytitle><manvolnum>2</manvolnum></citerefentry> system call, but
4638 before the matching <citerefentry
4639 project='man-pages'><refentrytitle>execve</refentrytitle><manvolnum>2</manvolnum></citerefentry> system call is
4640 called.) Specifically, exit codes defined by the C library, by the LSB specification and by the systemd service
4641 manager itself are used.</para>
4642
4643 <para>The following basic service exit codes are defined by the C library.</para>
4644
4645 <table>
4646 <title>Basic C library exit codes</title>
4647 <tgroup cols='3'>
4648 <thead>
4649 <row>
4650 <entry>Exit Code</entry>
4651 <entry>Symbolic Name</entry>
4652 <entry>Description</entry>
4653 </row>
4654 </thead>
4655 <tbody>
4656 <row>
4657 <entry>0</entry>
4658 <entry><constant>EXIT_SUCCESS</constant></entry>
4659 <entry>Generic success code.</entry>
4660 </row>
4661 <row>
4662 <entry>1</entry>
4663 <entry><constant>EXIT_FAILURE</constant></entry>
4664 <entry>Generic failure or unspecified error.</entry>
4665 </row>
4666 </tbody>
4667 </tgroup>
4668 </table>
4669
4670 <para>The following service exit codes are defined by the <ulink
4671 url="https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html">LSB specification</ulink>.
4672 </para>
4673
4674 <table>
4675 <title>LSB service exit codes</title>
4676 <tgroup cols='3'>
4677 <thead>
4678 <row>
4679 <entry>Exit Code</entry>
4680 <entry>Symbolic Name</entry>
4681 <entry>Description</entry>
4682 </row>
4683 </thead>
4684 <tbody>
4685 <row>
4686 <entry>2</entry>
4687 <entry><constant>EXIT_INVALIDARGUMENT</constant></entry>
4688 <entry>Invalid or excess arguments.</entry>
4689 </row>
4690 <row>
4691 <entry>3</entry>
4692 <entry><constant>EXIT_NOTIMPLEMENTED</constant></entry>
4693 <entry>Unimplemented feature.</entry>
4694 </row>
4695 <row>
4696 <entry>4</entry>
4697 <entry><constant>EXIT_NOPERMISSION</constant></entry>
4698 <entry>The user has insufficient privileges.</entry>
4699 </row>
4700 <row>
4701 <entry>5</entry>
4702 <entry><constant>EXIT_NOTINSTALLED</constant></entry>
4703 <entry>The program is not installed.</entry>
4704 </row>
4705 <row>
4706 <entry>6</entry>
4707 <entry><constant>EXIT_NOTCONFIGURED</constant></entry>
4708 <entry>The program is not configured.</entry>
4709 </row>
4710 <row>
4711 <entry>7</entry>
4712 <entry><constant>EXIT_NOTRUNNING</constant></entry>
4713 <entry>The program is not running.</entry>
4714 </row>
4715 </tbody>
4716 </tgroup>
4717 </table>
4718
4719 <para>
4720 The LSB specification suggests that error codes 200 and above are reserved for implementations. Some of them are
4721 used by the service manager to indicate problems during process invocation:
4722 </para>
4723 <table>
4724 <title>systemd-specific exit codes</title>
4725 <tgroup cols='3'>
4726 <thead>
4727 <row>
4728 <entry>Exit Code</entry>
4729 <entry>Symbolic Name</entry>
4730 <entry>Description</entry>
4731 </row>
4732 </thead>
4733 <tbody>
4734 <row>
4735 <entry>200</entry>
4736 <entry><constant>EXIT_CHDIR</constant></entry>
4737 <entry>Changing to the requested working directory failed. See <varname>WorkingDirectory=</varname> above.</entry>
4738 </row>
4739 <row>
4740 <entry>201</entry>
4741 <entry><constant>EXIT_NICE</constant></entry>
4742 <entry>Failed to set up process scheduling priority (nice level). See <varname>Nice=</varname> above.</entry>
4743 </row>
4744 <row>
4745 <entry>202</entry>
4746 <entry><constant>EXIT_FDS</constant></entry>
4747 <entry>Failed to close unwanted file descriptors, or to adjust passed file descriptors.</entry>
4748 </row>
4749 <row>
4750 <entry>203</entry>
4751 <entry><constant>EXIT_EXEC</constant></entry>
4752 <entry>The actual process execution failed (specifically, the <citerefentry project='man-pages'><refentrytitle>execve</refentrytitle><manvolnum>2</manvolnum></citerefentry> system call). Most likely this is caused by a missing or non-accessible executable file.</entry>
4753 </row>
4754 <row>
4755 <entry>204</entry>
4756 <entry><constant>EXIT_MEMORY</constant></entry>
4757 <entry>Failed to perform an action due to memory shortage.</entry>
4758 </row>
4759 <row>
4760 <entry>205</entry>
4761 <entry><constant>EXIT_LIMITS</constant></entry>
4762 <entry>Failed to adjust resource limits. See <varname>LimitCPU=</varname> and related settings above.</entry>
4763 </row>
4764 <row>
4765 <entry>206</entry>
4766 <entry><constant>EXIT_OOM_ADJUST</constant></entry>
4767 <entry>Failed to adjust the OOM setting. See <varname>OOMScoreAdjust=</varname> above.</entry>
4768 </row>
4769 <row>
4770 <entry>207</entry>
4771 <entry><constant>EXIT_SIGNAL_MASK</constant></entry>
4772 <entry>Failed to set process signal mask.</entry>
4773 </row>
4774 <row>
4775 <entry>208</entry>
4776 <entry><constant>EXIT_STDIN</constant></entry>
4777 <entry>Failed to set up standard input. See <varname>StandardInput=</varname> above.</entry>
4778 </row>
4779 <row>
4780 <entry>209</entry>
4781 <entry><constant>EXIT_STDOUT</constant></entry>
4782 <entry>Failed to set up standard output. See <varname>StandardOutput=</varname> above.</entry>
4783 </row>
4784 <row>
4785 <entry>210</entry>
4786 <entry><constant>EXIT_CHROOT</constant></entry>
4787 <entry>Failed to change root directory (<citerefentry project='man-pages'><refentrytitle>chroot</refentrytitle><manvolnum>2</manvolnum></citerefentry>). See <varname>RootDirectory=</varname>/<varname>RootImage=</varname> above.</entry>
4788 </row>
4789 <row>
4790 <entry>211</entry>
4791 <entry><constant>EXIT_IOPRIO</constant></entry>
4792 <entry>Failed to set up IO scheduling priority. See <varname>IOSchedulingClass=</varname>/<varname>IOSchedulingPriority=</varname> above.</entry>
4793 </row>
4794 <row>
4795 <entry>212</entry>
4796 <entry><constant>EXIT_TIMERSLACK</constant></entry>
4797 <entry>Failed to set up timer slack. See <varname>TimerSlackNSec=</varname> above.</entry>
4798 </row>
4799 <row>
4800 <entry>213</entry>
4801 <entry><constant>EXIT_SECUREBITS</constant></entry>
4802 <entry>Failed to set process secure bits. See <varname>SecureBits=</varname> above.</entry>
4803 </row>
4804 <row>
4805 <entry>214</entry>
4806 <entry><constant>EXIT_SETSCHEDULER</constant></entry>
4807 <entry>Failed to set up CPU scheduling. See <varname>CPUSchedulingPolicy=</varname>/<varname>CPUSchedulingPriority=</varname> above.</entry>
4808 </row>
4809 <row>
4810 <entry>215</entry>
4811 <entry><constant>EXIT_CPUAFFINITY</constant></entry>
4812 <entry>Failed to set up CPU affinity. See <varname>CPUAffinity=</varname> above.</entry>
4813 </row>
4814 <row>
4815 <entry>216</entry>
4816 <entry><constant>EXIT_GROUP</constant></entry>
4817 <entry>Failed to determine or change group credentials. See <varname>Group=</varname>/<varname>SupplementaryGroups=</varname> above.</entry>
4818 </row>
4819 <row>
4820 <entry>217</entry>
4821 <entry><constant>EXIT_USER</constant></entry>
4822 <entry>Failed to determine or change user credentials, or to set up user namespacing. See <varname>User=</varname>/<varname>PrivateUsers=</varname> above.</entry>
4823 </row>
4824 <row>
4825 <entry>218</entry>
4826 <entry><constant>EXIT_CAPABILITIES</constant></entry>
4827 <entry>Failed to drop capabilities, or apply ambient capabilities. See <varname>CapabilityBoundingSet=</varname>/<varname>AmbientCapabilities=</varname> above.</entry>
4828 </row>
4829 <row>
4830 <entry>219</entry>
4831 <entry><constant>EXIT_CGROUP</constant></entry>
4832 <entry>Setting up the service control group failed.</entry>
4833 </row>
4834 <row>
4835 <entry>220</entry>
4836 <entry><constant>EXIT_SETSID</constant></entry>
4837 <entry>Failed to create new process session.</entry>
4838 </row>
4839 <row>
4840 <entry>221</entry>
4841 <entry><constant>EXIT_CONFIRM</constant></entry>
4842 <entry>Execution has been cancelled by the user. See the <varname>systemd.confirm_spawn=</varname> kernel command line setting on <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry> for details.</entry>
4843 </row>
4844 <row>
4845 <entry>222</entry>
4846 <entry><constant>EXIT_STDERR</constant></entry>
4847 <entry>Failed to set up standard error output. See <varname>StandardError=</varname> above.</entry>
4848 </row>
4849 <row>
4850 <entry>224</entry>
4851 <entry><constant>EXIT_PAM</constant></entry>
4852 <entry>Failed to set up PAM session. See <varname>PAMName=</varname> above.</entry>
4853 </row>
4854 <row>
4855 <entry>225</entry>
4856 <entry><constant>EXIT_NETWORK</constant></entry>
4857 <entry>Failed to set up network namespacing. See <varname>PrivateNetwork=</varname> above.</entry>
4858 </row>
4859 <row>
4860 <entry>226</entry>
4861 <entry><constant>EXIT_NAMESPACE</constant></entry>
4862 <entry>Failed to set up mount, UTS, or IPC namespacing. See <varname>ReadOnlyPaths=</varname>, <varname>ProtectHostname=</varname>, <varname>PrivateIPC=</varname>, and related settings above.</entry>
4863 </row>
4864 <row>
4865 <entry>227</entry>
4866 <entry><constant>EXIT_NO_NEW_PRIVILEGES</constant></entry>
4867 <entry>Failed to disable new privileges. See <varname>NoNewPrivileges=yes</varname> above.</entry>
4868 </row>
4869 <row>
4870 <entry>228</entry>
4871 <entry><constant>EXIT_SECCOMP</constant></entry>
4872 <entry>Failed to apply system call filters. See <varname>SystemCallFilter=</varname> and related settings above.</entry>
4873 </row>
4874 <row>
4875 <entry>229</entry>
4876 <entry><constant>EXIT_SELINUX_CONTEXT</constant></entry>
4877 <entry>Determining or changing SELinux context failed. See <varname>SELinuxContext=</varname> above.</entry>
4878 </row>
4879 <row>
4880 <entry>230</entry>
4881 <entry><constant>EXIT_PERSONALITY</constant></entry>
4882 <entry>Failed to set up an execution domain (personality). See <varname>Personality=</varname> above.</entry>
4883 </row>
4884 <row>
4885 <entry>231</entry>
4886 <entry><constant>EXIT_APPARMOR_PROFILE</constant></entry>
4887 <entry>Failed to prepare changing AppArmor profile. See <varname>AppArmorProfile=</varname> above.</entry>
4888 </row>
4889 <row>
4890 <entry>232</entry>
4891 <entry><constant>EXIT_ADDRESS_FAMILIES</constant></entry>
4892 <entry>Failed to restrict address families. See <varname>RestrictAddressFamilies=</varname> above.</entry>
4893 </row>
4894 <row>
4895 <entry>233</entry>
4896 <entry><constant>EXIT_RUNTIME_DIRECTORY</constant></entry>
4897 <entry>Setting up runtime directory failed. See <varname>RuntimeDirectory=</varname> and related settings above.</entry>
4898 </row>
4899 <row>
4900 <entry>235</entry>
4901 <entry><constant>EXIT_CHOWN</constant></entry>
4902 <entry>Failed to adjust socket ownership. Used for socket units only.</entry>
4903 </row>
4904 <row>
4905 <entry>236</entry>
4906 <entry><constant>EXIT_SMACK_PROCESS_LABEL</constant></entry>
4907 <entry>Failed to set SMACK label. See <varname>SmackProcessLabel=</varname> above.</entry>
4908 </row>
4909 <row>
4910 <entry>237</entry>
4911 <entry><constant>EXIT_KEYRING</constant></entry>
4912 <entry>Failed to set up kernel keyring.</entry>
4913 </row>
4914 <row>
4915 <entry>238</entry>
4916 <entry><constant>EXIT_STATE_DIRECTORY</constant></entry>
4917 <entry>Failed to set up unit's state directory. See <varname>StateDirectory=</varname> above.</entry>
4918 </row>
4919 <row>
4920 <entry>239</entry>
4921 <entry><constant>EXIT_CACHE_DIRECTORY</constant></entry>
4922 <entry>Failed to set up unit's cache directory. See <varname>CacheDirectory=</varname> above.</entry>
4923 </row>
4924 <row>
4925 <entry>240</entry>
4926 <entry><constant>EXIT_LOGS_DIRECTORY</constant></entry>
4927 <entry>Failed to set up unit's logging directory. See <varname>LogsDirectory=</varname> above.</entry>
4928 </row>
4929 <row>
4930 <entry>241</entry>
4931 <entry><constant>EXIT_CONFIGURATION_DIRECTORY</constant></entry>
4932 <entry>Failed to set up unit's configuration directory. See <varname>ConfigurationDirectory=</varname> above.</entry>
4933 </row>
4934 <row>
4935 <entry>242</entry>
4936 <entry><constant>EXIT_NUMA_POLICY</constant></entry>
4937 <entry>Failed to set up unit's NUMA memory policy. See <varname>NUMAPolicy=</varname> and <varname>NUMAMask=</varname> above.</entry>
4938 </row>
4939 <row>
4940 <entry>243</entry>
4941 <entry><constant>EXIT_CREDENTIALS</constant></entry>
4942 <entry>Failed to set up unit's credentials. See <varname>ImportCredential=</varname>, <varname>LoadCredential=</varname> and <varname>SetCredential=</varname> above.</entry>
4943 </row>
4944 <row>
4945 <entry>245</entry>
4946 <entry><constant>EXIT_BPF</constant></entry>
4947 <entry>Failed to apply BPF restrictions. See <varname>RestrictFileSystems=</varname> above.</entry>
4948 </row>
4949 </tbody>
4950 </tgroup>
4951 </table>
4952
4953 <para>Finally, the BSD operating systems define a set of exit codes, typically defined on Linux systems too:</para>
4954
4955 <table>
4956 <title>BSD exit codes</title>
4957 <tgroup cols='3'>
4958 <thead>
4959 <row>
4960 <entry>Exit Code</entry>
4961 <entry>Symbolic Name</entry>
4962 <entry>Description</entry>
4963 </row>
4964 </thead>
4965 <tbody>
4966 <row>
4967 <entry>64</entry>
4968 <entry><constant>EX_USAGE</constant></entry>
4969 <entry>Command line usage error</entry>
4970 </row>
4971 <row>
4972 <entry>65</entry>
4973 <entry><constant>EX_DATAERR</constant></entry>
4974 <entry>Data format error</entry>
4975 </row>
4976 <row>
4977 <entry>66</entry>
4978 <entry><constant>EX_NOINPUT</constant></entry>
4979 <entry>Cannot open input</entry>
4980 </row>
4981 <row>
4982 <entry>67</entry>
4983 <entry><constant>EX_NOUSER</constant></entry>
4984 <entry>Addressee unknown</entry>
4985 </row>
4986 <row>
4987 <entry>68</entry>
4988 <entry><constant>EX_NOHOST</constant></entry>
4989 <entry>Host name unknown</entry>
4990 </row>
4991 <row>
4992 <entry>69</entry>
4993 <entry><constant>EX_UNAVAILABLE</constant></entry>
4994 <entry>Service unavailable</entry>
4995 </row>
4996 <row>
4997 <entry>70</entry>
4998 <entry><constant>EX_SOFTWARE</constant></entry>
4999 <entry>internal software error</entry>
5000 </row>
5001 <row>
5002 <entry>71</entry>
5003 <entry><constant>EX_OSERR</constant></entry>
5004 <entry>System error (e.g., cannot fork)</entry>
5005 </row>
5006 <row>
5007 <entry>72</entry>
5008 <entry><constant>EX_OSFILE</constant></entry>
5009 <entry>Critical OS file missing</entry>
5010 </row>
5011 <row>
5012 <entry>73</entry>
5013 <entry><constant>EX_CANTCREAT</constant></entry>
5014 <entry>Cannot create (user) output file</entry>
5015 </row>
5016 <row>
5017 <entry>74</entry>
5018 <entry><constant>EX_IOERR</constant></entry>
5019 <entry>Input/output error</entry>
5020 </row>
5021 <row>
5022 <entry>75</entry>
5023 <entry><constant>EX_TEMPFAIL</constant></entry>
5024 <entry>Temporary failure; user is invited to retry</entry>
5025 </row>
5026 <row>
5027 <entry>76</entry>
5028 <entry><constant>EX_PROTOCOL</constant></entry>
5029 <entry>Remote error in protocol</entry>
5030 </row>
5031 <row>
5032 <entry>77</entry>
5033 <entry><constant>EX_NOPERM</constant></entry>
5034 <entry>Permission denied</entry>
5035 </row>
5036 <row>
5037 <entry>78</entry>
5038 <entry><constant>EX_CONFIG</constant></entry>
5039 <entry>Configuration error</entry>
5040 </row>
5041 </tbody>
5042 </tgroup>
5043 </table>
5044 </refsect1>
5045
5046 <refsect1>
5047 <title>Examples</title>
5048
5049 <example>
5050 <title><varname>$MONITOR_<replaceable>*</replaceable></varname> usage</title>
5051
5052 <para>A service <filename index="false">myfailer.service</filename> which can trigger an
5053 <varname>OnFailure=</varname> dependency.</para>
5054
5055 <programlisting>
5056[Unit]
5057Description=Service which can trigger an OnFailure= dependency
5058OnFailure=myhandler.service
5059
5060[Service]
5061ExecStart=/bin/myprogram
5062</programlisting>
5063
5064 <para>A service <filename index="false">mysuccess.service</filename> which can trigger an
5065 <varname>OnSuccess=</varname> dependency.</para>
5066
5067 <programlisting>
5068[Unit]
5069Description=Service which can trigger an OnSuccess= dependency
5070OnSuccess=myhandler.service
5071
5072[Service]
5073ExecStart=/bin/mysecondprogram
5074</programlisting>
5075
5076 <para>A service <filename index="false">myhandler.service</filename> which can be triggered
5077 by any of the above services.</para>
5078
5079 <programlisting>
5080[Unit]
5081Description=Acts on service failing or succeeding
5082
5083[Service]
5084ExecStart=/bin/bash -c "echo $MONITOR_SERVICE_RESULT $MONITOR_EXIT_CODE $MONITOR_EXIT_STATUS $MONITOR_INVOCATION_ID $MONITOR_UNIT"
5085</programlisting>
5086
5087 <para>If <filename index="false">myfailer.service</filename> were to run and exit in failure,
5088 then <filename index="false">myhandler.service</filename> would be triggered and the
5089 monitor variables would be set as follows:</para>
5090
5091 <programlisting>
5092MONITOR_SERVICE_RESULT=exit-code
5093MONITOR_EXIT_CODE=exited
5094MONITOR_EXIT_STATUS=1
5095MONITOR_INVOCATION_ID=cc8fdc149b2b4ca698d4f259f4054236
5096MONITOR_UNIT=myfailer.service
5097</programlisting>
5098
5099 <para>If <filename index="false">mysuccess.service</filename> were to run and exit in success,
5100 then <filename index="false">myhandler.service</filename> would be triggered and the
5101 monitor variables would be set as follows:</para>
5102
5103 <programlisting>
5104MONITOR_SERVICE_RESULT=success
5105MONITOR_EXIT_CODE=exited
5106MONITOR_EXIT_STATUS=0
5107MONITOR_INVOCATION_ID=6ab9af147b8c4a3ebe36e7a5f8611697
5108MONITOR_UNIT=mysuccess.service
5109</programlisting>
5110
5111 </example>
5112
5113 </refsect1>
5114
5115 <refsect1>
5116 <title>See Also</title>
5117 <para><simplelist type="inline">
5118 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
5119 <member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
5120 <member><citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
5121 <member><citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
5122 <member><citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5123 <member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5124 <member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5125 <member><citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5126 <member><citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5127 <member><citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5128 <member><citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5129 <member><citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5130 <member><citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
5131 <member><citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
5132 <member><citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
5133 <member><citerefentry project='man-pages'><refentrytitle>exec</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
5134 <member><citerefentry project='man-pages'><refentrytitle>fork</refentrytitle><manvolnum>2</manvolnum></citerefentry></member>
5135 </simplelist></para>
5136 </refsect1>
5137
5138</refentry>