Debian Codegraph @

upstream/debian-trixie/man5/systemd.service.5

raw
1 '\" t
2 .TH "SYSTEMD\&.SERVICE" "5" "" "systemd 257.13" "systemd.service"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 systemd.service \- Service unit configuration
24 .SH "SYNOPSIS"
25 .PP
26 \fIservice\fR\&.service
27 .SH "DESCRIPTION"
28 .PP
29 A unit configuration file whose name ends in
30 "\&.service"
31 encodes information about a process controlled and supervised by systemd\&.
32 .PP
33 This man page lists the configuration options specific to this unit type\&. See
34 \fBsystemd.unit\fR(5)
35 for the common options of all unit configuration files\&. The common configuration items are configured in the generic [Unit] and [Install] sections\&. The service specific configuration options are configured in the [Service] section\&.
36 .PP
37 Additional options are listed in
38 \fBsystemd.exec\fR(5), which define the execution environment the commands are executed in, and in
39 \fBsystemd.kill\fR(5), which define the way the processes of the service are terminated, and in
40 \fBsystemd.resource-control\fR(5), which configure resource control settings for the processes of the service\&.
41 .PP
42 If SysV init compat is enabled, systemd automatically creates service units that wrap SysV init scripts (the service name is the same as the name of the script, with a
43 "\&.service"
44 suffix added); see
45 \fBsystemd-sysv-generator\fR(8)\&.
46 .PP
47 The
48 \fBsystemd-run\fR(1)
49 command allows creating
50 \&.service
51 and
52 \&.scope
53 units dynamically and transiently from the command line\&.
54 .SH "SERVICE TEMPLATES"
55 .PP
56 It is possible for
57 \fBsystemd\fR
58 services to take a single argument via the
59 "\fIservice\fR@\fIargument\fR\&.service"
60 syntax\&. Such services are called "instantiated" services, while the unit definition without the
61 \fIargument\fR
62 parameter is called a "template"\&. An example could be a
63 dhcpcd@\&.service
64 service template which takes a network interface as a parameter to form an instantiated service\&. Within the service file, this parameter or "instance name" can be accessed with %\-specifiers\&. See
65 \fBsystemd.unit\fR(5)
66 for details\&.
67 .SH "AUTOMATIC DEPENDENCIES"
68 .SS "Implicit Dependencies"
69 .PP
70 The following dependencies are implicitly added:
71 .sp
72 .RS 4
73 .ie n \{\
74 \h'-04'\(bu\h'+03'\c
75 .\}
76 .el \{\
77 .sp -1
78 .IP \(bu 2.3
79 .\}
80 Services with
81 \fIType=dbus\fR
82 set automatically acquire dependencies of type
83 \fIRequires=\fR
84 and
85 \fIAfter=\fR
86 on
87 dbus\&.socket\&.
88 .RE
89 .sp
90 .RS 4
91 .ie n \{\
92 \h'-04'\(bu\h'+03'\c
93 .\}
94 .el \{\
95 .sp -1
96 .IP \(bu 2.3
97 .\}
98 Socket activated services are automatically ordered after their activating
99 \&.socket
100 units via an automatic
101 \fIAfter=\fR
102 dependency\&. Services also pull in all
103 \&.socket
104 units listed in
105 \fISockets=\fR
106 via automatic
107 \fIWants=\fR
108 and
109 \fIAfter=\fR
110 dependencies\&.
111 .RE
112 .PP
113 Additional implicit dependencies may be added as result of execution and resource control parameters as documented in
114 \fBsystemd.exec\fR(5)
115 and
116 \fBsystemd.resource-control\fR(5)\&.
117 .SS "Default Dependencies"
118 .PP
119 The following dependencies are added unless
120 \fIDefaultDependencies=no\fR
121 is set:
122 .sp
123 .RS 4
124 .ie n \{\
125 \h'-04'\(bu\h'+03'\c
126 .\}
127 .el \{\
128 .sp -1
129 .IP \(bu 2.3
130 .\}
131 Service units will have dependencies of type
132 \fIRequires=\fR
133 and
134 \fIAfter=\fR
135 on
136 sysinit\&.target, a dependency of type
137 \fIAfter=\fR
138 on
139 basic\&.target
140 as well as dependencies of type
141 \fIConflicts=\fR
142 and
143 \fIBefore=\fR
144 on
145 shutdown\&.target\&. These ensure that normal service units pull in basic system initialization, and are terminated cleanly prior to system shutdown\&. Only services involved with early boot or late system shutdown should disable this option\&.
146 .RE
147 .sp
148 .RS 4
149 .ie n \{\
150 \h'-04'\(bu\h'+03'\c
151 .\}
152 .el \{\
153 .sp -1
154 .IP \(bu 2.3
155 .\}
156 Instanced service units (i\&.e\&. service units with an
157 "@"
158 in their name) are assigned by default a per\-template slice unit (see
159 \fBsystemd.slice\fR(5)), named after the template unit, containing all instances of the specific template\&. This slice is normally stopped at shutdown, together with all template instances\&. If that is not desired, set
160 \fIDefaultDependencies=no\fR
161 in the template unit, and either define your own per\-template slice unit file that also sets
162 \fIDefaultDependencies=no\fR, or set
163 \fISlice=system\&.slice\fR
164 (or another suitable slice) in the template unit\&. Also see
165 \fBsystemd.resource-control\fR(5)\&.
166 .RE
167 .SH "OPTIONS"
168 .PP
169 Service unit files may include [Unit] and [Install] sections, which are described in
170 \fBsystemd.unit\fR(5)\&.
171 .PP
172 Service unit files must include a [Service] section, which carries information about the service and the process it supervises\&. A number of options that may be used in this section are shared with other unit types\&. These options are documented in
173 \fBsystemd.exec\fR(5),
174 \fBsystemd.kill\fR(5)
175 and
176 \fBsystemd.resource-control\fR(5)\&. The options specific to the [Service] section of service units are the following:
177 .PP
178 \fIType=\fR
179 .RS 4
180 Configures the mechanism via which the service notifies the manager that the service start\-up has finished\&. One of
181 \fBsimple\fR,
182 \fBexec\fR,
183 \fBforking\fR,
184 \fBoneshot\fR,
185 \fBdbus\fR,
186 \fBnotify\fR,
187 \fBnotify\-reload\fR, or
188 \fBidle\fR:
189 .sp
190 .RS 4
191 .ie n \{\
192 \h'-04'\(bu\h'+03'\c
193 .\}
194 .el \{\
195 .sp -1
196 .IP \(bu 2.3
197 .\}
198 If set to
199 \fBsimple\fR
200 (the default if
201 \fIExecStart=\fR
202 is specified but neither
203 \fIType=\fR
204 nor
205 \fIBusName=\fR
206 are, and credentials are not used), the service manager will consider the unit started immediately after the main service process has been forked off (i\&.e\&. immediately after
207 \fBfork()\fR, and before various process attributes have been configured and in particular before the new process has called
208 \fBexecve()\fR
209 to invoke the actual service binary)\&. Typically,
210 \fIType=\fR\fBexec\fR
211 is the better choice, see below\&.
212 .sp
213 It is expected that the process configured with
214 \fIExecStart=\fR
215 is the main process of the service\&. In this mode, if the process offers functionality to other processes on the system, its communication channels should be installed before the service is started up (e\&.g\&. sockets set up by systemd, via socket activation), as the service manager will immediately proceed starting follow\-up units, right after creating the main service process, and before executing the service\*(Aqs binary\&. Note that this means
216 \fBsystemctl start\fR
217 command lines for
218 \fBsimple\fR
219 services will report success even if the service\*(Aqs binary cannot be invoked successfully (for example because the selected
220 \fIUser=\fR
221 does not exist, or the service binary is missing)\&.
222 .RE
223 .sp
224 .RS 4
225 .ie n \{\
226 \h'-04'\(bu\h'+03'\c
227 .\}
228 .el \{\
229 .sp -1
230 .IP \(bu 2.3
231 .\}
232 The
233 \fBexec\fR
234 type is similar to
235 \fBsimple\fR, but the service manager will consider the unit started immediately after the main service binary has been executed\&. The service manager will delay starting of follow\-up units until that point\&. (Or in other words:
236 \fBsimple\fR
237 proceeds with further jobs right after
238 \fBfork()\fR
239 returns, while
240 \fBexec\fR
241 will not proceed before both
242 \fBfork()\fR
243 and
244 \fBexecve()\fR
245 in the service process succeeded\&.) Note that this means
246 \fBsystemctl start\fR
247 command lines for
248 \fBexec\fR
249 services will report failure when the service\*(Aqs binary cannot be invoked successfully (for example because the selected
250 \fIUser=\fR
251 does not exist, or the service binary is missing)\&. This type is implied if credentials are used (refer to
252 \fILoadCredential=\fR
253 in
254 \fBsystemd.exec\fR(5)
255 for details)\&.
256 .RE
257 .sp
258 .RS 4
259 .ie n \{\
260 \h'-04'\(bu\h'+03'\c
261 .\}
262 .el \{\
263 .sp -1
264 .IP \(bu 2.3
265 .\}
266 If set to
267 \fBforking\fR, the manager will consider the unit started immediately after the binary that forked off by the manager exits\&.
268 \fIThe use of this type is discouraged, use \fR\fI\fBnotify\fR\fR\fI, \fR\fI\fBnotify\-reload\fR\fR\fI, or \fR\fI\fBdbus\fR\fR\fI instead\&.\fR
269 .sp
270 It is expected that the process configured with
271 \fIExecStart=\fR
272 will call
273 \fBfork()\fR
274 as part of its start\-up\&. The parent process is expected to exit when start\-up is complete and all communication channels are set up\&. The child continues to run as the main service process, and the service manager will consider the unit started when the parent process exits\&. This is the behavior of traditional UNIX services\&. If this setting is used, it is recommended to also use the
275 \fIPIDFile=\fR
276 option, so that systemd can reliably identify the main process of the service\&. The manager will proceed with starting follow\-up units after the parent process exits\&.
277 .RE
278 .sp
279 .RS 4
280 .ie n \{\
281 \h'-04'\(bu\h'+03'\c
282 .\}
283 .el \{\
284 .sp -1
285 .IP \(bu 2.3
286 .\}
287 Behavior of
288 \fBoneshot\fR
289 is similar to
290 \fBexec\fR; however, the service manager will consider the unit up after the main process exits\&. It will then start follow\-up units\&.
291 \fIRemainAfterExit=\fR
292 is particularly useful for this type of service\&.
293 \fIType=\fR\fBoneshot\fR
294 is the implied default if neither
295 \fIType=\fR
296 nor
297 \fIExecStart=\fR
298 are specified\&. Note that if this option is used without
299 \fIRemainAfterExit=\fR
300 the service will never enter
301 "active"
302 unit state, but will directly transition from
303 "activating"
304 to
305 "deactivating"
306 or
307 "dead", since no process is configured that shall run continuously\&. In particular this means that after a service of this type ran (and which has
308 \fIRemainAfterExit=\fR
309 not set) it will not show up as started afterwards, but as dead\&.
310 .RE
311 .sp
312 .RS 4
313 .ie n \{\
314 \h'-04'\(bu\h'+03'\c
315 .\}
316 .el \{\
317 .sp -1
318 .IP \(bu 2.3
319 .\}
320 Behavior of
321 \fBdbus\fR
322 is similar to
323 \fBsimple\fR; however, units of this type must have the
324 \fIBusName=\fR
325 specified and the service manager will consider the unit up when the specified bus name has been acquired\&. This type is the default if
326 \fIBusName=\fR
327 is specified\&.
328 .sp
329 Service units with this option configured implicitly gain dependencies on the
330 dbus\&.socket
331 unit\&. A service unit of this type is considered to be in the activating state until the specified bus name is acquired\&. It is considered activated while the bus name is taken\&. Once the bus name is released the service is considered being no longer functional which has the effect that the service manager attempts to terminate any remaining processes belonging to the service\&. Services that drop their bus name as part of their shutdown logic thus should be prepared to receive a
332 \fBSIGTERM\fR
333 (or whichever signal is configured in
334 \fIKillSignal=\fR) as result\&.
335 .RE
336 .sp
337 .RS 4
338 .ie n \{\
339 \h'-04'\(bu\h'+03'\c
340 .\}
341 .el \{\
342 .sp -1
343 .IP \(bu 2.3
344 .\}
345 Behavior of
346 \fBnotify\fR
347 is similar to
348 \fBexec\fR; however, it is expected that the service sends a
349 "READY=1"
350 notification message via
351 \fBsd_notify\fR(3)
352 or an equivalent call when it has finished starting up\&. systemd will proceed with starting follow\-up units after this notification message has been sent\&. If this option is used,
353 \fINotifyAccess=\fR
354 (see below) should be set to open access to the notification socket provided by systemd\&. If
355 \fINotifyAccess=\fR
356 is missing or set to
357 \fBnone\fR, it will be forcibly set to
358 \fBmain\fR\&.
359 .sp
360 If the service supports reloading, and uses a signal to start the reload, using
361 \fBnotify\-reload\fR
362 instead is recommended\&.
363 .RE
364 .sp
365 .RS 4
366 .ie n \{\
367 \h'-04'\(bu\h'+03'\c
368 .\}
369 .el \{\
370 .sp -1
371 .IP \(bu 2.3
372 .\}
373 Behavior of
374 \fBnotify\-reload\fR
375 is similar to
376 \fBnotify\fR, with one difference: the
377 \fBSIGHUP\fR
378 UNIX process signal is sent to the service\*(Aqs main process when the service is asked to reload and the manager will wait for a notification about the reload being finished\&.
379 .sp
380 When initiating the reload process the service is expected to reply with a notification message via
381 \fBsd_notify\fR(3)
382 that contains the
383 "RELOADING=1"
384 field in combination with
385 "MONOTONIC_USEC="
386 set to the current monotonic time (i\&.e\&.
387 \fBCLOCK_MONOTONIC\fR
388 in
389 \fBclock_gettime\fR(2)) in μs, formatted as decimal string\&. Once reloading is complete another notification message must be sent, containing
390 "READY=1"\&. Using this service type and implementing this reload protocol is an efficient alternative to providing an
391 \fIExecReload=\fR
392 command for reloading of the service\*(Aqs configuration\&.
393 .sp
394 The signal to send can be tweaked via
395 \fIReloadSignal=\fR, see below\&.
396 .RE
397 .sp
398 .RS 4
399 .ie n \{\
400 \h'-04'\(bu\h'+03'\c
401 .\}
402 .el \{\
403 .sp -1
404 .IP \(bu 2.3
405 .\}
406 Behavior of
407 \fBidle\fR
408 is very similar to
409 \fBsimple\fR; however, actual execution of the service program is delayed until all active jobs are dispatched\&. This may be used to avoid interleaving of output of shell services with the status output on the console\&. Note that this type is useful only to improve console output, it is not useful as a general unit ordering tool, and the effect of this service type is subject to a 5s timeout, after which the service program is invoked anyway\&.
410 .RE
411 .sp
412 It is recommended to use
413 \fIType=\fR\fBexec\fR
414 for long\-running services, as it ensures that process setup errors (e\&.g\&. errors such as a missing service executable, or missing user) are properly tracked\&. However, as this service type will not propagate the failures in the service\*(Aqs own startup code (as opposed to failures in the preparatory steps the service manager executes before
415 \fBexecve()\fR) and does not allow ordering of other units against completion of initialization of the service code itself (which for example is useful if clients need to connect to the service through some form of IPC, and the IPC channel is only established by the service itself \(em in contrast to doing this ahead of time through socket or bus activation or similar), it might not be sufficient for many cases\&. If so,
416 \fBnotify\fR,
417 \fBnotify\-reload\fR, or
418 \fBdbus\fR
419 (the latter only in case the service provides a D\-Bus interface) are the preferred options as they allow service program code to precisely schedule when to consider the service started up successfully and when to proceed with follow\-up units\&. The
420 \fBnotify\fR/\fBnotify\-reload\fR
421 service types require explicit support in the service codebase (as
422 \fBsd_notify()\fR
423 or an equivalent API needs to be invoked by the service at the appropriate time) \(em if it is not supported, then
424 \fBforking\fR
425 is an alternative: it supports the traditional heavy\-weight UNIX service start\-up protocol\&. Note that using any type other than
426 \fBsimple\fR
427 possibly delays the boot process, as the service manager needs to wait for at least some service initialization to complete\&. (Also note it is generally not recommended to use
428 \fBidle\fR
429 or
430 \fBoneshot\fR
431 for long\-running services\&.)
432 .sp
433 Note that various service settings (e\&.g\&.
434 \fIUser=\fR,
435 \fIGroup=\fR
436 through libc NSS) might result in "hidden" blocking IPC calls to other services when used\&. Sometimes it might be advisable to use the
437 \fBsimple\fR
438 service type to ensure that the service manager\*(Aqs transaction logic is not affected by such potentially slow operations and hidden dependencies, as this is the only service type where the service manager will not wait for such service execution setup operations to complete before proceeding\&.
439 .RE
440 .PP
441 \fIExitType=\fR
442 .RS 4
443 Specifies when the manager should consider the service to be finished\&. One of
444 \fBmain\fR
445 or
446 \fBcgroup\fR:
447 .sp
448 .RS 4
449 .ie n \{\
450 \h'-04'\(bu\h'+03'\c
451 .\}
452 .el \{\
453 .sp -1
454 .IP \(bu 2.3
455 .\}
456 If set to
457 \fBmain\fR
458 (the default), the service manager will consider the unit stopped when the main process, which is determined according to the
459 \fIType=\fR, exits\&. Consequently, it cannot be used with
460 \fIType=\fR\fBoneshot\fR\&.
461 .RE
462 .sp
463 .RS 4
464 .ie n \{\
465 \h'-04'\(bu\h'+03'\c
466 .\}
467 .el \{\
468 .sp -1
469 .IP \(bu 2.3
470 .\}
471 If set to
472 \fBcgroup\fR, the service will be considered running as long as at least one process in the cgroup has not exited\&.
473 .RE
474 .sp
475 It is generally recommended to use
476 \fIExitType=\fR\fBmain\fR
477 when a service has a known forking model and a main process can reliably be determined\&.
478 \fIExitType=\fR
479 \fBcgroup\fR
480 is meant for applications whose forking model is not known ahead of time and which might not have a specific main process\&. It is well suited for transient or automatically generated services, such as graphical applications inside of a desktop environment\&.
481 .sp
482 Added in version 250\&.
483 .RE
484 .PP
485 \fIRemainAfterExit=\fR
486 .RS 4
487 Takes a boolean value that specifies whether the service shall be considered active even when all its processes exited\&. Defaults to
488 \fBno\fR\&.
489 .RE
490 .PP
491 \fIGuessMainPID=\fR
492 .RS 4
493 Takes a boolean value that specifies whether systemd should try to guess the main PID of a service if it cannot be determined reliably\&. This option is ignored unless
494 \fBType=forking\fR
495 is set and
496 \fBPIDFile=\fR
497 is unset because for the other types or with an explicitly configured PID file, the main PID is always known\&. The guessing algorithm might come to incorrect conclusions if a daemon consists of more than one process\&. If the main PID cannot be determined, failure detection and automatic restarting of a service will not work reliably\&. Defaults to
498 \fByes\fR\&.
499 .RE
500 .PP
501 \fIPIDFile=\fR
502 .RS 4
503 Takes a path referring to the PID file of the service\&. Usage of this option is recommended for services where
504 \fIType=\fR
505 is set to
506 \fBforking\fR\&. The path specified typically points to a file below
507 /run/\&. If a relative path is specified for system service, then it is hence prefixed with
508 /run/, and prefixed with
509 $XDG_RUNTIME_DIR
510 if specified in a user service\&. The service manager will read the PID of the main process of the service from this file after start\-up of the service\&. The service manager will not write to the file configured here, although it will remove the file after the service has shut down if it still exists\&. The PID file does not need to be owned by a privileged user, but if it is owned by an unprivileged user additional safety restrictions are enforced: the file may not be a symlink to a file owned by a different user (neither directly nor indirectly), and the PID file must refer to a process already belonging to the service\&.
511 .sp
512 Note that PID files should be avoided in modern projects\&. Use
513 \fBType=notify\fR,
514 \fBType=notify\-reload\fR
515 or
516 \fBType=simple\fR
517 where possible, which does not require use of PID files to determine the main process of a service and avoids needless forking\&.
518 .RE
519 .PP
520 \fIBusName=\fR
521 .RS 4
522 Takes a D\-Bus destination name that this service shall use\&. This option is mandatory for services where
523 \fIType=\fR
524 is set to
525 \fBdbus\fR\&. It is recommended to always set this property if known to make it easy to map the service name to the D\-Bus destination\&. In particular,
526 \fBsystemctl service\-log\-level/service\-log\-target\fR
527 verbs make use of this\&.
528 .RE
529 .PP
530 \fIExecStart=\fR
531 .RS 4
532 Commands that are executed when this service is started\&.
533 .sp
534 Unless
535 \fIType=\fR
536 is
537 \fBoneshot\fR, exactly one command must be given\&. When
538 \fIType=oneshot\fR
539 is used, this setting may be used multiple times to define multiple commands to execute\&. If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect\&. If no
540 \fIExecStart=\fR
541 is specified, then the service must have
542 \fIRemainAfterExit=yes\fR
543 and at least one
544 \fIExecStop=\fR
545 line set\&. (Services lacking both
546 \fIExecStart=\fR
547 and
548 \fIExecStop=\fR
549 are not valid\&.)
550 .sp
551 If more than one command is configured, the commands are invoked sequentially in the order they appear in the unit file\&. If one of the commands fails (and is not prefixed with
552 "\-"), other lines are not executed, and the unit is considered failed\&.
553 .sp
554 Unless
555 \fIType=forking\fR
556 is set, the process started via this command line will be considered the main process of the daemon\&.
557 .RE
558 .PP
559 \fIExecStartPre=\fR, \fIExecStartPost=\fR
560 .RS 4
561 Additional commands that are executed before or after the command in
562 \fIExecStart=\fR, respectively\&. Syntax is the same as for
563 \fIExecStart=\fR\&. Multiple command lines are allowed, regardless of the service type (i\&.e\&.
564 \fIType=\fR), and the commands are executed one after the other, serially\&.
565 .sp
566 If any of those commands (not prefixed with
567 "\-") fail, the rest are not executed and the unit is considered failed\&.
568 .sp
569 \fIExecStart=\fR
570 commands are only run after all
571 \fIExecStartPre=\fR
572 commands that were not prefixed with a
573 "\-"
574 exit successfully\&.
575 .sp
576 \fIExecStartPost=\fR
577 commands are only run after the commands specified in
578 \fIExecStart=\fR
579 have been invoked successfully, as determined by
580 \fIType=\fR
581 (i\&.e\&. the process has been started for
582 \fIType=simple\fR
583 or
584 \fIType=idle\fR, the last
585 \fIExecStart=\fR
586 process exited successfully for
587 \fIType=oneshot\fR, the initial process exited successfully for
588 \fIType=forking\fR,
589 "READY=1"
590 is sent for
591 \fIType=notify\fR/\fIType=notify\-reload\fR, or the
592 \fIBusName=\fR
593 has been taken for
594 \fIType=dbus\fR)\&.
595 .sp
596 Note that
597 \fIExecStartPre=\fR
598 may not be used to start long\-running processes\&. All processes forked off by processes invoked via
599 \fIExecStartPre=\fR
600 will be killed before the next service process is run\&.
601 .sp
602 Note that if any of the commands specified in
603 \fIExecStartPre=\fR,
604 \fIExecStart=\fR, or
605 \fIExecStartPost=\fR
606 fail (and are not prefixed with
607 "\-", see above) or time out before the service is fully up, execution continues with commands specified in
608 \fIExecStopPost=\fR, the commands in
609 \fIExecStop=\fR
610 are skipped\&.
611 .sp
612 Note that the execution of
613 \fIExecStartPost=\fR
614 is taken into account for the purpose of
615 \fIBefore=\fR/\fIAfter=\fR
616 ordering constraints\&.
617 .RE
618 .PP
619 \fIExecCondition=\fR
620 .RS 4
621 Optional commands that are executed before the commands in
622 \fIExecStartPre=\fR\&. Syntax is the same as for
623 \fIExecStart=\fR\&. Multiple command lines are allowed, regardless of the service type (i\&.e\&.
624 \fIType=\fR), and the commands are executed one after the other, serially\&.
625 .sp
626 The behavior is like an
627 \fIExecStartPre=\fR
628 and condition check hybrid: when an
629 \fIExecCondition=\fR
630 command exits with exit code 1 through 254 (inclusive), the remaining commands are skipped and the unit is
631 \fInot\fR
632 marked as failed\&. However, if an
633 \fIExecCondition=\fR
634 command exits with 255 or abnormally (e\&.g\&. timeout, killed by a signal, etc\&.), the unit will be considered failed (and remaining commands will be skipped)\&. Exit code of 0 or those matching
635 \fISuccessExitStatus=\fR
636 will continue execution to the next commands\&.
637 .sp
638 The same recommendations about not running long\-running processes in
639 \fIExecStartPre=\fR
640 also applies to
641 \fIExecCondition=\fR\&.
642 \fIExecCondition=\fR
643 will also run the commands in
644 \fIExecStopPost=\fR, as part of stopping the service, in the case of any non\-zero or abnormal exits, like the ones described above\&.
645 .sp
646 Added in version 243\&.
647 .RE
648 .PP
649 \fIExecReload=\fR
650 .RS 4
651 Commands to execute to trigger a configuration reload in the service\&. This argument takes multiple command lines, following the same scheme as described for
652 \fIExecStart=\fR
653 above\&. Use of this setting is optional\&. Specifier and environment variable substitution is supported here following the same scheme as for
654 \fIExecStart=\fR\&.
655 .sp
656 One additional, special environment variable is set: if known,
657 \fI$MAINPID\fR
658 is set to the main process of the daemon, and may be used for command lines like the following:
659 .sp
660 .if n \{\
661 .RS 4
662 .\}
663 .nf
664 ExecReload=kill \-HUP $MAINPID
665 .fi
666 .if n \{\
667 .RE
668 .\}
669 .sp
670 Note however that reloading a daemon by enqueuing a signal (as with the example line above) is usually not a good choice, because this is an asynchronous operation and hence not suitable when ordering reloads of multiple services against each other\&. It is thus strongly recommended to either use
671 \fIType=\fR\fBnotify\-reload\fR
672 in place of
673 \fIExecReload=\fR, or to set
674 \fIExecReload=\fR
675 to a command that not only triggers a configuration reload of the daemon, but also synchronously waits for it to complete\&. For example,
676 \fBdbus-broker\fR(1)
677 uses the following:
678 .sp
679 .if n \{\
680 .RS 4
681 .\}
682 .nf
683 ExecReload=busctl call org\&.freedesktop\&.DBus \e
684 /org/freedesktop/DBus org\&.freedesktop\&.DBus \e
685 ReloadConfig
686 .fi
687 .if n \{\
688 .RE
689 .\}
690 .RE
691 .PP
692 \fIExecStop=\fR
693 .RS 4
694 Commands to execute to stop the service started via
695 \fIExecStart=\fR\&. This argument takes multiple command lines, following the same scheme as described for
696 \fIExecStart=\fR
697 above\&. Use of this setting is optional\&. After the commands configured in this option are run, it is implied that the service is stopped, and any processes remaining for it are terminated according to the
698 \fIKillMode=\fR
699 setting (see
700 \fBsystemd.kill\fR(5))\&. If this option is not specified, the process is terminated by sending the signal specified in
701 \fIKillSignal=\fR
702 or
703 \fIRestartKillSignal=\fR
704 when service stop is requested\&. Specifier and environment variable substitution is supported (including
705 \fI$MAINPID\fR, see above)\&.
706 .sp
707 Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by sending some form of termination signal to it), but does not wait for it to do so\&. Since the remaining processes of the services are killed according to
708 \fIKillMode=\fR
709 and
710 \fIKillSignal=\fR
711 or
712 \fIRestartKillSignal=\fR
713 as described above immediately after the command exited, this may not result in a clean stop\&. The specified command should hence be a synchronous operation, not an asynchronous one\&.
714 .sp
715 Note that the commands specified in
716 \fIExecStop=\fR
717 are only executed when the service started successfully first\&. They are not invoked if the service was never started at all, or in case its start\-up failed, for example because any of the commands specified in
718 \fIExecStart=\fR,
719 \fIExecStartPre=\fR
720 or
721 \fIExecStartPost=\fR
722 failed (and were not prefixed with
723 "\-", see above) or timed out\&. Use
724 \fIExecStopPost=\fR
725 to invoke commands when a service failed to start up correctly and is shut down again\&. Also note that the stop operation is always performed if the service started successfully, even if the processes in the service terminated on their own or were killed\&. The stop commands must be prepared to deal with that case\&.
726 \fI$MAINPID\fR
727 will be unset if systemd knows that the main process exited by the time the stop commands are called\&.
728 .sp
729 Service restart requests are implemented as stop operations followed by start operations\&. This means that
730 \fIExecStop=\fR
731 and
732 \fIExecStopPost=\fR
733 are executed during a service restart operation\&.
734 .sp
735 It is recommended to use this setting for commands that communicate with the service requesting clean termination\&. For post\-mortem clean\-up steps use
736 \fIExecStopPost=\fR
737 instead\&.
738 .RE
739 .PP
740 \fIExecStopPost=\fR
741 .RS 4
742 Additional commands that are executed after the service is stopped\&. This includes cases where the commands configured in
743 \fIExecStop=\fR
744 were used, where the service does not have any
745 \fIExecStop=\fR
746 defined, or where the service exited unexpectedly\&. This argument takes multiple command lines, following the same scheme as described for
747 \fIExecStart=\fR\&. Use of these settings is optional\&. Specifier and environment variable substitution is supported\&. Note that \(en unlike
748 \fIExecStop=\fR
749 \(en commands specified with this setting are invoked when a service failed to start up correctly and is shut down again\&.
750 .sp
751 It is recommended to use this setting for clean\-up operations that shall be executed even when the service failed to start up correctly\&. Commands configured with this setting need to be able to operate even if the service failed starting up half\-way and left incompletely initialized data around\&. As the service\*(Aqs processes have likely exited already when the commands specified with this setting are executed they should not attempt to communicate with them\&.
752 .sp
753 Note that all commands that are configured with this setting are invoked with the result code of the service, as well as the main process\*(Aq exit code and status, set in the
754 \fI$SERVICE_RESULT\fR,
755 \fI$EXIT_CODE\fR
756 and
757 \fI$EXIT_STATUS\fR
758 environment variables, see
759 \fBsystemd.exec\fR(5)
760 for details\&.
761 .sp
762 Note that the execution of
763 \fIExecStopPost=\fR
764 is taken into account for the purpose of
765 \fIBefore=\fR/\fIAfter=\fR
766 ordering constraints\&.
767 .RE
768 .PP
769 \fIRestartSec=\fR
770 .RS 4
771 Configures the time to sleep before restarting a service (as configured with
772 \fIRestart=\fR)\&. Takes a unit\-less value in seconds, or a time span value such as "5min 20s"\&. Defaults to 100ms\&.
773 .RE
774 .PP
775 \fIRestartSteps=\fR
776 .RS 4
777 Configures the number of exponential steps to take to increase the interval of auto\-restarts from
778 \fIRestartSec=\fR
779 to
780 \fIRestartMaxDelaySec=\fR\&. Takes a positive integer or 0 to disable it\&. Defaults to 0\&.
781 \fIHint:\fR
782 values between 3 and 5 are good choices when exponential backoff is desired\&.
783 .sp
784 Example:
785 .sp
786 .if n \{\
787 .RS 4
788 .\}
789 .nf
790 RestartSec=10s
791 RestartSteps=4
792 RestartMaxDelaySec=160s
793 .fi
794 .if n \{\
795 .RE
796 .\}
797 .sp
798 This will produce the following restart intervals: 10s, 20s, 40s, 80s, 160s, 160s, 160s, etc\&. Notice the geometric interpolation and the resulting constant ratio between intervals; here it is 2\&. The formula for the
799 \fIratio\fR
800 is
801 (\fIRestartMaxDelaySec\fR / \fIRestartSec\fR)^(1 / \fIRestartSteps\fR)\&. A (repeating) delay equal to
802 \fIRestartMaxDelaySec=\fR
803 is always reached after
804 \fIRestartSteps\fR + 1
805 steps\&.
806 .sp
807 This setting is effective only if
808 \fIRestartMaxDelaySec=\fR
809 is also set and
810 \fIRestartSec=\fR
811 is not zero\&.
812 .sp
813 Added in version 254\&.
814 .RE
815 .PP
816 \fIRestartMaxDelaySec=\fR
817 .RS 4
818 Configures the longest time to sleep before restarting a service as the interval goes up with
819 \fIRestartSteps=\fR\&. Takes a value in the same format as
820 \fIRestartSec=\fR, or
821 "infinity"
822 to disable the setting\&. Defaults to
823 "infinity"\&.
824 .sp
825 This setting is effective only if
826 \fIRestartSteps=\fR
827 is also set and
828 \fIRestartSec=\fR
829 is not zero\&.
830 .sp
831 Added in version 254\&.
832 .RE
833 .PP
834 \fITimeoutStartSec=\fR
835 .RS 4
836 Configures the time to wait for start\-up\&. If a daemon service does not signal start\-up completion within the configured time, the service will be considered failed and will be shut down again\&. The precise action depends on the
837 \fITimeoutStartFailureMode=\fR
838 option\&. Takes a unit\-less value in seconds, or a time span value such as "5min 20s"\&. Pass
839 "infinity"
840 to disable the timeout logic\&. Defaults to
841 \fIDefaultTimeoutStartSec=\fR
842 set in the manager, except when
843 \fIType=oneshot\fR
844 is used, in which case the timeout is disabled by default (see
845 \fBsystemd-system.conf\fR(5))\&.
846 .sp
847 If a service of
848 \fIType=notify\fR/\fIType=notify\-reload\fR
849 sends
850 "EXTEND_TIMEOUT_USEC=\&...", this may cause the start time to be extended beyond
851 \fITimeoutStartSec=\fR\&. The first receipt of this message must occur before
852 \fITimeoutStartSec=\fR
853 is exceeded, and once the start time has extended beyond
854 \fITimeoutStartSec=\fR, the service manager will allow the service to continue to start, provided the service repeats
855 "EXTEND_TIMEOUT_USEC=\&..."
856 within the interval specified until the service startup status is finished by
857 "READY=1"\&. (see
858 \fBsd_notify\fR(3))\&.
859 .sp
860 Note that the start timeout is also applied to service reloads, regardless if implemented through
861 \fIExecReload=\fR
862 or via the reload logic enabled via
863 \fIType=notify\-reload\fR\&. If the reload does not complete within the configured time, the reload will be considered failed and the service will continue running with the old configuration\&. This will not affect the running service, but will be logged and will cause e\&.g\&.
864 \fBsystemctl reload\fR
865 to fail\&.
866 .sp
867 Added in version 188\&.
868 .RE
869 .PP
870 \fITimeoutStopSec=\fR
871 .RS 4
872 This option serves two purposes\&. First, it configures the time to wait for each
873 \fIExecStop=\fR
874 command\&. If any of them times out, subsequent
875 \fIExecStop=\fR
876 commands are skipped and the service will be terminated by
877 \fBSIGTERM\fR\&. If no
878 \fIExecStop=\fR
879 commands are specified, the service gets the
880 \fBSIGTERM\fR
881 immediately\&. This default behavior can be changed by the
882 \fITimeoutStopFailureMode=\fR
883 option\&. Second, it configures the time to wait for the service itself to stop\&. If it does not terminate in the specified time, it will be forcibly terminated by
884 \fBSIGKILL\fR
885 (see
886 \fIKillMode=\fR
887 in
888 \fBsystemd.kill\fR(5))\&. Takes a unit\-less value in seconds, or a time span value such as "5min 20s"\&. Pass
889 "infinity"
890 to disable the timeout logic\&. Defaults to
891 \fIDefaultTimeoutStopSec=\fR
892 from the manager configuration file (see
893 \fBsystemd-system.conf\fR(5))\&.
894 .sp
895 If a service of
896 \fIType=notify\fR/\fIType=notify\-reload\fR
897 sends
898 "EXTEND_TIMEOUT_USEC=\&...", this may cause the stop time to be extended beyond
899 \fITimeoutStopSec=\fR\&. The first receipt of this message must occur before
900 \fITimeoutStopSec=\fR
901 is exceeded, and once the stop time has extended beyond
902 \fITimeoutStopSec=\fR, the service manager will allow the service to continue to stop, provided the service repeats
903 "EXTEND_TIMEOUT_USEC=\&..."
904 within the interval specified, or terminates itself (see
905 \fBsd_notify\fR(3))\&.
906 .sp
907 Added in version 188\&.
908 .RE
909 .PP
910 \fITimeoutAbortSec=\fR
911 .RS 4
912 This option configures the time to wait for the service to terminate when it was aborted due to a watchdog timeout (see
913 \fIWatchdogSec=\fR)\&. If the service has a short
914 \fITimeoutStopSec=\fR
915 this option can be used to give the system more time to write a core dump of the service\&. Upon expiration the service will be forcibly terminated by
916 \fBSIGKILL\fR
917 (see
918 \fIKillMode=\fR
919 in
920 \fBsystemd.kill\fR(5))\&. The core file will be truncated in this case\&. Use
921 \fITimeoutAbortSec=\fR
922 to set a sensible timeout for the core dumping per service that is large enough to write all expected data while also being short enough to handle the service failure in due time\&.
923 .sp
924 Takes a unit\-less value in seconds, or a time span value such as "5min 20s"\&. Pass an empty value to skip the dedicated watchdog abort timeout handling and fall back
925 \fITimeoutStopSec=\fR\&. Pass
926 "infinity"
927 to disable the timeout logic\&. Defaults to
928 \fIDefaultTimeoutAbortSec=\fR
929 from the manager configuration file (see
930 \fBsystemd-system.conf\fR(5))\&.
931 .sp
932 If a service of
933 \fIType=notify\fR/\fIType=notify\-reload\fR
934 handles
935 \fBSIGABRT\fR
936 itself (instead of relying on the kernel to write a core dump) it can send
937 "EXTEND_TIMEOUT_USEC=\&..."
938 to extended the abort time beyond
939 \fITimeoutAbortSec=\fR\&. The first receipt of this message must occur before
940 \fITimeoutAbortSec=\fR
941 is exceeded, and once the abort time has extended beyond
942 \fITimeoutAbortSec=\fR, the service manager will allow the service to continue to abort, provided the service repeats
943 "EXTEND_TIMEOUT_USEC=\&..."
944 within the interval specified, or terminates itself (see
945 \fBsd_notify\fR(3))\&.
946 .sp
947 Added in version 243\&.
948 .RE
949 .PP
950 \fITimeoutSec=\fR
951 .RS 4
952 A shorthand for configuring both
953 \fITimeoutStartSec=\fR
954 and
955 \fITimeoutStopSec=\fR
956 to the specified value\&.
957 .RE
958 .PP
959 \fITimeoutStartFailureMode=\fR, \fITimeoutStopFailureMode=\fR
960 .RS 4
961 These options configure the action that is taken in case a daemon service does not signal start\-up within its configured
962 \fITimeoutStartSec=\fR, respectively if it does not stop within
963 \fITimeoutStopSec=\fR\&. Takes one of
964 \fBterminate\fR,
965 \fBabort\fR
966 and
967 \fBkill\fR\&. Both options default to
968 \fBterminate\fR\&.
969 .sp
970 If
971 \fBterminate\fR
972 is set the service will be gracefully terminated by sending the signal specified in
973 \fIKillSignal=\fR
974 (defaults to
975 \fBSIGTERM\fR, see
976 \fBsystemd.kill\fR(5))\&. If the service does not terminate the
977 \fIFinalKillSignal=\fR
978 is sent after
979 \fITimeoutStopSec=\fR\&. If
980 \fBabort\fR
981 is set,
982 \fIWatchdogSignal=\fR
983 is sent instead and
984 \fITimeoutAbortSec=\fR
985 applies before sending
986 \fIFinalKillSignal=\fR\&. This setting may be used to analyze services that fail to start\-up or shut\-down intermittently\&. By using
987 \fBkill\fR
988 the service is immediately terminated by sending
989 \fIFinalKillSignal=\fR
990 without any further timeout\&. This setting can be used to expedite the shutdown of failing services\&.
991 .sp
992 Added in version 246\&.
993 .RE
994 .PP
995 \fIRuntimeMaxSec=\fR
996 .RS 4
997 Configures a maximum time for the service to run\&. If this is used and the service has been active for longer than the specified time it is terminated and put into a failure state\&. Note that this setting does not have any effect on
998 \fIType=oneshot\fR
999 services, as they terminate immediately after activation completed (use
1000 \fITimeoutStartSec=\fR
1001 to limit their activation)\&. Pass
1002 "infinity"
1003 (the default) to configure no runtime limit\&.
1004 .sp
1005 If a service of
1006 \fIType=notify\fR/\fIType=notify\-reload\fR
1007 sends
1008 "EXTEND_TIMEOUT_USEC=\&...", this may cause the runtime to be extended beyond
1009 \fIRuntimeMaxSec=\fR\&. The first receipt of this message must occur before
1010 \fIRuntimeMaxSec=\fR
1011 is exceeded, and once the runtime has extended beyond
1012 \fIRuntimeMaxSec=\fR, the service manager will allow the service to continue to run, provided the service repeats
1013 "EXTEND_TIMEOUT_USEC=\&..."
1014 within the interval specified until the service shutdown is achieved by
1015 "STOPPING=1"
1016 (or termination)\&. (see
1017 \fBsd_notify\fR(3))\&.
1018 .sp
1019 Added in version 229\&.
1020 .RE
1021 .PP
1022 \fIRuntimeRandomizedExtraSec=\fR
1023 .RS 4
1024 This option modifies
1025 \fIRuntimeMaxSec=\fR
1026 by increasing the maximum runtime by an evenly distributed duration between 0 and the specified value (in seconds)\&. If
1027 \fIRuntimeMaxSec=\fR
1028 is unspecified, then this feature will be disabled\&.
1029 .sp
1030 Added in version 250\&.
1031 .RE
1032 .PP
1033 \fIWatchdogSec=\fR
1034 .RS 4
1035 Configures the watchdog timeout for a service\&. The watchdog is activated when the start\-up is completed\&. The service must call
1036 \fBsd_notify\fR(3)
1037 regularly with
1038 "WATCHDOG=1"
1039 (i\&.e\&. the "keep\-alive ping")\&. If the time between two such calls is larger than the configured time, then the service is placed in a failed state and it will be terminated with
1040 \fBSIGABRT\fR
1041 (or the signal specified by
1042 \fIWatchdogSignal=\fR)\&. By setting
1043 \fIRestart=\fR
1044 to
1045 \fBon\-failure\fR,
1046 \fBon\-watchdog\fR,
1047 \fBon\-abnormal\fR
1048 or
1049 \fBalways\fR, the service will be automatically restarted\&. The time configured here will be passed to the executed service process in the
1050 \fIWATCHDOG_USEC=\fR
1051 environment variable\&. This allows daemons to automatically enable the keep\-alive pinging logic if watchdog support is enabled for the service\&. If this option is used,
1052 \fINotifyAccess=\fR
1053 (see below) should be set to open access to the notification socket provided by systemd\&. If
1054 \fINotifyAccess=\fR
1055 is not set, it will be implicitly set to
1056 \fBmain\fR\&. Defaults to 0, which disables this feature\&. The service can check whether the service manager expects watchdog keep\-alive notifications\&. See
1057 \fBsd_watchdog_enabled\fR(3)
1058 for details\&.
1059 \fBsd_event_set_watchdog\fR(3)
1060 may be used to enable automatic watchdog notification support\&.
1061 .RE
1062 .PP
1063 \fIRestart=\fR
1064 .RS 4
1065 Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached\&. The service process may be the main service process, but it may also be one of the processes specified with
1066 \fIExecStartPre=\fR,
1067 \fIExecStartPost=\fR,
1068 \fIExecStop=\fR,
1069 \fIExecStopPost=\fR, or
1070 \fIExecReload=\fR\&. When the death of the process is a result of systemd operation (e\&.g\&. service stop or restart), the service will not be restarted\&. Timeouts include missing the watchdog "keep\-alive ping" deadline and a service start, reload, and stop operation timeouts\&.
1071 .sp
1072 Takes one of
1073 \fBno\fR,
1074 \fBon\-success\fR,
1075 \fBon\-failure\fR,
1076 \fBon\-abnormal\fR,
1077 \fBon\-watchdog\fR,
1078 \fBon\-abort\fR, or
1079 \fBalways\fR\&. If set to
1080 \fBno\fR
1081 (the default), the service will not be restarted\&. If set to
1082 \fBon\-success\fR, it will be restarted only when the service process exits cleanly\&. In this context, a clean exit means any of the following:
1083 .sp
1084 .RS 4
1085 .ie n \{\
1086 \h'-04'\(bu\h'+03'\c
1087 .\}
1088 .el \{\
1089 .sp -1
1090 .IP \(bu 2.3
1091 .\}
1092 exit code of 0;
1093 .RE
1094 .sp
1095 .RS 4
1096 .ie n \{\
1097 \h'-04'\(bu\h'+03'\c
1098 .\}
1099 .el \{\
1100 .sp -1
1101 .IP \(bu 2.3
1102 .\}
1103 for types other than
1104 \fIType=oneshot\fR, one of the signals
1105 \fBSIGHUP\fR,
1106 \fBSIGINT\fR,
1107 \fBSIGTERM\fR, or
1108 \fBSIGPIPE\fR;
1109 .RE
1110 .sp
1111 .RS 4
1112 .ie n \{\
1113 \h'-04'\(bu\h'+03'\c
1114 .\}
1115 .el \{\
1116 .sp -1
1117 .IP \(bu 2.3
1118 .\}
1119 exit statuses and signals specified in
1120 \fISuccessExitStatus=\fR\&.
1121 .RE
1122 .sp
1123 If set to
1124 \fBon\-failure\fR, the service will be restarted when the process exits with a non\-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered\&. If set to
1125 \fBon\-abnormal\fR, the service will be restarted when the process is terminated by a signal (including on core dump, excluding the aforementioned four signals), when an operation times out, or when the watchdog timeout is triggered\&. If set to
1126 \fBon\-abort\fR, the service will be restarted only if the service process exits due to an uncaught signal not specified as a clean exit status\&. If set to
1127 \fBon\-watchdog\fR, the service will be restarted only if the watchdog timeout for the service expires\&. If set to
1128 \fBalways\fR, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout\&. Note that
1129 \fIType=oneshot\fR
1130 services will never be restarted on a clean exit status, i\&.e\&.
1131 \fBalways\fR
1132 and
1133 \fBon\-success\fR
1134 are rejected for them\&.
1135 .sp
1136 .it 1 an-trap
1137 .nr an-no-space-flag 1
1138 .nr an-break-flag 1
1139 .br
1140 .B Table\ \&1.\ \&Exit causes and the effect of the \fIRestart=\fR settings
1141 .TS
1142 allbox tab(:);
1143 lB lB lB lB lB lB lB lB.
1144 T{
1145 Restart settings/Exit causes
1146 T}:T{
1147 \fBno\fR
1148 T}:T{
1149 \fBalways\fR
1150 T}:T{
1151 \fBon\-success\fR
1152 T}:T{
1153 \fBon\-failure\fR
1154 T}:T{
1155 \fBon\-abnormal\fR
1156 T}:T{
1157 \fBon\-abort\fR
1158 T}:T{
1159 \fBon\-watchdog\fR
1160 T}
1161 .T&
1162 l l l l l l l l
1163 l l l l l l l l
1164 l l l l l l l l
1165 l l l l l l l l
1166 l l l l l l l l.
1167 T{
1168 Clean exit code or signal
1169 T}:T{
1170 \ \&
1171 T}:T{
1172 X
1173 T}:T{
1174 X
1175 T}:T{
1176 \ \&
1177 T}:T{
1178 \ \&
1179 T}:T{
1180 \ \&
1181 T}:T{
1182 \ \&
1183 T}
1184 T{
1185 Unclean exit code
1186 T}:T{
1187 \ \&
1188 T}:T{
1189 X
1190 T}:T{
1191 \ \&
1192 T}:T{
1193 X
1194 T}:T{
1195 \ \&
1196 T}:T{
1197 \ \&
1198 T}:T{
1199 \ \&
1200 T}
1201 T{
1202 Unclean signal
1203 T}:T{
1204 \ \&
1205 T}:T{
1206 X
1207 T}:T{
1208 \ \&
1209 T}:T{
1210 X
1211 T}:T{
1212 X
1213 T}:T{
1214 X
1215 T}:T{
1216 \ \&
1217 T}
1218 T{
1219 Timeout
1220 T}:T{
1221 \ \&
1222 T}:T{
1223 X
1224 T}:T{
1225 \ \&
1226 T}:T{
1227 X
1228 T}:T{
1229 X
1230 T}:T{
1231 \ \&
1232 T}:T{
1233 \ \&
1234 T}
1235 T{
1236 Watchdog
1237 T}:T{
1238 \ \&
1239 T}:T{
1240 X
1241 T}:T{
1242 \ \&
1243 T}:T{
1244 X
1245 T}:T{
1246 X
1247 T}:T{
1248 \ \&
1249 T}:T{
1250 X
1251 T}
1252 .TE
1253 .sp 1
1254 As exceptions to the setting above, the service will not be restarted if the exit code or signal is specified in
1255 \fIRestartPreventExitStatus=\fR
1256 (see below) or the service is stopped with
1257 \fBsystemctl stop\fR
1258 or an equivalent operation\&. Also, the services will always be restarted if the exit code or signal is specified in
1259 \fIRestartForceExitStatus=\fR
1260 (see below)\&.
1261 .sp
1262 Note that service restart is subject to unit start rate limiting configured with
1263 \fIStartLimitIntervalSec=\fR
1264 and
1265 \fIStartLimitBurst=\fR, see
1266 \fBsystemd.unit\fR(5)
1267 for details\&.
1268 .sp
1269 Setting this to
1270 \fBon\-failure\fR
1271 is the recommended choice for long\-running services, in order to increase reliability by attempting automatic recovery from errors\&. For services that shall be able to terminate on their own choice (and avoid immediate restarting),
1272 \fBon\-abnormal\fR
1273 is an alternative choice\&.
1274 .RE
1275 .PP
1276 \fIRestartMode=\fR
1277 .RS 4
1278 Takes a string value that specifies how a service should restart:
1279 .sp
1280 .RS 4
1281 .ie n \{\
1282 \h'-04'\(bu\h'+03'\c
1283 .\}
1284 .el \{\
1285 .sp -1
1286 .IP \(bu 2.3
1287 .\}
1288 If set to
1289 \fBnormal\fR
1290 (the default), the service restarts by going through a failed/inactive state\&.
1291 .sp
1292 Added in version 254\&.
1293 .RE
1294 .sp
1295 .RS 4
1296 .ie n \{\
1297 \h'-04'\(bu\h'+03'\c
1298 .\}
1299 .el \{\
1300 .sp -1
1301 .IP \(bu 2.3
1302 .\}
1303 If set to
1304 \fBdirect\fR, the service transitions to the activating state directly during auto\-restart, skipping failed/inactive state\&.
1305 \fIExecStopPost=\fR
1306 is still invoked\&.
1307 \fIOnSuccess=\fR
1308 and
1309 \fIOnFailure=\fR
1310 are skipped\&.
1311 .sp
1312 This option is useful in cases where a dependency can fail temporarily but we do not want these temporary failures to make the dependent units fail\&. Dependent units are not notified of these temporary failures\&.
1313 .sp
1314 Added in version 254\&.
1315 .RE
1316 .sp
1317 .RS 4
1318 .ie n \{\
1319 \h'-04'\(bu\h'+03'\c
1320 .\}
1321 .el \{\
1322 .sp -1
1323 .IP \(bu 2.3
1324 .\}
1325 If set to
1326 \fBdebug\fR, the service manager will log messages that are related to this unit at debug level while automated restarts are attempted, until either the service hits the rate limit or it succeeds, and the
1327 \fI$DEBUG_INVOCATION=1\fR
1328 environment variable will be set for the unit\&. This is useful to be able to get additional information when a service fails to start, without needing to proactively or permanently enable debug level logging in systemd, which is very verbose\&. This is otherwise equivalent to
1329 \fBnormal\fR
1330 mode\&.
1331 .sp
1332 Added in version 257\&.
1333 .RE
1334 .sp
1335 Added in version 254\&.
1336 .RE
1337 .PP
1338 \fISuccessExitStatus=\fR
1339 .RS 4
1340 Takes a list of exit status definitions that, when returned by the main service process, will be considered successful termination, in addition to the normal successful exit status 0 and, except for
1341 \fIType=oneshot\fR, the signals
1342 \fBSIGHUP\fR,
1343 \fBSIGINT\fR,
1344 \fBSIGTERM\fR, and
1345 \fBSIGPIPE\fR\&. Exit status definitions can be numeric termination statuses, termination status names, or termination signal names, separated by spaces\&. See the Process Exit Codes section in
1346 \fBsystemd.exec\fR(5)
1347 for a list of termination status names (for this setting only the part without the
1348 "EXIT_"
1349 or
1350 "EX_"
1351 prefix should be used)\&. See
1352 \fBsignal\fR(7)
1353 for a list of signal names\&.
1354 .sp
1355 Note that this setting does not change the mapping between numeric exit statuses and their names, i\&.e\&. regardless how this setting is used 0 will still be mapped to
1356 "SUCCESS"
1357 (and thus typically shown as
1358 "0/SUCCESS"
1359 in tool outputs) and 1 to
1360 "FAILURE"
1361 (and thus typically shown as
1362 "1/FAILURE"), and so on\&. It only controls what happens as effect of these exit statuses, and how it propagates to the state of the service as a whole\&.
1363 .sp
1364 This option may appear more than once, in which case the list of successful exit statuses is merged\&. If the empty string is assigned to this option, the list is reset, all prior assignments of this option will have no effect\&.
1365 .PP
1366 \fBExample\ \&1.\ \&A service with the \fISuccessExitStatus=\fR setting\fR
1367 .sp
1368 .if n \{\
1369 .RS 4
1370 .\}
1371 .nf
1372 SuccessExitStatus=TEMPFAIL 250 SIGKILL
1373 .fi
1374 .if n \{\
1375 .RE
1376 .\}
1377 .sp
1378 Exit status 75 (\fBTEMPFAIL\fR), 250, and the termination signal
1379 \fBSIGKILL\fR
1380 are considered clean service terminations\&.
1381
1382 Note:
1383 \fBsystemd\-analyze exit\-status\fR
1384 may be used to list exit statuses and translate between numerical status values and names\&.
1385 .sp
1386 Added in version 189\&.
1387 .RE
1388 .PP
1389 \fIRestartPreventExitStatus=\fR
1390 .RS 4
1391 Takes a list of exit status definitions that, when returned by the main service process, will prevent automatic service restarts, regardless of the restart setting configured with
1392 \fIRestart=\fR\&. Exit status definitions can be numeric termination statuses, termination status names, or termination signal names, separated by spaces\&. Defaults to the empty list, so that, by default, no exit status is excluded from the configured restart logic\&.
1393 .PP \fBExample\ \&2.\ \&A service with the \fIRestartPreventExitStatus=\fR setting\fR .sp .if n \{\ .RS 4 .\} .nf RestartPreventExitStatus=TEMPFAIL 250 SIGKILL .fi .if n \{\ .RE .\} .sp Exit status 75 (\fBTEMPFAIL\fR), 250, and the termination signal \fBSIGKILL\fR will not result in automatic service restarting\&.
1394 This option may appear more than once, in which case the list of restart\-preventing statuses is merged\&. If the empty string is assigned to this option, the list is reset and all prior assignments of this option will have no effect\&.
1395 .sp
1396 Note that this setting has no effect on processes configured via
1397 \fIExecStartPre=\fR,
1398 \fIExecStartPost=\fR,
1399 \fIExecStop=\fR,
1400 \fIExecStopPost=\fR
1401 or
1402 \fIExecReload=\fR, but only on the main service process, i\&.e\&. either the one invoked by
1403 \fIExecStart=\fR
1404 or (depending on
1405 \fIType=\fR,
1406 \fIPIDFile=\fR, \&...) the otherwise configured main process\&.
1407 .sp
1408 Added in version 189\&.
1409 .RE
1410 .PP
1411 \fIRestartForceExitStatus=\fR
1412 .RS 4
1413 Takes a list of exit status definitions that, when returned by the main service process, will force automatic service restarts, regardless of the restart setting configured with
1414 \fIRestart=\fR\&. The argument format is similar to
1415 \fIRestartPreventExitStatus=\fR\&.
1416 .sp
1417 Note that for
1418 \fIType=oneshot\fR
1419 services, a success exit status will prevent them from auto\-restarting, no matter whether the corresponding exit statuses are listed in this option or not\&.
1420 .sp
1421 Added in version 215\&.
1422 .RE
1423 .PP
1424 \fIRootDirectoryStartOnly=\fR
1425 .RS 4
1426 Takes a boolean argument\&. If true, the root directory, as configured with the
1427 \fIRootDirectory=\fR
1428 option (see
1429 \fBsystemd.exec\fR(5)
1430 for more information), is only applied to the process started with
1431 \fIExecStart=\fR, and not to the various other
1432 \fIExecStartPre=\fR,
1433 \fIExecStartPost=\fR,
1434 \fIExecReload=\fR,
1435 \fIExecStop=\fR, and
1436 \fIExecStopPost=\fR
1437 commands\&. If false, the setting is applied to all configured commands the same way\&. Defaults to false\&.
1438 .RE
1439 .PP
1440 \fINonBlocking=\fR
1441 .RS 4
1442 Set the
1443 \fBO_NONBLOCK\fR
1444 flag for all file descriptors passed via socket\-based activation\&. If true, all file descriptors >= 3 (i\&.e\&. all except stdin, stdout, stderr), excluding those passed in via the file descriptor storage logic (see
1445 \fIFileDescriptorStoreMax=\fR
1446 for details), will have the
1447 \fBO_NONBLOCK\fR
1448 flag set and hence are in non\-blocking mode\&. This option is only useful in conjunction with a socket unit, as described in
1449 \fBsystemd.socket\fR(5)
1450 and has no effect on file descriptors which were previously saved in the file\-descriptor store for example\&. Defaults to false\&.
1451 .sp
1452 Note that if the same socket unit is configured to be passed to multiple service units (via the
1453 \fISockets=\fR
1454 setting, see below), and these services have different
1455 \fINonBlocking=\fR
1456 configurations, the precise state of
1457 \fBO_NONBLOCK\fR
1458 depends on the order in which these services are invoked, and will possibly change after service code already took possession of the socket file descriptor, simply because the
1459 \fBO_NONBLOCK\fR
1460 state of a socket is shared by all file descriptors referencing it\&. Hence it is essential that all services sharing the same socket use the same
1461 \fINonBlocking=\fR
1462 configuration, and do not change the flag in service code either\&.
1463 .RE
1464 .PP
1465 \fINotifyAccess=\fR
1466 .RS 4
1467 Controls access to the service status notification socket, as accessible via the
1468 \fBsd_notify\fR(3)
1469 call\&. Takes one of
1470 \fBnone\fR
1471 (the default),
1472 \fBmain\fR,
1473 \fBexec\fR
1474 or
1475 \fBall\fR\&. If
1476 \fBnone\fR, no daemon status updates are accepted from the service processes, all status update messages are ignored\&. If
1477 \fBmain\fR, only service updates sent from the main process of the service are accepted\&. If
1478 \fBexec\fR, only service updates sent from any of the main or control processes originating from one of the
1479 \fIExec*=\fR
1480 commands are accepted\&. If
1481 \fBall\fR, all services updates from all members of the service\*(Aqs control group are accepted\&. This option should be set to open access to the notification socket when using
1482 \fIType=notify\fR/\fIType=notify\-reload\fR
1483 or
1484 \fIWatchdogSec=\fR
1485 (see above)\&. If those options are used but
1486 \fINotifyAccess=\fR
1487 is not configured, it will be implicitly set to
1488 \fBmain\fR\&.
1489 .sp
1490 Note that
1491 \fBsd_notify()\fR
1492 notifications may be attributed to units correctly only if either the sending process is still around at the time PID 1 processes the message, or if the sending process is explicitly runtime\-tracked by the service manager\&. The latter is the case if the service manager originally forked off the process, i\&.e\&. on all processes that match
1493 \fBmain\fR
1494 or
1495 \fBexec\fR\&. Conversely, if an auxiliary process of the unit sends an
1496 \fBsd_notify()\fR
1497 message and immediately exits, the service manager might not be able to properly attribute the message to the unit, and thus will ignore it, even if
1498 \fINotifyAccess=\fR\fBall\fR
1499 is set for it\&.
1500 .sp
1501 Hence, to eliminate all race conditions involving lookup of the client\*(Aqs unit and attribution of notifications to units correctly,
1502 \fBsd_notify_barrier()\fR
1503 may be used\&. This call acts as a synchronization point and ensures all notifications sent before this call have been picked up by the service manager when it returns successfully\&. Use of
1504 \fBsd_notify_barrier()\fR
1505 is needed for clients which are not invoked by the service manager, otherwise this synchronization mechanism is unnecessary for attribution of notifications to the unit\&.
1506 .RE
1507 .PP
1508 \fISockets=\fR
1509 .RS 4
1510 Specifies the name of the socket units this service shall inherit socket file descriptors from when the service is started\&. Normally, it should not be necessary to use this setting, as all socket file descriptors whose unit shares the same name as the service (subject to the different unit name suffix of course) are passed to the spawned process\&.
1511 .sp
1512 Note that the same socket file descriptors may be passed to multiple processes simultaneously\&. Also note that a different service may be activated on incoming socket traffic than the one which is ultimately configured to inherit the socket file descriptors\&. Or, in other words: the
1513 \fIService=\fR
1514 setting of
1515 \&.socket
1516 units does not have to match the inverse of the
1517 \fISockets=\fR
1518 setting of the
1519 \&.service
1520 it refers to\&.
1521 .sp
1522 This option may appear more than once, in which case the list of socket units is merged\&. Note that once set, clearing the list of sockets again (for example, by assigning the empty string to this option) is not supported\&.
1523 .RE
1524 .PP
1525 \fIFileDescriptorStoreMax=\fR
1526 .RS 4
1527 Configure how many file descriptors may be stored in the service manager for the service using
1528 \fBsd_pid_notify_with_fds\fR(3)\*(Aqs
1529 "FDSTORE=1"
1530 messages\&. This is useful for implementing services that can restart after an explicit request or a crash without losing state\&. Any open sockets and other file descriptors which should not be closed during the restart may be stored this way\&. Application state can either be serialized to a file in
1531 \fIRuntimeDirectory=\fR, or stored in a
1532 \fBmemfd_create\fR(2)
1533 memory file descriptor\&. Defaults to 0, i\&.e\&. no file descriptors may be stored in the service manager\&. All file descriptors passed to the service manager from a specific service are passed back to the service\*(Aqs main process on the next service restart (see
1534 \fBsd_listen_fds\fR(3)
1535 for details about the precise protocol used and the order in which the file descriptors are passed)\&. Any file descriptors passed to the service manager are automatically closed when
1536 \fBPOLLHUP\fR
1537 or
1538 \fBPOLLERR\fR
1539 is seen on them, or when the service is fully stopped and no job is queued or being executed for it (the latter can be tweaked with
1540 \fIFileDescriptorStorePreserve=\fR, see below)\&. If this option is used,
1541 \fINotifyAccess=\fR
1542 (see above) should be set to open access to the notification socket provided by systemd\&. If
1543 \fINotifyAccess=\fR
1544 is not set, it will be implicitly set to
1545 \fBmain\fR\&.
1546 .sp
1547 The
1548 \fBfdstore\fR
1549 command of
1550 \fBsystemd-analyze\fR(1)
1551 may be used to list the current contents of a service\*(Aqs file descriptor store\&.
1552 .sp
1553 Note that the service manager will only pass file descriptors contained in the file descriptor store to the service\*(Aqs own processes, never to other clients via IPC or similar\&. However, it does allow unprivileged clients to query the list of currently open file descriptors of a service\&. Sensitive data may hence be safely placed inside the referenced files, but should not be attached to the metadata (e\&.g\&. included in filenames) of the stored file descriptors\&.
1554 .sp
1555 If this option is set to a non\-zero value the
1556 \fI$FDSTORE\fR
1557 environment variable will be set for processes invoked for this service\&. See
1558 \fBsystemd.exec\fR(5)
1559 for details\&.
1560 .sp
1561 For further information on the file descriptor store see the
1562 \m[blue]\fBFile Descriptor Store\fR\m[]\&\s-2\u[1]\d\s+2
1563 overview\&.
1564 .sp
1565 Added in version 219\&.
1566 .RE
1567 .PP
1568 \fIFileDescriptorStorePreserve=\fR
1569 .RS 4
1570 Takes one of
1571 \fBno\fR,
1572 \fByes\fR,
1573 \fBrestart\fR
1574 and controls when to release the service\*(Aqs file descriptor store (i\&.e\&. when to close the contained file descriptors, if any)\&. If set to
1575 \fBno\fR
1576 the file descriptor store is automatically released when the service is stopped; if
1577 \fBrestart\fR
1578 (the default) it is kept around as long as the unit is neither inactive nor failed, or a job is queued for the service, or the service is expected to be restarted\&. If
1579 \fByes\fR
1580 the file descriptor store is kept around until the unit is removed from memory (i\&.e\&. is not referenced anymore and inactive)\&. The latter is useful to keep entries in the file descriptor store pinned until the service manager exits\&.
1581 .sp
1582 Use
1583 \fBsystemctl clean \-\-what=fdstore \&...\fR
1584 to release the file descriptor store explicitly\&.
1585 .sp
1586 Added in version 254\&.
1587 .RE
1588 .PP
1589 \fIUSBFunctionDescriptors=\fR
1590 .RS 4
1591 Configure the location of a file containing
1592 \m[blue]\fBUSB FunctionFS\fR\m[]\&\s-2\u[2]\d\s+2
1593 descriptors, for implementation of USB gadget functions\&. This is used only in conjunction with a socket unit with
1594 \fIListenUSBFunction=\fR
1595 configured\&. The contents of this file are written to the
1596 ep0
1597 file after it is opened\&.
1598 .sp
1599 Added in version 227\&.
1600 .RE
1601 .PP
1602 \fIUSBFunctionStrings=\fR
1603 .RS 4
1604 Configure the location of a file containing USB FunctionFS strings\&. Behavior is similar to
1605 \fIUSBFunctionDescriptors=\fR
1606 above\&.
1607 .sp
1608 Added in version 227\&.
1609 .RE
1610 .PP
1611 \fIOOMPolicy=\fR
1612 .RS 4
1613 Configure the out\-of\-memory (OOM) killing policy for the kernel and the userspace OOM killer
1614 \fBsystemd-oomd.service\fR(8)\&. On Linux, when memory becomes scarce to the point that the kernel has trouble allocating memory for itself, it might decide to kill a running process in order to free up memory and reduce memory pressure\&. Note that
1615 systemd\-oomd\&.service
1616 is a more flexible solution that aims to prevent out\-of\-memory situations for the userspace too, not just the kernel, by attempting to terminate services earlier, before the kernel would have to act\&.
1617 .sp
1618 This setting takes one of
1619 \fBcontinue\fR,
1620 \fBstop\fR
1621 or
1622 \fBkill\fR\&. If set to
1623 \fBcontinue\fR
1624 and a process in the unit is killed by the OOM killer, this is logged but the unit continues running\&. If set to
1625 \fBstop\fR
1626 the event is logged but the unit is terminated cleanly by the service manager\&. If set to
1627 \fBkill\fR
1628 and one of the unit\*(Aqs processes is killed by the OOM killer the kernel is instructed to kill all remaining processes of the unit too, by setting the
1629 memory\&.oom\&.group
1630 attribute to
1631 \fB1\fR; also see kernel page
1632 \m[blue]\fBControl Group v2\fR\m[]\&\s-2\u[3]\d\s+2\&.
1633 .sp
1634 Defaults to the setting
1635 \fIDefaultOOMPolicy=\fR
1636 in
1637 \fBsystemd-system.conf\fR(5)
1638 is set to, except for units where
1639 \fIDelegate=\fR
1640 is turned on, where it defaults to
1641 \fBcontinue\fR\&.
1642 .sp
1643 Use the
1644 \fIOOMScoreAdjust=\fR
1645 setting to configure whether processes of the unit shall be considered preferred or less preferred candidates for process termination by the Linux OOM killer logic\&. See
1646 \fBsystemd.exec\fR(5)
1647 for details\&.
1648 .sp
1649 This setting also applies to
1650 \fBsystemd-oomd.service\fR(8)\&. Similarly to the kernel OOM kills performed by the kernel, this setting determines the state of the unit after
1651 \fBsystemd\-oomd\fR
1652 kills a cgroup associated with it\&.
1653 .sp
1654 Added in version 243\&.
1655 .RE
1656 .PP
1657 \fIOpenFile=\fR
1658 .RS 4
1659 Takes an argument of the form
1660 "path[\fI:fd\-name:options\fR]", where:
1661 .sp
1662 .RS 4
1663 .ie n \{\
1664 \h'-04'\(bu\h'+03'\c
1665 .\}
1666 .el \{\
1667 .sp -1
1668 .IP \(bu 2.3
1669 .\}
1670 "path"
1671 is a path to a file or an
1672 \fBAF_UNIX\fR
1673 socket in the file system;
1674 .RE
1675 .sp
1676 .RS 4
1677 .ie n \{\
1678 \h'-04'\(bu\h'+03'\c
1679 .\}
1680 .el \{\
1681 .sp -1
1682 .IP \(bu 2.3
1683 .\}
1684 "fd\-name"
1685 is a name that will be associated with the file descriptor; the name may contain any ASCII character, but must exclude control characters and ":", and must be at most 255 characters in length; it is optional and, if not provided, defaults to the file name;
1686 .RE
1687 .sp
1688 .RS 4
1689 .ie n \{\
1690 \h'-04'\(bu\h'+03'\c
1691 .\}
1692 .el \{\
1693 .sp -1
1694 .IP \(bu 2.3
1695 .\}
1696 "options"
1697 is a comma\-separated list of access options; possible values are
1698 "read\-only",
1699 "append",
1700 "truncate",
1701 "graceful"; if not specified, files will be opened in
1702 \fBrw\fR
1703 mode; if
1704 "graceful"
1705 is specified, errors during file/socket opening are ignored\&. Specifying the same option several times is treated as an error\&.
1706 .RE
1707 .sp
1708 The file or socket is opened by the service manager and the file descriptor is passed to the service\&. If the path is a socket, we call
1709 \fBconnect()\fR
1710 on it\&. See
1711 \fBsd_listen_fds\fR(3)
1712 for more details on how to retrieve these file descriptors\&.
1713 .sp
1714 This setting is useful to allow services to access files/sockets that they cannot access themselves (due to running in a separate mount namespace, not having privileges, \&.\&.\&.)\&.
1715 .sp
1716 This setting can be specified multiple times, in which case all the specified paths are opened and the file descriptors passed to the service\&. If the empty string is assigned, the entire list of open files defined prior to this is reset\&.
1717 .sp
1718 Added in version 253\&.
1719 .RE
1720 .PP
1721 \fIReloadSignal=\fR
1722 .RS 4
1723 Configures the UNIX process signal to send to the service\*(Aqs main process when asked to reload the service\*(Aqs configuration\&. Defaults to
1724 \fBSIGHUP\fR\&. This option has no effect unless
1725 \fIType=\fR\fBnotify\-reload\fR
1726 is used, see above\&.
1727 .sp
1728 Added in version 253\&.
1729 .RE
1730 .PP
1731 Check
1732 \fBsystemd.unit\fR(5),
1733 \fBsystemd.exec\fR(5), and
1734 \fBsystemd.kill\fR(5)
1735 for more settings\&.
1736 .SH "COMMAND LINES"
1737 .PP
1738 This section describes command line parsing and variable and specifier substitutions for
1739 \fIExecStart=\fR,
1740 \fIExecStartPre=\fR,
1741 \fIExecStartPost=\fR,
1742 \fIExecReload=\fR,
1743 \fIExecStop=\fR,
1744 \fIExecStopPost=\fR, and
1745 \fIExecCondition=\fR
1746 options\&.
1747 .PP
1748 Multiple command lines may be specified by using the relevant setting multiple times\&.
1749 .PP
1750 Each command line is unquoted using the rules described in "Quoting" section in
1751 \fBsystemd.syntax\fR(7)\&. The first item becomes the command to execute, and the subsequent items the arguments\&.
1752 .PP
1753 This syntax is inspired by shell syntax, but only the meta\-characters and expansions described in the following paragraphs are understood, and the expansion of variables is different\&. Specifically, redirection using
1754 "<",
1755 "<<",
1756 ">", and
1757 ">>", pipes using
1758 "|", running programs in the background using
1759 "&", and
1760 \fIother elements of shell syntax are not supported\fR\&.
1761 .PP
1762 The command to execute may contain spaces, but control characters are not allowed\&.
1763 .PP
1764 Each command may be prefixed with a number of special characters:
1765 .sp
1766 .it 1 an-trap
1767 .nr an-no-space-flag 1
1768 .nr an-break-flag 1
1769 .br
1770 .B Table\ \&2.\ \&Special executable prefixes
1771 .TS
1772 allbox tab(:);
1773 lB lB.
1774 T{
1775 Prefix
1776 T}:T{
1777 Effect
1778 T}
1779 .T&
1780 l l
1781 l l
1782 l l
1783 l l
1784 l l
1785 l l.
1786 T{
1787 "@"
1788 T}:T{
1789 If the executable path is prefixed with "@", the second specified token will be passed as \fBargv[0]\fR to the executed process (instead of the actual filename), followed by the further arguments specified\&.
1790 T}
1791 T{
1792 "\-"
1793 T}:T{
1794 If the executable path is prefixed with "\-", an exit code of the command normally considered a failure (i\&.e\&. non\-zero exit status or abnormal exit due to signal) is recorded, but has no further effect and is considered equivalent to success\&.
1795 T}
1796 T{
1797 ":"
1798 T}:T{
1799 If the executable path is prefixed with ":", environment variable substitution (as described below this table) is not applied\&.
1800 T}
1801 T{
1802 "+"
1803 T}:T{
1804 If the executable path is prefixed with "+" then the process is executed with full privileges\&. In this mode privilege restrictions configured with \fIUser=\fR, \fIGroup=\fR, \fICapabilityBoundingSet=\fR or the various file system namespacing options (such as \fIPrivateDevices=\fR, \fIPrivateTmp=\fR) are not applied to the invoked command line (but still affect any other \fIExecStart=\fR, \fIExecStop=\fR, \&... lines)\&. However, note that this will not bypass options that apply to the whole control group, such as \fIDevicePolicy=\fR, see \fBsystemd.resource-control\fR(5) for the full list\&.
1805 T}
1806 T{
1807 "!"
1808 T}:T{
1809 Similar to the "+" character discussed above this permits invoking command lines with elevated privileges\&. However, unlike "+" the "!" character exclusively alters the effect of \fIUser=\fR, \fIGroup=\fR and \fISupplementaryGroups=\fR, i\&.e\&. only the stanzas that affect user and group credentials\&. Note that this setting may be combined with \fIDynamicUser=\fR, in which case a dynamic user/group pair is allocated before the command is invoked, but credential changing is left to the executed process itself\&.
1810 T}
1811 T{
1812 "!!"
1813 T}:T{
1814 This prefix is very similar to "!", however it only has an effect on systems lacking support for ambient process capabilities, i\&.e\&. without support for \fIAmbientCapabilities=\fR\&. It\*(Aqs intended to be used for unit files that take benefit of ambient capabilities to run processes with minimal privileges wherever possible while remaining compatible with systems that lack ambient capabilities support\&. Note that when "!!" is used, and a system lacking ambient capability support is detected any configured \fISystemCallFilter=\fR and \fICapabilityBoundingSet=\fR stanzas are implicitly modified, in order to permit spawned processes to drop credentials and capabilities themselves, even if this is configured to not be allowed\&. Moreover, if this prefix is used and a system lacking ambient capability support is detected \fIAmbientCapabilities=\fR will be skipped and not be applied\&. On systems supporting ambient capabilities, "!!" has no effect and is redundant\&.
1815 T}
1816 .TE
1817 .sp 1
1818 .PP
1819 "@",
1820 "\-",
1821 ":", and one of
1822 "+"/"!"/"!!"
1823 may be used together and they can appear in any order\&. However, only one of
1824 "+",
1825 "!",
1826 "!!"
1827 may be used at a time\&.
1828 .PP
1829 For each command, the first argument must be either an absolute path to an executable or a simple file name without any slashes\&. If the command is not a full (absolute) path, it will be resolved to a full path using a fixed search path determined at compilation time\&. Searched directories include
1830 /usr/local/bin/,
1831 /usr/bin/, and their
1832 sbin/
1833 counterparts (only on systems using split
1834 bin/
1835 and
1836 sbin/)\&. It is thus safe to use just the executable name in case of executables located in any of the "standard" directories, and an absolute path must be used in other cases\&. Hint: this search path may be queried using
1837 \fBsystemd\-path search\-binaries\-default\fR\&.
1838 .PP
1839 The command line accepts
1840 "%"
1841 specifiers as described in
1842 \fBsystemd.unit\fR(5)\&.
1843 .PP
1844 An argument solely consisting of
1845 ";"
1846 must be escaped, i\&.e\&. specified as
1847 "\e;"\&.
1848 .PP
1849 Basic environment variable substitution is supported\&. Use
1850 "${FOO}"
1851 as part of a word, or as a word of its own, on the command line, in which case it will be erased and replaced by the exact value of the environment variable (if any) including all whitespace it contains, always resulting in exactly a single argument\&. Use
1852 "$FOO"
1853 as a separate word on the command line, in which case it will be replaced by the value of the environment variable split at whitespace, resulting in zero or more arguments\&. For this type of expansion, quotes are respected when splitting into words, and afterwards removed\&.
1854 .PP
1855 Example:
1856 .sp
1857 .if n \{\
1858 .RS 4
1859 .\}
1860 .nf
1861 Environment="ONE=one" \*(AqTWO=two two\*(Aq
1862 ExecStart=echo $ONE $TWO ${TWO}
1863 .fi
1864 .if n \{\
1865 .RE
1866 .\}
1867 .PP
1868 This will execute
1869 \fB/bin/echo\fR
1870 with four arguments:
1871 "one",
1872 "two",
1873 "two", and
1874 "two two"\&.
1875 .PP
1876 Example:
1877 .sp
1878 .if n \{\
1879 .RS 4
1880 .\}
1881 .nf
1882 Environment=ONE=\*(Aqone\*(Aq "TWO=\*(Aqtwo\ \&two\*(Aq\ \&too" THREE=
1883 ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
1884 ExecStart=/bin/echo $ONE $TWO $THREE
1885 .fi
1886 .if n \{\
1887 .RE
1888 .\}
1889 .PP
1890 This results in
1891 /bin/echo
1892 being called twice, the first time with arguments
1893 "\*(Aqone\*(Aq",
1894 "\*(Aqtwo\ \&two\*(Aq\ \&too",
1895 "", and the second time with arguments
1896 "one",
1897 "two\ \&two",
1898 "too"\&.
1899 .PP
1900 Unless for commands with the special executable prefix
1901 ":", to pass a literal dollar sign, use
1902 "$$"\&. Variables whose value is not known at expansion time are treated as empty strings\&. Note that the first argument (i\&.e\&. the program to execute) may not be a variable\&.
1903 .PP
1904 Variables to be used in this fashion may be defined through
1905 \fIEnvironment=\fR
1906 and
1907 \fIEnvironmentFile=\fR\&. In addition, variables listed in the section "Environment variables in spawned processes" in
1908 \fBsystemd.exec\fR(5), which are considered "static configuration", may be used (this includes e\&.g\&.
1909 \fI$USER\fR, but not
1910 \fI$TERM\fR)\&.
1911 .PP
1912 Note that shell command lines are not directly supported\&. If shell command lines are to be used, they need to be passed explicitly to a shell implementation of some kind\&. Example:
1913 .sp
1914 .if n \{\
1915 .RS 4
1916 .\}
1917 .nf
1918 ExecStart=sh \-c \*(Aqdmesg | tac\*(Aq
1919 .fi
1920 .if n \{\
1921 .RE
1922 .\}
1923 .PP
1924 Example:
1925 .sp
1926 .if n \{\
1927 .RS 4
1928 .\}
1929 .nf
1930 ExecStart=echo one
1931 ExecStart=echo "two two"
1932 .fi
1933 .if n \{\
1934 .RE
1935 .\}
1936 .PP
1937 This will execute
1938 \fBecho\fR
1939 two times, each time with one argument:
1940 "one"
1941 and
1942 "two two", respectively\&. Because two commands are specified,
1943 \fIType=oneshot\fR
1944 must be used\&.
1945 .PP
1946 Example:
1947 .sp
1948 .if n \{\
1949 .RS 4
1950 .\}
1951 .nf
1952 Type=oneshot
1953 ExecStart=:echo $USER
1954 ExecStart=\-false
1955 ExecStart=+:@true $TEST
1956 .fi
1957 .if n \{\
1958 .RE
1959 .\}
1960 .PP
1961 This will execute
1962 \fB/usr/bin/echo\fR
1963 with the literal argument
1964 "$USER"
1965 (":"
1966 suppresses variable expansion), and then
1967 \fB/usr/bin/false\fR
1968 (the return value will be ignored because
1969 "\-"
1970 suppresses checking of the return value), and
1971 \fB/usr/bin/true\fR
1972 (with elevated privileges, with
1973 "$TEST"
1974 as
1975 \fBargv[0]\fR)\&.
1976 .PP
1977 Example:
1978 .sp
1979 .if n \{\
1980 .RS 4
1981 .\}
1982 .nf
1983 ExecStart=echo / >/dev/null & \e; \e
1984 ls
1985 .fi
1986 .if n \{\
1987 .RE
1988 .\}
1989 .PP
1990 This will execute
1991 \fBecho\fR
1992 with five arguments:
1993 "/",
1994 ">/dev/null",
1995 "&",
1996 ";", and
1997 "ls"\&.
1998 .SH "EXAMPLES"
1999 .PP
2000 \fBExample\ \&3.\ \&Simple service\fR
2001 .PP
2002 The following unit file creates a service that will execute
2003 /usr/sbin/foo\-daemon\&. Since no
2004 \fIType=\fR
2005 is specified, the default
2006 \fIType=\fR\fBsimple\fR
2007 will be assumed\&. systemd will assume the unit to be started immediately after the program has begun executing\&.
2008 .sp
2009 .if n \{\
2010 .RS 4
2011 .\}
2012 .nf
2013 [Unit]
2014 Description=Foo
2015
2016 [Service]
2017 ExecStart=/usr/sbin/foo\-daemon
2018
2019 [Install]
2020 WantedBy=multi\-user\&.target
2021 .fi
2022 .if n \{\
2023 .RE
2024 .\}
2025 .PP
2026 Note that systemd assumes here that the process started by systemd will continue running until the service terminates\&. If the program daemonizes itself (i\&.e\&. forks), please use
2027 \fIType=\fR\fBforking\fR
2028 instead\&.
2029 .PP
2030 Since no
2031 \fIExecStop=\fR
2032 was specified, systemd will send SIGTERM to all processes started from this service, and after a timeout also SIGKILL\&. This behavior can be modified, see
2033 \fBsystemd.kill\fR(5)
2034 for details\&.
2035 .PP
2036 Note that this unit type does not include any type of notification when a service has completed initialization\&. For this, you should use other unit types, such as
2037 \fIType=\fR\fBnotify\fR/\fIType=\fR\fBnotify\-reload\fR
2038 if the service understands systemd\*(Aqs notification protocol,
2039 \fIType=\fR\fBforking\fR
2040 if the service can background itself or
2041 \fIType=\fR\fBdbus\fR
2042 if the unit acquires a DBus name once initialization is complete\&. See below\&.
2043 .PP
2044 \fBExample\ \&4.\ \&Oneshot service\fR
2045 .PP
2046 Sometimes, units should just execute an action without keeping active processes, such as a filesystem check or a cleanup action on boot\&. For this,
2047 \fIType=\fR\fBoneshot\fR
2048 exists\&. Units of this type will wait until the process specified terminates and then fall back to being inactive\&. The following unit will perform a cleanup action:
2049 .sp
2050 .if n \{\
2051 .RS 4
2052 .\}
2053 .nf
2054 [Unit]
2055 Description=Cleanup old Foo data
2056
2057 [Service]
2058 Type=oneshot
2059 ExecStart=/usr/sbin/foo\-cleanup
2060
2061 [Install]
2062 WantedBy=multi\-user\&.target
2063 .fi
2064 .if n \{\
2065 .RE
2066 .\}
2067 .PP
2068 Note that systemd will consider the unit to be in the state "starting" until the program has terminated, so ordered dependencies will wait for the program to finish before starting themselves\&. The unit will revert to the "inactive" state after the execution is done, never reaching the "active" state\&. That means another request to start the unit will perform the action again\&.
2069 .PP
2070 \fIType=\fR\fBoneshot\fR
2071 are the only service units that may have more than one
2072 \fIExecStart=\fR
2073 specified\&. For units with multiple commands (\fIType=oneshot\fR), all commands will be run again\&.
2074 .PP
2075 For
2076 \fIType=oneshot\fR,
2077 \fIRestart=\fR\fBalways\fR
2078 and
2079 \fIRestart=\fR\fBon\-success\fR
2080 are
2081 \fInot\fR
2082 allowed\&.
2083 .PP
2084 \fBExample\ \&5.\ \&Stoppable oneshot service\fR
2085 .PP
2086 Similarly to the oneshot services, there are sometimes units that need to execute a program to set up something and then execute another to shut it down, but no process remains active while they are considered "started"\&. Network configuration can sometimes fall into this category\&. Another use case is if a oneshot service shall not be executed each time when they are pulled in as a dependency, but only the first time\&.
2087 .PP
2088 For this, systemd knows the setting
2089 \fIRemainAfterExit=\fR\fByes\fR, which causes systemd to consider the unit to be active if the start action exited successfully\&. This directive can be used with all types, but is most useful with
2090 \fIType=\fR\fBoneshot\fR
2091 and
2092 \fIType=\fR\fBsimple\fR\&. With
2093 \fIType=\fR\fBoneshot\fR, systemd waits until the start action has completed before it considers the unit to be active, so dependencies start only after the start action has succeeded\&. With
2094 \fIType=\fR\fBsimple\fR, dependencies will start immediately after the start action has been dispatched\&. The following unit provides an example for a simple static firewall\&.
2095 .sp
2096 .if n \{\
2097 .RS 4
2098 .\}
2099 .nf
2100 [Unit]
2101 Description=Simple firewall
2102
2103 [Service]
2104 Type=oneshot
2105 RemainAfterExit=yes
2106 ExecStart=/usr/local/sbin/simple\-firewall\-start
2107 ExecStop=/usr/local/sbin/simple\-firewall\-stop
2108
2109 [Install]
2110 WantedBy=multi\-user\&.target
2111 .fi
2112 .if n \{\
2113 .RE
2114 .\}
2115 .PP
2116 Since the unit is considered to be running after the start action has exited, invoking
2117 \fBsystemctl start\fR
2118 on that unit again will cause no action to be taken\&.
2119 .PP
2120 \fBExample\ \&6.\ \&Traditional forking services\fR
2121 .PP
2122 Many traditional daemons/services background (i\&.e\&. fork, daemonize) themselves when starting\&. Set
2123 \fIType=\fR\fBforking\fR
2124 in the service\*(Aqs unit file to support this mode of operation\&. systemd will consider the service to be in the process of initialization while the original program is still running\&. Once it exits successfully and at least a process remains (and
2125 \fIRemainAfterExit=\fR\fBno\fR), the service is considered started\&.
2126 .PP
2127 Often, a traditional daemon only consists of one process\&. Therefore, if only one process is left after the original process terminates, systemd will consider that process the main process of the service\&. In that case, the
2128 \fI$MAINPID\fR
2129 variable will be available in
2130 \fIExecReload=\fR,
2131 \fIExecStop=\fR, etc\&.
2132 .PP
2133 In case more than one process remains, systemd will be unable to determine the main process, so it will not assume there is one\&. In that case,
2134 \fI$MAINPID\fR
2135 will not expand to anything\&. However, if the process decides to write a traditional PID file, systemd will be able to read the main PID from there\&. Please set
2136 \fIPIDFile=\fR
2137 accordingly\&. Note that the daemon should write that file before finishing with its initialization\&. Otherwise, systemd might try to read the file before it exists\&.
2138 .PP
2139 The following example shows a simple daemon that forks and just starts one process in the background:
2140 .sp
2141 .if n \{\
2142 .RS 4
2143 .\}
2144 .nf
2145 [Unit]
2146 Description=My Simple Daemon
2147
2148 [Service]
2149 Type=forking
2150 ExecStart=/usr/sbin/my\-simple\-daemon \-d
2151
2152 [Install]
2153 WantedBy=multi\-user\&.target
2154 .fi
2155 .if n \{\
2156 .RE
2157 .\}
2158 .PP
2159 Please see
2160 \fBsystemd.kill\fR(5)
2161 for details on how you can influence the way systemd terminates the service\&.
2162 .PP
2163 \fBExample\ \&7.\ \&DBus services\fR
2164 .PP
2165 For services that acquire a name on the DBus system bus, use
2166 \fIType=\fR\fBdbus\fR
2167 and set
2168 \fIBusName=\fR
2169 accordingly\&. The service should not fork (daemonize)\&. systemd will consider the service to be initialized once the name has been acquired on the system bus\&. The following example shows a typical DBus service:
2170 .sp
2171 .if n \{\
2172 .RS 4
2173 .\}
2174 .nf
2175 [Unit]
2176 Description=Simple DBus Service
2177
2178 [Service]
2179 Type=dbus
2180 BusName=org\&.example\&.simple\-dbus\-service
2181 ExecStart=/usr/sbin/simple\-dbus\-service
2182
2183 [Install]
2184 WantedBy=multi\-user\&.target
2185 .fi
2186 .if n \{\
2187 .RE
2188 .\}
2189 .PP
2190 For
2191 \fIbus\-activatable\fR
2192 services, do not include a [Install] section in the systemd service file, but use the
2193 \fISystemdService=\fR
2194 option in the corresponding DBus service file, for example (/usr/share/dbus\-1/system\-services/org\&.example\&.simple\-dbus\-service\&.service):
2195 .sp
2196 .if n \{\
2197 .RS 4
2198 .\}
2199 .nf
2200 [D\-BUS Service]
2201 Name=org\&.example\&.simple\-dbus\-service
2202 Exec=/usr/sbin/simple\-dbus\-service
2203 User=root
2204 SystemdService=simple\-dbus\-service\&.service
2205 .fi
2206 .if n \{\
2207 .RE
2208 .\}
2209 .PP
2210 Please see
2211 \fBsystemd.kill\fR(5)
2212 for details on how you can influence the way systemd terminates the service\&.
2213 .PP
2214 \fBExample\ \&8.\ \&Services that notify systemd about their initialization\fR
2215 .PP
2216 \fIType=\fR\fBsimple\fR
2217 services are really easy to write, but have the major disadvantage of systemd not being able to tell when initialization of the given service is complete\&. For this reason, systemd supports a simple notification protocol that allows daemons to make systemd aware that they are done initializing\&. Use
2218 \fIType=\fR\fBnotify\fR
2219 or
2220 \fIType=\fR\fBnotify\-reload\fR
2221 for this\&. A typical service file for such a daemon would look like this:
2222 .sp
2223 .if n \{\
2224 .RS 4
2225 .\}
2226 .nf
2227 [Unit]
2228 Description=Simple Notifying Service
2229
2230 [Service]
2231 Type=notify\-reload
2232 ExecStart=/usr/sbin/simple\-notifying\-service
2233
2234 [Install]
2235 WantedBy=multi\-user\&.target
2236 .fi
2237 .if n \{\
2238 .RE
2239 .\}
2240 .PP
2241 Note that the daemon has to support systemd\*(Aqs notification protocol, else systemd will think the service has not started yet and kill it after a timeout\&. For an example of how to update daemons to support this protocol transparently, take a look at
2242 \fBsd_notify\fR(3)\&. systemd will consider the unit to be in the \*(Aqstarting\*(Aq state until a readiness notification has arrived\&.
2243 .PP
2244 Please see
2245 \fBsystemd.kill\fR(5)
2246 for details on how you can influence the way systemd terminates the service\&.
2247 .PP
2248 To avoid code duplication, it is preferable to use
2249 \fBsd_notify\fR(3)
2250 when possible, especially when other APIs provided by
2251 \fBlibsystemd\fR(3)
2252 are also used, but note that the notification protocol is very simple and guaranteed to be stable as per the
2253 \m[blue]\fBInterface Portability and Stability Promise\fR\m[]\&\s-2\u[4]\d\s+2, so it can be reimplemented by services with no external dependencies\&. For a self\-contained example, see
2254 \fBsd_notify\fR(3)\&.
2255 .SH "SEE ALSO"
2256 .PP
2257 \fBsystemd\fR(1), \fBsystemctl\fR(1), \fBsystemd-system.conf\fR(5), \fBsystemd.unit\fR(5), \fBsystemd.exec\fR(5), \fBsystemd.resource-control\fR(5), \fBsystemd.kill\fR(5), \fBsystemd.directives\fR(7), \fBsystemd-run\fR(1)
2258 .SH "NOTES"
2259 .IP " 1." 4
2260 File Descriptor Store
2261 .RS 4
2262 \%https://systemd.io/FILE_DESCRIPTOR_STORE
2263 .RE
2264 .IP " 2." 4
2265 USB FunctionFS
2266 .RS 4
2267 \%https://docs.kernel.org/usb/functionfs.html
2268 .RE
2269 .IP " 3." 4
2270 Control Group v2
2271 .RS 4
2272 \%https://docs.kernel.org/admin-guide/cgroup-v2.html
2273 .RE
2274 .IP " 4." 4
2275 Interface Portability and Stability Promise
2276 .RS 4
2277 \%https://systemd.io/PORTABILITY_AND_STABILITY/
2278 .RE