Debian Codegraph @

upstream/mageia-cauldron/man5/systemd.service.5

raw
1 '\" t
2 .TH "SYSTEMD\&.SERVICE" "5" "" "systemd 258.7" "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 of whether 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 l l l l l l l l.
1168 T{
1169 Clean exit code or signal
1170 T}:T{
1171 \ \&
1172 T}:T{
1173 X
1174 T}:T{
1175 X
1176 T}:T{
1177 \ \&
1178 T}:T{
1179 \ \&
1180 T}:T{
1181 \ \&
1182 T}:T{
1183 \ \&
1184 T}
1185 T{
1186 Unclean exit code
1187 T}:T{
1188 \ \&
1189 T}:T{
1190 X
1191 T}:T{
1192 \ \&
1193 T}:T{
1194 X
1195 T}:T{
1196 \ \&
1197 T}:T{
1198 \ \&
1199 T}:T{
1200 \ \&
1201 T}
1202 T{
1203 Unclean signal
1204 T}:T{
1205 \ \&
1206 T}:T{
1207 X
1208 T}:T{
1209 \ \&
1210 T}:T{
1211 X
1212 T}:T{
1213 X
1214 T}:T{
1215 X
1216 T}:T{
1217 \ \&
1218 T}
1219 T{
1220 Timeout
1221 T}:T{
1222 \ \&
1223 T}:T{
1224 X
1225 T}:T{
1226 \ \&
1227 T}:T{
1228 X
1229 T}:T{
1230 X
1231 T}:T{
1232 \ \&
1233 T}:T{
1234 \ \&
1235 T}
1236 T{
1237 Watchdog
1238 T}:T{
1239 \ \&
1240 T}:T{
1241 X
1242 T}:T{
1243 \ \&
1244 T}:T{
1245 X
1246 T}:T{
1247 X
1248 T}:T{
1249 \ \&
1250 T}:T{
1251 X
1252 T}
1253 T{
1254 Termination due to OOM
1255 T}:T{
1256 \ \&
1257 T}:T{
1258 X
1259 T}:T{
1260 \ \&
1261 T}:T{
1262 X
1263 T}:T{
1264 X
1265 T}:T{
1266 \ \&
1267 T}:T{
1268 \ \&
1269 T}
1270 .TE
1271 .sp 1
1272 As exceptions to the setting above, the service will not be restarted if the exit code or signal is specified in
1273 \fIRestartPreventExitStatus=\fR
1274 (see below) or the service is stopped with
1275 \fBsystemctl stop\fR
1276 or an equivalent operation\&. Also, the services will always be restarted if the exit code or signal is specified in
1277 \fIRestartForceExitStatus=\fR
1278 (see below)\&.
1279 .sp
1280 Note that service restart is subject to unit start rate limiting configured with
1281 \fIStartLimitIntervalSec=\fR
1282 and
1283 \fIStartLimitBurst=\fR, see
1284 \fBsystemd.unit\fR(5)
1285 for details\&.
1286 .sp
1287 Setting this to
1288 \fBon\-failure\fR
1289 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),
1290 \fBon\-abnormal\fR
1291 is an alternative choice\&.
1292 .RE
1293 .PP
1294 \fIRestartMode=\fR
1295 .RS 4
1296 Takes a string value that specifies how a service should restart:
1297 .sp
1298 .RS 4
1299 .ie n \{\
1300 \h'-04'\(bu\h'+03'\c
1301 .\}
1302 .el \{\
1303 .sp -1
1304 .IP \(bu 2.3
1305 .\}
1306 If set to
1307 \fBnormal\fR
1308 (the default), the service restarts by going through a failed/inactive state\&.
1309 .sp
1310 Added in version 254\&.
1311 .RE
1312 .sp
1313 .RS 4
1314 .ie n \{\
1315 \h'-04'\(bu\h'+03'\c
1316 .\}
1317 .el \{\
1318 .sp -1
1319 .IP \(bu 2.3
1320 .\}
1321 If set to
1322 \fBdirect\fR, the service transitions to the activating state directly during auto\-restart, skipping failed/inactive state\&.
1323 \fIExecStopPost=\fR
1324 is still invoked\&.
1325 \fIOnSuccess=\fR
1326 and
1327 \fIOnFailure=\fR
1328 are skipped\&.
1329 .sp
1330 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\&.
1331 .sp
1332 Added in version 254\&.
1333 .RE
1334 .sp
1335 .RS 4
1336 .ie n \{\
1337 \h'-04'\(bu\h'+03'\c
1338 .\}
1339 .el \{\
1340 .sp -1
1341 .IP \(bu 2.3
1342 .\}
1343 If set to
1344 \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
1345 \fI$DEBUG_INVOCATION=1\fR
1346 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
1347 \fBnormal\fR
1348 mode\&.
1349 .sp
1350 Added in version 257\&.
1351 .RE
1352 .sp
1353 Added in version 254\&.
1354 .RE
1355 .PP
1356 \fISuccessExitStatus=\fR
1357 .RS 4
1358 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
1359 \fIType=oneshot\fR, the signals
1360 \fBSIGHUP\fR,
1361 \fBSIGINT\fR,
1362 \fBSIGTERM\fR, and
1363 \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
1364 \fBsystemd.exec\fR(5)
1365 for a list of termination status names (for this setting only the part without the
1366 "EXIT_"
1367 or
1368 "EX_"
1369 prefix should be used)\&. See
1370 \fBsignal\fR(7)
1371 for a list of signal names\&.
1372 .sp
1373 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
1374 "SUCCESS"
1375 (and thus typically shown as
1376 "0/SUCCESS"
1377 in tool outputs) and 1 to
1378 "FAILURE"
1379 (and thus typically shown as
1380 "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\&.
1381 .sp
1382 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\&.
1383 .PP
1384 \fBExample\ \&1.\ \&A service with the \fISuccessExitStatus=\fR setting\fR
1385 .sp
1386 .if n \{\
1387 .RS 4
1388 .\}
1389 .nf
1390 SuccessExitStatus=TEMPFAIL 250 SIGKILL
1391 .fi
1392 .if n \{\
1393 .RE
1394 .\}
1395 .sp
1396 Exit status 75 (\fBTEMPFAIL\fR), 250, and the termination signal
1397 \fBSIGKILL\fR
1398 are considered clean service terminations\&.
1399
1400 Note:
1401 \fBsystemd\-analyze exit\-status\fR
1402 may be used to list exit statuses and translate between numerical status values and names\&.
1403 .sp
1404 Added in version 189\&.
1405 .RE
1406 .PP
1407 \fIRestartPreventExitStatus=\fR
1408 .RS 4
1409 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
1410 \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\&.
1411 .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\&.
1412 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\&.
1413 .sp
1414 Note that this setting has no effect on processes configured via
1415 \fIExecStartPre=\fR,
1416 \fIExecStartPost=\fR,
1417 \fIExecStop=\fR,
1418 \fIExecStopPost=\fR
1419 or
1420 \fIExecReload=\fR, but only on the main service process, i\&.e\&. either the one invoked by
1421 \fIExecStart=\fR
1422 or (depending on
1423 \fIType=\fR,
1424 \fIPIDFile=\fR, \&...) the otherwise configured main process\&.
1425 .sp
1426 Added in version 189\&.
1427 .RE
1428 .PP
1429 \fIRestartForceExitStatus=\fR
1430 .RS 4
1431 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
1432 \fIRestart=\fR\&. The argument format is similar to
1433 \fIRestartPreventExitStatus=\fR\&.
1434 .sp
1435 Note that for
1436 \fIType=oneshot\fR
1437 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\&.
1438 .sp
1439 Added in version 215\&.
1440 .RE
1441 .PP
1442 \fIRootDirectoryStartOnly=\fR
1443 .RS 4
1444 Takes a boolean argument\&. If true, the root directory, as configured with the
1445 \fIRootDirectory=\fR
1446 option (see
1447 \fBsystemd.exec\fR(5)
1448 for more information), is only applied to the process started with
1449 \fIExecStart=\fR, and not to the various other
1450 \fIExecStartPre=\fR,
1451 \fIExecStartPost=\fR,
1452 \fIExecReload=\fR,
1453 \fIExecStop=\fR, and
1454 \fIExecStopPost=\fR
1455 commands\&. If false, the setting is applied to all configured commands the same way\&. Defaults to false\&.
1456 .RE
1457 .PP
1458 \fINonBlocking=\fR
1459 .RS 4
1460 Set the
1461 \fBO_NONBLOCK\fR
1462 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
1463 \fIFileDescriptorStoreMax=\fR
1464 for details), will have the
1465 \fBO_NONBLOCK\fR
1466 flag set and hence are in non\-blocking mode\&. This option is only useful in conjunction with a socket unit, as described in
1467 \fBsystemd.socket\fR(5)
1468 and has no effect on file descriptors which were previously saved in the file\-descriptor store for example\&. Defaults to false\&.
1469 .sp
1470 Note that if the same socket unit is configured to be passed to multiple service units (via the
1471 \fISockets=\fR
1472 setting, see below), and these services have different
1473 \fINonBlocking=\fR
1474 configurations, the precise state of
1475 \fBO_NONBLOCK\fR
1476 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
1477 \fBO_NONBLOCK\fR
1478 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
1479 \fINonBlocking=\fR
1480 configuration, and do not change the flag in service code either\&.
1481 .RE
1482 .PP
1483 \fINotifyAccess=\fR
1484 .RS 4
1485 Controls access to the service status notification socket, as accessible via the
1486 \fBsd_notify\fR(3)
1487 call\&. Takes one of
1488 \fBnone\fR
1489 (the default),
1490 \fBmain\fR,
1491 \fBexec\fR
1492 or
1493 \fBall\fR\&. If
1494 \fBnone\fR, no daemon status updates are accepted from the service processes, all status update messages are ignored\&. If
1495 \fBmain\fR, only service updates sent from the main process of the service are accepted\&. If
1496 \fBexec\fR, only service updates sent from any of the main or control processes originating from one of the
1497 \fIExec*=\fR
1498 commands are accepted\&. If
1499 \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
1500 \fIType=notify\fR/\fIType=notify\-reload\fR
1501 or
1502 \fIWatchdogSec=\fR
1503 (see above)\&. If those options are used but
1504 \fINotifyAccess=\fR
1505 is not configured, it will be implicitly set to
1506 \fBmain\fR\&.
1507 .sp
1508 Note that
1509 \fBsd_notify()\fR
1510 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
1511 \fBmain\fR
1512 or
1513 \fBexec\fR\&. Conversely, if an auxiliary process of the unit sends an
1514 \fBsd_notify()\fR
1515 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
1516 \fINotifyAccess=\fR\fBall\fR
1517 is set for it\&.
1518 .sp
1519 Hence, to eliminate all race conditions involving lookup of the client\*(Aqs unit and attribution of notifications to units correctly,
1520 \fBsd_notify_barrier()\fR
1521 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
1522 \fBsd_notify_barrier()\fR
1523 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\&.
1524 .RE
1525 .PP
1526 \fISockets=\fR
1527 .RS 4
1528 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\&.
1529 .sp
1530 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
1531 \fIService=\fR
1532 setting of
1533 \&.socket
1534 units does not have to match the inverse of the
1535 \fISockets=\fR
1536 setting of the
1537 \&.service
1538 it refers to\&.
1539 .sp
1540 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\&.
1541 .RE
1542 .PP
1543 \fIFileDescriptorStoreMax=\fR
1544 .RS 4
1545 Configure how many file descriptors may be stored in the service manager for the service using
1546 \fBsd_pid_notify_with_fds\fR(3)\*(Aqs
1547 "FDSTORE=1"
1548 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
1549 \fIRuntimeDirectory=\fR, or stored in a
1550 \fBmemfd_create\fR(2)
1551 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
1552 \fBsd_listen_fds\fR(3)
1553 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
1554 \fBPOLLHUP\fR
1555 or
1556 \fBPOLLERR\fR
1557 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
1558 \fIFileDescriptorStorePreserve=\fR, see below)\&. If this option is used,
1559 \fINotifyAccess=\fR
1560 (see above) should be set to open access to the notification socket provided by systemd\&. If
1561 \fINotifyAccess=\fR
1562 is not set, it will be implicitly set to
1563 \fBmain\fR\&.
1564 .sp
1565 The
1566 \fBfdstore\fR
1567 command of
1568 \fBsystemd-analyze\fR(1)
1569 may be used to list the current contents of a service\*(Aqs file descriptor store\&.
1570 .sp
1571 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\&.
1572 .sp
1573 If this option is set to a non\-zero value the
1574 \fI$FDSTORE\fR
1575 environment variable will be set for processes invoked for this service\&. See
1576 \fBsystemd.exec\fR(5)
1577 for details\&.
1578 .sp
1579 For further information on the file descriptor store see the
1580 \m[blue]\fBFile Descriptor Store\fR\m[]\&\s-2\u[1]\d\s+2
1581 overview\&.
1582 .sp
1583 Added in version 219\&.
1584 .RE
1585 .PP
1586 \fIFileDescriptorStorePreserve=\fR
1587 .RS 4
1588 Takes one of
1589 \fBno\fR,
1590 \fByes\fR,
1591 \fBrestart\fR
1592 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
1593 \fBno\fR
1594 the file descriptor store is automatically released when the service is stopped; if
1595 \fBrestart\fR
1596 (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
1597 \fByes\fR
1598 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\&.
1599 .sp
1600 Use
1601 \fBsystemctl clean \-\-what=fdstore \&...\fR
1602 to release the file descriptor store explicitly\&.
1603 .sp
1604 Added in version 254\&.
1605 .RE
1606 .PP
1607 \fIUSBFunctionDescriptors=\fR
1608 .RS 4
1609 Configure the location of a file containing
1610 \m[blue]\fBUSB FunctionFS\fR\m[]\&\s-2\u[2]\d\s+2
1611 descriptors, for implementation of USB gadget functions\&. This is used only in conjunction with a socket unit with
1612 \fIListenUSBFunction=\fR
1613 configured\&. The contents of this file are written to the
1614 ep0
1615 file after it is opened\&.
1616 .sp
1617 Added in version 227\&.
1618 .RE
1619 .PP
1620 \fIUSBFunctionStrings=\fR
1621 .RS 4
1622 Configure the location of a file containing USB FunctionFS strings\&. Behavior is similar to
1623 \fIUSBFunctionDescriptors=\fR
1624 above\&.
1625 .sp
1626 Added in version 227\&.
1627 .RE
1628 .PP
1629 \fIOOMPolicy=\fR
1630 .RS 4
1631 Configure the out\-of\-memory (OOM) killing policy for the kernel and the userspace OOM killer
1632 \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
1633 systemd\-oomd\&.service
1634 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\&.
1635 .sp
1636 This setting takes one of
1637 \fBcontinue\fR,
1638 \fBstop\fR
1639 or
1640 \fBkill\fR\&. If set to
1641 \fBcontinue\fR
1642 and a process in the unit is killed by the OOM killer, this is logged but the unit continues running\&. If set to
1643 \fBstop\fR
1644 the event is logged but the unit is terminated cleanly by the service manager\&. If set to
1645 \fBkill\fR
1646 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
1647 memory\&.oom\&.group
1648 attribute to
1649 \fB1\fR; also see kernel page
1650 \m[blue]\fBControl Group v2\fR\m[]\&\s-2\u[3]\d\s+2\&.
1651 .sp
1652 Defaults to the setting
1653 \fIDefaultOOMPolicy=\fR
1654 in
1655 \fBsystemd-system.conf\fR(5)
1656 is set to, except for units where
1657 \fIDelegate=\fR
1658 is turned on, where it defaults to
1659 \fBcontinue\fR\&.
1660 .sp
1661 Use the
1662 \fIOOMScoreAdjust=\fR
1663 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
1664 \fBsystemd.exec\fR(5)
1665 for details\&.
1666 .sp
1667 This setting also applies to
1668 \fBsystemd-oomd.service\fR(8)\&. Similarly to the kernel OOM kills performed by the kernel, this setting determines the state of the unit after
1669 \fBsystemd\-oomd\fR
1670 kills a cgroup associated with it\&.
1671 .sp
1672 Added in version 243\&.
1673 .RE
1674 .PP
1675 \fIOpenFile=\fR
1676 .RS 4
1677 Takes an argument of the form
1678 "path[\fI:fd\-name:options\fR]", where:
1679 .sp
1680 .RS 4
1681 .ie n \{\
1682 \h'-04'\(bu\h'+03'\c
1683 .\}
1684 .el \{\
1685 .sp -1
1686 .IP \(bu 2.3
1687 .\}
1688 "path"
1689 is a path to a file or an
1690 \fBAF_UNIX\fR
1691 socket in the file system;
1692 .RE
1693 .sp
1694 .RS 4
1695 .ie n \{\
1696 \h'-04'\(bu\h'+03'\c
1697 .\}
1698 .el \{\
1699 .sp -1
1700 .IP \(bu 2.3
1701 .\}
1702 "fd\-name"
1703 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;
1704 .RE
1705 .sp
1706 .RS 4
1707 .ie n \{\
1708 \h'-04'\(bu\h'+03'\c
1709 .\}
1710 .el \{\
1711 .sp -1
1712 .IP \(bu 2.3
1713 .\}
1714 "options"
1715 is a comma\-separated list of access options; possible values are
1716 "read\-only",
1717 "append",
1718 "truncate",
1719 "graceful"; if not specified, files will be opened in
1720 \fBrw\fR
1721 mode; if
1722 "graceful"
1723 is specified, errors during file/socket opening are ignored\&. Specifying the same option several times is treated as an error\&.
1724 .RE
1725 .sp
1726 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
1727 \fBconnect()\fR
1728 on it\&. See
1729 \fBsd_listen_fds\fR(3)
1730 for more details on how to retrieve these file descriptors\&.
1731 .sp
1732 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, \&.\&.\&.)\&.
1733 .sp
1734 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\&.
1735 .sp
1736 Added in version 253\&.
1737 .RE
1738 .PP
1739 \fIReloadSignal=\fR
1740 .RS 4
1741 Configures the UNIX process signal to send to the service\*(Aqs main process when asked to reload the service\*(Aqs configuration\&. Defaults to
1742 \fBSIGHUP\fR\&. This option has no effect unless
1743 \fIType=\fR\fBnotify\-reload\fR
1744 is used, see above\&.
1745 .sp
1746 Added in version 253\&.
1747 .RE
1748 .PP
1749 Check
1750 \fBsystemd.unit\fR(5),
1751 \fBsystemd.exec\fR(5), and
1752 \fBsystemd.kill\fR(5)
1753 for more settings\&.
1754 .SH "COMMAND LINES"
1755 .PP
1756 This section describes command line parsing and variable and specifier substitutions for
1757 \fIExecStart=\fR,
1758 \fIExecStartPre=\fR,
1759 \fIExecStartPost=\fR,
1760 \fIExecReload=\fR,
1761 \fIExecStop=\fR,
1762 \fIExecStopPost=\fR, and
1763 \fIExecCondition=\fR
1764 options\&.
1765 .PP
1766 Multiple command lines may be specified by using the relevant setting multiple times\&.
1767 .PP
1768 Each command line is unquoted using the rules described in "Quoting" section in
1769 \fBsystemd.syntax\fR(7)\&. The first item becomes the command to execute, and the subsequent items the arguments\&.
1770 .PP
1771 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
1772 "<",
1773 "<<",
1774 ">", and
1775 ">>", pipes using
1776 "|", running programs in the background using
1777 "&", and
1778 \fIother elements of shell syntax are not supported\fR\&.
1779 .PP
1780 The command to execute may contain spaces, but control characters are not allowed\&.
1781 .PP
1782 Each command may be prefixed with a number of special characters:
1783 .sp
1784 .it 1 an-trap
1785 .nr an-no-space-flag 1
1786 .nr an-break-flag 1
1787 .br
1788 .B Table\ \&2.\ \&Special executable prefixes
1789 .TS
1790 allbox tab(:);
1791 lB lB.
1792 T{
1793 Prefix
1794 T}:T{
1795 Effect
1796 T}
1797 .T&
1798 l l
1799 l l
1800 l l
1801 l l
1802 l l
1803 l l.
1804 T{
1805 "@"
1806 T}:T{
1807 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, unless "|" is also specified, in which case it enables login shell semantics for the shell spawned by prefixing "\-" to \fBargv[0]\fR\&.
1808 T}
1809 T{
1810 "\-"
1811 T}:T{
1812 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\&.
1813 T}
1814 T{
1815 ":"
1816 T}:T{
1817 If the executable path is prefixed with ":", environment variable substitution (as described below this table) is not applied\&.
1818 T}
1819 T{
1820 "+"
1821 T}:T{
1822 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\&.
1823 T}
1824 T{
1825 "!"
1826 T}:T{
1827 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\&.
1828 T}
1829 T{
1830 "|"
1831 T}:T{
1832 If "|" is specified standalone as executable path, invoke the default shell of \fIUser=\fR\&. If specified as a prefix, use the shell ("\-c") to spawn the executable\&. When "@" is used in conjunction, \fBargv[0]\fR of shell will be prefixed with "\-" to enable login shell semantics\&.
1833 T}
1834 .TE
1835 .sp 1
1836 .PP
1837 "@",
1838 "|",
1839 "\-",
1840 ":", and one of
1841 "+"/"!"
1842 may be used together and they can appear in any order\&. However,
1843 "+"
1844 and
1845 "!"
1846 may not be specified at the same time\&.
1847 .PP
1848 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
1849 /usr/local/bin/,
1850 /usr/bin/, and their
1851 sbin/
1852 counterparts (only on systems using split
1853 bin/
1854 and
1855 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
1856 \fBsystemd\-path search\-binaries\-default\fR\&.
1857 .PP
1858 The command line accepts
1859 "%"
1860 specifiers as described in
1861 \fBsystemd.unit\fR(5)\&.
1862 .PP
1863 An argument solely consisting of
1864 ";"
1865 must be escaped, i\&.e\&. specified as
1866 "\e;"\&.
1867 .PP
1868 Basic environment variable substitution is supported\&. Use
1869 "${FOO}"
1870 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
1871 "$FOO"
1872 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\&.
1873 .PP
1874 Example:
1875 .sp
1876 .if n \{\
1877 .RS 4
1878 .\}
1879 .nf
1880 Environment="ONE=one" \*(AqTWO=two two\*(Aq
1881 ExecStart=echo $ONE $TWO ${TWO}
1882 .fi
1883 .if n \{\
1884 .RE
1885 .\}
1886 .PP
1887 This will execute
1888 \fB/bin/echo\fR
1889 with four arguments:
1890 "one",
1891 "two",
1892 "two", and
1893 "two two"\&.
1894 .PP
1895 Example:
1896 .sp
1897 .if n \{\
1898 .RS 4
1899 .\}
1900 .nf
1901 Environment=ONE=\*(Aqone\*(Aq "TWO=\*(Aqtwo\ \&two\*(Aq\ \&too" THREE=
1902 ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
1903 ExecStart=/bin/echo $ONE $TWO $THREE
1904 .fi
1905 .if n \{\
1906 .RE
1907 .\}
1908 .PP
1909 This results in
1910 /bin/echo
1911 being called twice, the first time with arguments
1912 "\*(Aqone\*(Aq",
1913 "\*(Aqtwo\ \&two\*(Aq\ \&too",
1914 "", and the second time with arguments
1915 "one",
1916 "two\ \&two",
1917 "too"\&.
1918 .PP
1919 Unless for commands with the special executable prefix
1920 ":", to pass a literal dollar sign, use
1921 "$$"\&. 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\&.
1922 .PP
1923 Variables to be used in this fashion may be defined through
1924 \fIEnvironment=\fR
1925 and
1926 \fIEnvironmentFile=\fR\&. In addition, variables listed in the section "Environment variables in spawned processes" in
1927 \fBsystemd.exec\fR(5), which are considered "static configuration", may be used (this includes e\&.g\&.
1928 \fI$USER\fR, but not
1929 \fI$TERM\fR)\&.
1930 .PP
1931 Note that shell command lines are not directly supported, and
1932 "|"
1933 invokes the user\*(Aqs default shell which isn\*(Aqt deterministic\&. It\*(Aqs recommended to specify a shell implementation explicitly if portability is desired\&. Example:
1934 .sp
1935 .if n \{\
1936 .RS 4
1937 .\}
1938 .nf
1939 ExecStart=sh \-c \*(Aqdmesg | tac\*(Aq
1940 .fi
1941 .if n \{\
1942 .RE
1943 .\}
1944 .PP
1945 Example:
1946 .sp
1947 .if n \{\
1948 .RS 4
1949 .\}
1950 .nf
1951 ExecStart=echo one
1952 ExecStart=echo "two two"
1953 .fi
1954 .if n \{\
1955 .RE
1956 .\}
1957 .PP
1958 This will execute
1959 \fBecho\fR
1960 two times, each time with one argument:
1961 "one"
1962 and
1963 "two two", respectively\&. Because two commands are specified,
1964 \fIType=oneshot\fR
1965 must be used\&.
1966 .PP
1967 Example:
1968 .sp
1969 .if n \{\
1970 .RS 4
1971 .\}
1972 .nf
1973 Type=oneshot
1974 ExecStart=:echo $USER
1975 ExecStart=\-false
1976 ExecStart=+:@true $TEST
1977 .fi
1978 .if n \{\
1979 .RE
1980 .\}
1981 .PP
1982 This will execute
1983 \fB/usr/bin/echo\fR
1984 with the literal argument
1985 "$USER"
1986 (":"
1987 suppresses variable expansion), and then
1988 \fB/usr/bin/false\fR
1989 (the return value will be ignored because
1990 "\-"
1991 suppresses checking of the return value), and
1992 \fB/usr/bin/true\fR
1993 (with elevated privileges, with
1994 "$TEST"
1995 as
1996 \fBargv[0]\fR)\&.
1997 .PP
1998 Example:
1999 .sp
2000 .if n \{\
2001 .RS 4
2002 .\}
2003 .nf
2004 ExecStart=echo / >/dev/null & \e; \e
2005 ls
2006 .fi
2007 .if n \{\
2008 .RE
2009 .\}
2010 .PP
2011 This will execute
2012 \fBecho\fR
2013 with five arguments:
2014 "/",
2015 ">/dev/null",
2016 "&",
2017 ";", and
2018 "ls"\&.
2019 .SH "EXAMPLES"
2020 .PP
2021 \fBExample\ \&3.\ \&Simple service\fR
2022 .PP
2023 The following unit file creates a service that will execute
2024 /usr/sbin/foo\-daemon\&. Since no
2025 \fIType=\fR
2026 is specified, the default
2027 \fIType=\fR\fBsimple\fR
2028 will be assumed\&. systemd will assume the unit to be started immediately after the program has begun executing\&.
2029 .sp
2030 .if n \{\
2031 .RS 4
2032 .\}
2033 .nf
2034 [Unit]
2035 Description=Foo
2036
2037 [Service]
2038 ExecStart=/usr/sbin/foo\-daemon
2039
2040 [Install]
2041 WantedBy=multi\-user\&.target
2042 .fi
2043 .if n \{\
2044 .RE
2045 .\}
2046 .PP
2047 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
2048 \fIType=\fR\fBforking\fR
2049 instead\&.
2050 .PP
2051 Since no
2052 \fIExecStop=\fR
2053 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
2054 \fBsystemd.kill\fR(5)
2055 for details\&.
2056 .PP
2057 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
2058 \fIType=\fR\fBnotify\fR/\fIType=\fR\fBnotify\-reload\fR
2059 if the service understands systemd\*(Aqs notification protocol,
2060 \fIType=\fR\fBforking\fR
2061 if the service can background itself or
2062 \fIType=\fR\fBdbus\fR
2063 if the unit acquires a DBus name once initialization is complete\&. See below\&.
2064 .PP
2065 \fBExample\ \&4.\ \&Oneshot service\fR
2066 .PP
2067 Sometimes, units should just execute an action without keeping active processes, such as a filesystem check or a cleanup action on boot\&. For this,
2068 \fIType=\fR\fBoneshot\fR
2069 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:
2070 .sp
2071 .if n \{\
2072 .RS 4
2073 .\}
2074 .nf
2075 [Unit]
2076 Description=Cleanup old Foo data
2077
2078 [Service]
2079 Type=oneshot
2080 ExecStart=/usr/sbin/foo\-cleanup
2081
2082 [Install]
2083 WantedBy=multi\-user\&.target
2084 .fi
2085 .if n \{\
2086 .RE
2087 .\}
2088 .PP
2089 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\&.
2090 .PP
2091 \fIType=\fR\fBoneshot\fR
2092 are the only service units that may have more than one
2093 \fIExecStart=\fR
2094 specified\&. For units with multiple commands (\fIType=oneshot\fR), all commands will be run again\&.
2095 .PP
2096 For
2097 \fIType=oneshot\fR,
2098 \fIRestart=\fR\fBalways\fR
2099 and
2100 \fIRestart=\fR\fBon\-success\fR
2101 are
2102 \fInot\fR
2103 allowed\&.
2104 .PP
2105 \fBExample\ \&5.\ \&Stoppable oneshot service\fR
2106 .PP
2107 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\&.
2108 .PP
2109 For this, systemd knows the setting
2110 \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
2111 \fIType=\fR\fBoneshot\fR
2112 and
2113 \fIType=\fR\fBsimple\fR\&. With
2114 \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
2115 \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\&.
2116 .sp
2117 .if n \{\
2118 .RS 4
2119 .\}
2120 .nf
2121 [Unit]
2122 Description=Simple firewall
2123
2124 [Service]
2125 Type=oneshot
2126 RemainAfterExit=yes
2127 ExecStart=/usr/local/sbin/simple\-firewall\-start
2128 ExecStop=/usr/local/sbin/simple\-firewall\-stop
2129
2130 [Install]
2131 WantedBy=multi\-user\&.target
2132 .fi
2133 .if n \{\
2134 .RE
2135 .\}
2136 .PP
2137 Since the unit is considered to be running after the start action has exited, invoking
2138 \fBsystemctl start\fR
2139 on that unit again will cause no action to be taken\&.
2140 .PP
2141 \fBExample\ \&6.\ \&Traditional forking services\fR
2142 .PP
2143 Many traditional daemons/services background (i\&.e\&. fork, daemonize) themselves when starting\&. Set
2144 \fIType=\fR\fBforking\fR
2145 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
2146 \fIRemainAfterExit=\fR\fBno\fR), the service is considered started\&.
2147 .PP
2148 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
2149 \fI$MAINPID\fR
2150 variable will be available in
2151 \fIExecReload=\fR,
2152 \fIExecStop=\fR, etc\&.
2153 .PP
2154 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,
2155 \fI$MAINPID\fR
2156 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
2157 \fIPIDFile=\fR
2158 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\&.
2159 .PP
2160 The following example shows a simple daemon that forks and just starts one process in the background:
2161 .sp
2162 .if n \{\
2163 .RS 4
2164 .\}
2165 .nf
2166 [Unit]
2167 Description=My Simple Daemon
2168
2169 [Service]
2170 Type=forking
2171 ExecStart=/usr/sbin/my\-simple\-daemon \-d
2172
2173 [Install]
2174 WantedBy=multi\-user\&.target
2175 .fi
2176 .if n \{\
2177 .RE
2178 .\}
2179 .PP
2180 Please see
2181 \fBsystemd.kill\fR(5)
2182 for details on how you can influence the way systemd terminates the service\&.
2183 .PP
2184 \fBExample\ \&7.\ \&DBus services\fR
2185 .PP
2186 For services that acquire a name on the DBus system bus, use
2187 \fIType=\fR\fBdbus\fR
2188 and set
2189 \fIBusName=\fR
2190 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:
2191 .sp
2192 .if n \{\
2193 .RS 4
2194 .\}
2195 .nf
2196 [Unit]
2197 Description=Simple DBus Service
2198
2199 [Service]
2200 Type=dbus
2201 BusName=org\&.example\&.simple\-dbus\-service
2202 ExecStart=/usr/sbin/simple\-dbus\-service
2203
2204 [Install]
2205 WantedBy=multi\-user\&.target
2206 .fi
2207 .if n \{\
2208 .RE
2209 .\}
2210 .PP
2211 For
2212 \fIbus\-activatable\fR
2213 services, do not include a [Install] section in the systemd service file, but use the
2214 \fISystemdService=\fR
2215 option in the corresponding DBus service file, for example (/usr/share/dbus\-1/system\-services/org\&.example\&.simple\-dbus\-service\&.service):
2216 .sp
2217 .if n \{\
2218 .RS 4
2219 .\}
2220 .nf
2221 [D\-BUS Service]
2222 Name=org\&.example\&.simple\-dbus\-service
2223 Exec=/usr/sbin/simple\-dbus\-service
2224 User=root
2225 SystemdService=simple\-dbus\-service\&.service
2226 .fi
2227 .if n \{\
2228 .RE
2229 .\}
2230 .PP
2231 Please see
2232 \fBsystemd.kill\fR(5)
2233 for details on how you can influence the way systemd terminates the service\&.
2234 .PP
2235 \fBExample\ \&8.\ \&Services that notify systemd about their initialization\fR
2236 .PP
2237 \fIType=\fR\fBsimple\fR
2238 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
2239 \fIType=\fR\fBnotify\fR
2240 or
2241 \fIType=\fR\fBnotify\-reload\fR
2242 for this\&. A typical service file for such a daemon would look like this:
2243 .sp
2244 .if n \{\
2245 .RS 4
2246 .\}
2247 .nf
2248 [Unit]
2249 Description=Simple Notifying Service
2250
2251 [Service]
2252 Type=notify\-reload
2253 ExecStart=/usr/sbin/simple\-notifying\-service
2254
2255 [Install]
2256 WantedBy=multi\-user\&.target
2257 .fi
2258 .if n \{\
2259 .RE
2260 .\}
2261 .PP
2262 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
2263 \fBsd_notify\fR(3)\&. systemd will consider the unit to be in the \*(Aqstarting\*(Aq state until a readiness notification has arrived\&.
2264 .PP
2265 Please see
2266 \fBsystemd.kill\fR(5)
2267 for details on how you can influence the way systemd terminates the service\&.
2268 .PP
2269 To avoid code duplication, it is preferable to use
2270 \fBsd_notify\fR(3)
2271 when possible, especially when other APIs provided by
2272 \fBlibsystemd\fR(3)
2273 are also used, but note that the notification protocol is very simple and guaranteed to be stable as per the
2274 \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
2275 \fBsd_notify\fR(3)\&.
2276 .SH "SEE ALSO"
2277 .PP
2278 \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)
2279 .SH "NOTES"
2280 .IP " 1." 4
2281 File Descriptor Store
2282 .RS 4
2283 \%https://systemd.io/FILE_DESCRIPTOR_STORE
2284 .RE
2285 .IP " 2." 4
2286 USB FunctionFS
2287 .RS 4
2288 \%https://docs.kernel.org/usb/functionfs.html
2289 .RE
2290 .IP " 3." 4
2291 Control Group v2
2292 .RS 4
2293 \%https://docs.kernel.org/admin-guide/cgroup-v2.html
2294 .RE
2295 .IP " 4." 4
2296 Interface Portability and Stability Promise
2297 .RS 4
2298 \%https://systemd.io/PORTABILITY_AND_STABILITY/
2299 .RE