1SYSTEMD.SERVICE(5)              systemd.service             SYSTEMD.SERVICE(5)
2
3
4

NAME

6       systemd.service - Service unit configuration
7

SYNOPSIS

9       service.service
10

DESCRIPTION

12       A unit configuration file whose name ends in ".service" encodes
13       information about a process controlled and supervised by systemd.
14
15       This man page lists the configuration options specific to this unit
16       type. See systemd.unit(5) for the common options of all unit
17       configuration files. The common configuration items are configured in
18       the generic [Unit] and [Install] sections. The service specific
19       configuration options are configured in the [Service] section.
20
21       Additional options are listed in systemd.exec(5), which define the
22       execution environment the commands are executed in, and in
23       systemd.kill(5), which define the way the processes of the service are
24       terminated, and in systemd.resource-control(5), which configure
25       resource control settings for the processes of the service.
26
27       If a service is requested under a certain name but no unit
28       configuration file is found, systemd looks for a SysV init script by
29       the same name (with the .service suffix removed) and dynamically
30       creates a service unit from that script. This is useful for
31       compatibility with SysV. Note that this compatibility is quite
32       comprehensive but not 100%. For details about the incompatibilities,
33       see the Incompatibilities with SysV[1] document.
34
35       The systemd-run(1) command allows creating .service and .scope units
36       dynamically and transiently from the command line.
37

SERVICE TEMPLATES

39       It is possible for systemd services to take a single argument via the
40       "service@argument.service" syntax. Such services are called
41       "instantiated" services, while the unit definition without the argument
42       parameter is called a "template". An example could be a dhcpcd@.service
43       service template which takes a network interface as a parameter to form
44       an instantiated service. Within the service file, this parameter or
45       "instance name" can be accessed with %-specifiers. See systemd.unit(5)
46       for details.
47

AUTOMATIC DEPENDENCIES

49   Implicit Dependencies
50       The following dependencies are implicitly added:
51
52       ·   Services with Type=dbus set automatically acquire dependencies of
53           type Requires= and After= on dbus.socket.
54
55       ·   Socket activated services are automatically ordered after their
56           activating .socket units via an automatic After= dependency.
57           Services also pull in all .socket units listed in Sockets= via
58           automatic Wants= and After= dependencies.
59
60       Additional implicit dependencies may be added as result of execution
61       and resource control parameters as documented in systemd.exec(5) and
62       systemd.resource-control(5).
63
64   Default Dependencies
65       The following dependencies are added unless DefaultDependencies=no is
66       set:
67
68       ·   Service units will have dependencies of type Requires= and After=
69           on sysinit.target, a dependency of type After= on basic.target as
70           well as dependencies of type Conflicts= and Before= on
71           shutdown.target. These ensure that normal service units pull in
72           basic system initialization, and are terminated cleanly prior to
73           system shutdown. Only services involved with early boot or late
74           system shutdown should disable this option.
75
76       ·   Instanced service units (i.e. service units with an "@" in their
77           name) are assigned by default a per-template slice unit (see
78           systemd.slice(5)), named after the template unit, containing all
79           instances of the specific template. This slice is normally stopped
80           at shutdown, together with all template instances. If that is not
81           desired, set DefaultDependencies=no in the template unit, and
82           either define your own per-template slice unit file that also sets
83           DefaultDependencies=no, or set Slice=system.slice (or another
84           suitable slice) in the template unit. Also see systemd.resource-
85           control(5).
86

OPTIONS

88       Service files must include a [Service] section, which carries
89       information about the service and the process it supervises. A number
90       of options that may be used in this section are shared with other unit
91       types. These options are documented in systemd.exec(5), systemd.kill(5)
92       and systemd.resource-control(5). The options specific to the [Service]
93       section of service units are the following:
94
95       Type=
96           Configures the process start-up type for this service unit. One of
97           simple, exec, forking, oneshot, dbus, notify or idle:
98
99           ·   If set to simple (the default if ExecStart= is specified but
100               neither Type= nor BusName= are), the service manager will
101               consider the unit started immediately after the main service
102               process has been forked off. It is expected that the process
103               configured with ExecStart= is the main process of the service.
104               In this mode, if the process offers functionality to other
105               processes on the system, its communication channels should be
106               installed before the service is started up (e.g. sockets set up
107               by systemd, via socket activation), as the service manager will
108               immediately proceed starting follow-up units, right after
109               creating the main service process, and before executing the
110               service's binary. Note that this means systemctl start command
111               lines for simple services will report success even if the
112               service's binary cannot be invoked successfully (for example
113               because the selected User= doesn't exist, or the service binary
114               is missing).
115
116           ·   The exec type is similar to simple, but the service manager
117               will consider the unit started immediately after the main
118               service binary has been executed. The service manager will
119               delay starting of follow-up units until that point. (Or in
120               other words: simple proceeds with further jobs right after
121               fork() returns, while exec will not proceed before both fork()
122               and execve() in the service process succeeded.) Note that this
123               means systemctl start command lines for exec services will
124               report failure when the service's binary cannot be invoked
125               successfully (for example because the selected User= doesn't
126               exist, or the service binary is missing).
127
128           ·   If set to forking, it is expected that the process configured
129               with ExecStart= will call fork() as part of its start-up. The
130               parent process is expected to exit when start-up is complete
131               and all communication channels are set up. The child continues
132               to run as the main service process, and the service manager
133               will consider the unit started when the parent process exits.
134               This is the behavior of traditional UNIX services. If this
135               setting is used, it is recommended to also use the PIDFile=
136               option, so that systemd can reliably identify the main process
137               of the service. systemd will proceed with starting follow-up
138               units as soon as the parent process exits.
139
140           ·   Behavior of oneshot is similar to simple; however, the service
141               manager will consider the unit up after the main process exits.
142               It will then start follow-up units.  RemainAfterExit= is
143               particularly useful for this type of service.  Type=oneshot is
144               the implied default if neither Type= nor ExecStart= are
145               specified. Note that if this option is used without
146               RemainAfterExit= the service will never enter "active" unit
147               state, but directly transition from "activating" to
148               "deactivating" or "dead" since no process is configured that
149               shall run continuously. In particular this means that after a
150               service of this type ran (and which has RemainAfterExit= not
151               set) it will not show up as started afterwards, but as dead.
152
153           ·   Behavior of dbus is similar to simple; however, it is expected
154               that the service acquires a name on the D-Bus bus, as
155               configured by BusName=. systemd will proceed with starting
156               follow-up units after the D-Bus bus name has been acquired.
157               Service units with this option configured implicitly gain
158               dependencies on the dbus.socket unit. This type is the default
159               if BusName= is specified. A service unit of this type is
160               considered to be in the activating state until the specified
161               bus name is acquired. It is considered activated while the bus
162               name is taken. Once the bus name is released the service is
163               considered being no longer functional which has the effect that
164               the service manager attempts to terminate any remaining
165               processes belonging to the service. Services that drop their
166               bus name as part of their shutdown logic thus should be
167               prepared to receive a SIGTERM (or whichever signal is
168               configured in KillSignal=) as result.
169
170           ·   Behavior of notify is similar to exec; however, it is expected
171               that the service sends a notification message via sd_notify(3)
172               or an equivalent call when it has finished starting up. systemd
173               will proceed with starting follow-up units after this
174               notification message has been sent. If this option is used,
175               NotifyAccess= (see below) should be set to open access to the
176               notification socket provided by systemd. If NotifyAccess= is
177               missing or set to none, it will be forcibly set to main.
178
179           ·   Behavior of idle is very similar to simple; however, actual
180               execution of the service program is delayed until all active
181               jobs are dispatched. This may be used to avoid interleaving of
182               output of shell services with the status output on the console.
183               Note that this type is useful only to improve console output,
184               it is not useful as a general unit ordering tool, and the
185               effect of this service type is subject to a 5s timeout, after
186               which the service program is invoked anyway.
187
188           It is generally recommended to use Type=simple for long-running
189           services whenever possible, as it is the simplest and fastest
190           option. However, as this service type won't propagate service
191           start-up failures and doesn't allow ordering of other units against
192           completion of initialization of the service (which for example is
193           useful if clients need to connect to the service through some form
194           of IPC, and the IPC channel is only established by the service
195           itself — in contrast to doing this ahead of time through socket or
196           bus activation or similar), it might not be sufficient for many
197           cases. If so, notify or dbus (the latter only in case the service
198           provides a D-Bus interface) are the preferred options as they allow
199           service program code to precisely schedule when to consider the
200           service started up successfully and when to proceed with follow-up
201           units. The notify service type requires explicit support in the
202           service codebase (as sd_notify() or an equivalent API needs to be
203           invoked by the service at the appropriate time) — if it's not
204           supported, then forking is an alternative: it supports the
205           traditional UNIX service start-up protocol. Finally, exec might be
206           an option for cases where it is enough to ensure the service binary
207           is invoked, and where the service binary itself executes no or
208           little initialization on its own (and its initialization is
209           unlikely to fail). Note that using any type other than simple
210           possibly delays the boot process, as the service manager needs to
211           wait for service initialization to complete. It is hence
212           recommended not to needlessly use any types other than simple.
213           (Also note it is generally not recommended to use idle or oneshot
214           for long-running services.)
215
216       RemainAfterExit=
217           Takes a boolean value that specifies whether the service shall be
218           considered active even when all its processes exited. Defaults to
219           no.
220
221       GuessMainPID=
222           Takes a boolean value that specifies whether systemd should try to
223           guess the main PID of a service if it cannot be determined
224           reliably. This option is ignored unless Type=forking is set and
225           PIDFile= is unset because for the other types or with an explicitly
226           configured PID file, the main PID is always known. The guessing
227           algorithm might come to incorrect conclusions if a daemon consists
228           of more than one process. If the main PID cannot be determined,
229           failure detection and automatic restarting of a service will not
230           work reliably. Defaults to yes.
231
232       PIDFile=
233           Takes a path referring to the PID file of the service. Usage of
234           this option is recommended for services where Type= is set to
235           forking. The path specified typically points to a file below /run/.
236           If a relative path is specified it is hence prefixed with /run/.
237           The service manager will read the PID of the main process of the
238           service from this file after start-up of the service. The service
239           manager will not write to the file configured here, although it
240           will remove the file after the service has shut down if it still
241           exists. The PID file does not need to be owned by a privileged
242           user, but if it is owned by an unprivileged user additional safety
243           restrictions are enforced: the file may not be a symlink to a file
244           owned by a different user (neither directly nor indirectly), and
245           the PID file must refer to a process already belonging to the
246           service.
247
248       BusName=
249           Takes a D-Bus bus name that this service is reachable as. This
250           option is mandatory for services where Type= is set to dbus.
251
252       ExecStart=
253           Commands with their arguments that are executed when this service
254           is started. The value is split into zero or more command lines
255           according to the rules described below (see section "Command Lines"
256           below).
257
258           Unless Type= is oneshot, exactly one command must be given. When
259           Type=oneshot is used, zero or more commands may be specified.
260           Commands may be specified by providing multiple command lines in
261           the same directive, or alternatively, this directive may be
262           specified more than once with the same effect. If the empty string
263           is assigned to this option, the list of commands to start is reset,
264           prior assignments of this option will have no effect. If no
265           ExecStart= is specified, then the service must have
266           RemainAfterExit=yes and at least one ExecStop= line set. (Services
267           lacking both ExecStart= and ExecStop= are not valid.)
268
269           For each of the specified commands, the first argument must be
270           either an absolute path to an executable or a simple file name
271           without any slashes. Optionally, this filename may be prefixed with
272           a number of special characters:
273
274           Table 1. Special executable prefixes
275           ┌───────┬────────────────────────────┐
276Prefix Effect                     
277           ├───────┼────────────────────────────┤
278           │"@"    │ If the executable path is  │
279           │       │ prefixed with "@", the     │
280           │       │ second specified token     │
281           │       │ will be passed as          │
282           │       │ "argv[0]" to the executed  │
283           │       │ process (instead of the    │
284           │       │ actual filename), followed │
285           │       │ by the further arguments   │
286           │       │ specified.                 │
287           ├───────┼────────────────────────────┤
288           │"-"    │ If the executable path is  │
289           │       │ prefixed with "-", an exit │
290           │       │ code of the command        │
291           │       │ normally considered a      │
292           │       │ failure (i.e. non-zero     │
293           │       │ exit status or abnormal    │
294           │       │ exit due to signal) is     │
295           │       │ recorded, but has no       │
296           │       │ further effect and is      │
297           │       │ considered equivalent to   │
298           │       │ success.                   │
299           ├───────┼────────────────────────────┤
300           │":"    │ If the executable path is  │
301           │       │ prefixed with ":",         │
302           │       │ environment variable       │
303           │       │ substitution (as described │
304           │       │ by the "Command Lines"     │
305           │       │ section below) is not      │
306           │       │ applied.                   │
307           ├───────┼────────────────────────────┤
308           │"+"    │ If the executable path is  │
309           │       │ prefixed with "+" then the │
310           │       │ process is executed with   │
311           │       │ full privileges. In this   │
312           │       │ mode privilege             │
313           │       │ restrictions configured    │
314           │       │ with User=, Group=,        │
315           │       │ CapabilityBoundingSet= or  │
316           │       │ the various file system    │
317           │       │ namespacing options (such  │
318           │       │ as PrivateDevices=,        │
319           │       │ PrivateTmp=) are not       │
320           │       │ applied to the invoked     │
321           │       │ command line (but still    │
322           │       │ affect any other           │
323           │       │ ExecStart=, ExecStop=, ... │
324           │       │ lines).                    │
325           ├───────┼────────────────────────────┤
326           │"!"    │ Similar to the "+"         │
327           │       │ character discussed above  │
328           │       │ this permits invoking      │
329           │       │ command lines with         │
330           │       │ elevated privileges.       │
331           │       │ However, unlike "+" the    │
332           │       │ "!" character exclusively  │
333           │       │ alters the effect of       │
334           │       │ User=, Group= and          │
335           │       │ SupplementaryGroups=, i.e. │
336           │       │ only the stanzas that      │
337           │       │ affect user and group      │
338           │       │ credentials. Note that     │
339           │       │ this setting may be        │
340           │       │ combined with              │
341           │       │ DynamicUser=, in which     │
342           │       │ case a dynamic user/group  │
343           │       │ pair is allocated before   │
344           │       │ the command is invoked,    │
345           │       │ but credential changing is │
346           │       │ left to the executed       │
347           │       │ process itself.            │
348           ├───────┼────────────────────────────┤
349           │"!!"   │ This prefix is very        │
350           │       │ similar to "!", however it │
351           │       │ only has an effect on      │
352           │       │ systems lacking support    │
353           │       │ for ambient process        │
354           │       │ capabilities, i.e. without │
355           │       │ support for                │
356           │       │ AmbientCapabilities=. It's │
357           │       │ intended to be used for    │
358           │       │ unit files that take       │
359           │       │ benefit of ambient         │
360           │       │ capabilities to run        │
361           │       │ processes with minimal     │
362           │       │ privileges wherever        │
363           │       │ possible while remaining   │
364           │       │ compatible with systems    │
365           │       │ that lack ambient          │
366           │       │ capabilities support. Note │
367           │       │ that when "!!" is used,    │
368           │       │ and a system lacking       │
369           │       │ ambient capability support │
370           │       │ is detected any configured │
371           │       │ SystemCallFilter= and      │
372           │       │ CapabilityBoundingSet=
373           │       │ stanzas are implicitly     │
374           │       │ modified, in order to      │
375           │       │ permit spawned processes   │
376           │       │ to drop credentials and    │
377           │       │ capabilities themselves,   │
378           │       │ even if this is configured │
379           │       │ to not be allowed.         │
380           │       │ Moreover, if this prefix   │
381           │       │ is used and a system       │
382           │       │ lacking ambient capability │
383           │       │ support is detected        │
384           │       │ AmbientCapabilities= will  │
385           │       │ be skipped and not be      │
386           │       │ applied. On systems        │
387           │       │ supporting ambient         │
388           │       │ capabilities, "!!" has no  │
389           │       │ effect and is redundant.   │
390           └───────┴────────────────────────────┘
391           "@", "-", ":", and one of "+"/"!"/"!!"  may be used together and
392           they can appear in any order. However, only one of "+", "!", "!!"
393           may be used at a time. Note that these prefixes are also supported
394           for the other command line settings, i.e.  ExecStartPre=,
395           ExecStartPost=, ExecReload=, ExecStop= and ExecStopPost=.
396
397           If more than one command is specified, the commands are invoked
398           sequentially in the order they appear in the unit file. If one of
399           the commands fails (and is not prefixed with "-"), other lines are
400           not executed, and the unit is considered failed.
401
402           Unless Type=forking is set, the process started via this command
403           line will be considered the main process of the daemon.
404
405       ExecStartPre=, ExecStartPost=
406           Additional commands that are executed before or after the command
407           in ExecStart=, respectively. Syntax is the same as for ExecStart=,
408           except that multiple command lines are allowed and the commands are
409           executed one after the other, serially.
410
411           If any of those commands (not prefixed with "-") fail, the rest are
412           not executed and the unit is considered failed.
413
414           ExecStart= commands are only run after all ExecStartPre= commands
415           that were not prefixed with a "-" exit successfully.
416
417           ExecStartPost= commands are only run after the commands specified
418           in ExecStart= have been invoked successfully, as determined by
419           Type= (i.e. the process has been started for Type=simple or
420           Type=idle, the last ExecStart= process exited successfully for
421           Type=oneshot, the initial process exited successfully for
422           Type=forking, "READY=1" is sent for Type=notify, or the BusName=
423           has been taken for Type=dbus).
424
425           Note that ExecStartPre= may not be used to start long-running
426           processes. All processes forked off by processes invoked via
427           ExecStartPre= will be killed before the next service process is
428           run.
429
430           Note that if any of the commands specified in ExecStartPre=,
431           ExecStart=, or ExecStartPost= fail (and are not prefixed with "-",
432           see above) or time out before the service is fully up, execution
433           continues with commands specified in ExecStopPost=, the commands in
434           ExecStop= are skipped.
435
436           Note that the execution of ExecStartPost= is taken into account for
437           the purpose of Before=/After= ordering constraints.
438
439       ExecCondition=
440           Optional commands that are executed before the command(s) in
441           ExecStartPre=. Syntax is the same as for ExecStart=, except that
442           multiple command lines are allowed and the commands are executed
443           one after the other, serially.
444
445           The behavior is like an ExecStartPre= and condition check hybrid:
446           when an ExecCondition= command exits with exit code 1 through 254
447           (inclusive), the remaining commands are skipped and the unit is not
448           marked as failed. However, if an ExecCondition= command exits with
449           255 or abnormally (e.g. timeout, killed by a signal, etc.), the
450           unit will be considered failed (and remaining commands will be
451           skipped). Exit code of 0 or those matching SuccessExitStatus= will
452           continue execution to the next command(s).
453
454           The same recommendations about not running long-running processes
455           in ExecStartPre= also applies to ExecCondition=.  ExecCondition=
456           will also run the commands in ExecStopPost=, as part of stopping
457           the service, in the case of any non-zero or abnormal exits, like
458           the ones described above.
459
460       ExecReload=
461           Commands to execute to trigger a configuration reload in the
462           service. This argument takes multiple command lines, following the
463           same scheme as described for ExecStart= above. Use of this setting
464           is optional. Specifier and environment variable substitution is
465           supported here following the same scheme as for ExecStart=.
466
467           One additional, special environment variable is set: if known,
468           $MAINPID is set to the main process of the daemon, and may be used
469           for command lines like the following:
470
471               ExecReload=kill -HUP $MAINPID
472
473           Note however that reloading a daemon by sending a signal (as with
474           the example line above) is usually not a good choice, because this
475           is an asynchronous operation and hence not suitable to order
476           reloads of multiple services against each other. It is strongly
477           recommended to set ExecReload= to a command that not only triggers
478           a configuration reload of the daemon, but also synchronously waits
479           for it to complete. For example, dbus-broker(1) uses the following:
480
481               ExecReload=busctl call org.freedesktop.DBus \
482                       /org/freedesktop/DBus org.freedesktop.DBus \
483                       ReloadConfig
484
485       ExecStop=
486           Commands to execute to stop the service started via ExecStart=.
487           This argument takes multiple command lines, following the same
488           scheme as described for ExecStart= above. Use of this setting is
489           optional. After the commands configured in this option are run, it
490           is implied that the service is stopped, and any processes remaining
491           for it are terminated according to the KillMode= setting (see
492           systemd.kill(5)). If this option is not specified, the process is
493           terminated by sending the signal specified in KillSignal= or
494           RestartKillSignal= when service stop is requested. Specifier and
495           environment variable substitution is supported (including $MAINPID,
496           see above).
497
498           Note that it is usually not sufficient to specify a command for
499           this setting that only asks the service to terminate (for example,
500           by sending some form of termination signal to it), but does not
501           wait for it to do so. Since the remaining processes of the services
502           are killed according to KillMode= and KillSignal= or
503           RestartKillSignal= as described above immediately after the command
504           exited, this may not result in a clean stop. The specified command
505           should hence be a synchronous operation, not an asynchronous one.
506
507           Note that the commands specified in ExecStop= are only executed
508           when the service started successfully first. They are not invoked
509           if the service was never started at all, or in case its start-up
510           failed, for example because any of the commands specified in
511           ExecStart=, ExecStartPre= or ExecStartPost= failed (and weren't
512           prefixed with "-", see above) or timed out. Use ExecStopPost= to
513           invoke commands when a service failed to start up correctly and is
514           shut down again. Also note that the stop operation is always
515           performed if the service started successfully, even if the
516           processes in the service terminated on their own or were killed.
517           The stop commands must be prepared to deal with that case.
518           $MAINPID will be unset if systemd knows that the main process
519           exited by the time the stop commands are called.
520
521           Service restart requests are implemented as stop operations
522           followed by start operations. This means that ExecStop= and
523           ExecStopPost= are executed during a service restart operation.
524
525           It is recommended to use this setting for commands that communicate
526           with the service requesting clean termination. For post-mortem
527           clean-up steps use ExecStopPost= instead.
528
529       ExecStopPost=
530           Additional commands that are executed after the service is stopped.
531           This includes cases where the commands configured in ExecStop= were
532           used, where the service does not have any ExecStop= defined, or
533           where the service exited unexpectedly. This argument takes multiple
534           command lines, following the same scheme as described for
535           ExecStart=. Use of these settings is optional. Specifier and
536           environment variable substitution is supported. Note that – unlike
537           ExecStop= – commands specified with this setting are invoked when a
538           service failed to start up correctly and is shut down again.
539
540           It is recommended to use this setting for clean-up operations that
541           shall be executed even when the service failed to start up
542           correctly. Commands configured with this setting need to be able to
543           operate even if the service failed starting up half-way and left
544           incompletely initialized data around. As the service's processes
545           have been terminated already when the commands specified with this
546           setting are executed they should not attempt to communicate with
547           them.
548
549           Note that all commands that are configured with this setting are
550           invoked with the result code of the service, as well as the main
551           process' exit code and status, set in the $SERVICE_RESULT,
552           $EXIT_CODE and $EXIT_STATUS environment variables, see
553           systemd.exec(5) for details.
554
555           Note that the execution of ExecStopPost= is taken into account for
556           the purpose of Before=/After= ordering constraints.
557
558       RestartSec=
559           Configures the time to sleep before restarting a service (as
560           configured with Restart=). Takes a unit-less value in seconds, or a
561           time span value such as "5min 20s". Defaults to 100ms.
562
563       TimeoutStartSec=
564           Configures the time to wait for start-up. If a daemon service does
565           not signal start-up completion within the configured time, the
566           service will be considered failed and will be shut down again. The
567           precise action depends on the TimeoutStartFailureMode= option.
568           Takes a unit-less value in seconds, or a time span value such as
569           "5min 20s". Pass "infinity" to disable the timeout logic. Defaults
570           to DefaultTimeoutStartSec= from the manager configuration file,
571           except when Type=oneshot is used, in which case the timeout is
572           disabled by default (see systemd-system.conf(5)).
573
574           If a service of Type=notify sends "EXTEND_TIMEOUT_USEC=...", this
575           may cause the start time to be extended beyond TimeoutStartSec=.
576           The first receipt of this message must occur before
577           TimeoutStartSec= is exceeded, and once the start time has extended
578           beyond TimeoutStartSec=, the service manager will allow the service
579           to continue to start, provided the service repeats
580           "EXTEND_TIMEOUT_USEC=..."  within the interval specified until the
581           service startup status is finished by "READY=1". (see
582           sd_notify(3)).
583
584       TimeoutStopSec=
585           This option serves two purposes. First, it configures the time to
586           wait for each ExecStop= command. If any of them times out,
587           subsequent ExecStop= commands are skipped and the service will be
588           terminated by SIGTERM. If no ExecStop= commands are specified, the
589           service gets the SIGTERM immediately. This default behavior can be
590           changed by the TimeoutStopFailureMode= option. Second, it
591           configures the time to wait for the service itself to stop. If it
592           doesn't terminate in the specified time, it will be forcibly
593           terminated by SIGKILL (see KillMode= in systemd.kill(5)). Takes a
594           unit-less value in seconds, or a time span value such as "5min
595           20s". Pass "infinity" to disable the timeout logic. Defaults to
596           DefaultTimeoutStopSec= from the manager configuration file (see
597           systemd-system.conf(5)).
598
599           If a service of Type=notify sends "EXTEND_TIMEOUT_USEC=...", this
600           may cause the stop time to be extended beyond TimeoutStopSec=. The
601           first receipt of this message must occur before TimeoutStopSec= is
602           exceeded, and once the stop time has extended beyond
603           TimeoutStopSec=, the service manager will allow the service to
604           continue to stop, provided the service repeats
605           "EXTEND_TIMEOUT_USEC=..."  within the interval specified, or
606           terminates itself (see sd_notify(3)).
607
608       TimeoutAbortSec=
609           This option configures the time to wait for the service to
610           terminate when it was aborted due to a watchdog timeout (see
611           WatchdogSec=). If the service has a short TimeoutStopSec= this
612           option can be used to give the system more time to write a core
613           dump of the service. Upon expiration the service will be forcibly
614           terminated by SIGKILL (see KillMode= in systemd.kill(5)). The core
615           file will be truncated in this case. Use TimeoutAbortSec= to set a
616           sensible timeout for the core dumping per service that is large
617           enough to write all expected data while also being short enough to
618           handle the service failure in due time.
619
620           Takes a unit-less value in seconds, or a time span value such as
621           "5min 20s". Pass an empty value to skip the dedicated watchdog
622           abort timeout handling and fall back TimeoutStopSec=. Pass
623           "infinity" to disable the timeout logic. Defaults to
624           DefaultTimeoutAbortSec= from the manager configuration file (see
625           systemd-system.conf(5)).
626
627           If a service of Type=notify handles SIGABRT itself (instead of
628           relying on the kernel to write a core dump) it can send
629           "EXTEND_TIMEOUT_USEC=..."  to extended the abort time beyond
630           TimeoutAbortSec=. The first receipt of this message must occur
631           before TimeoutAbortSec= is exceeded, and once the abort time has
632           extended beyond TimeoutAbortSec=, the service manager will allow
633           the service to continue to abort, provided the service repeats
634           "EXTEND_TIMEOUT_USEC=..."  within the interval specified, or
635           terminates itself (see sd_notify(3)).
636
637       TimeoutSec=
638           A shorthand for configuring both TimeoutStartSec= and
639           TimeoutStopSec= to the specified value.
640
641       TimeoutStartFailureMode=, TimeoutStopFailureMode=
642           These options configure the action that is taken in case a daemon
643           service does not signal start-up within its configured
644           TimeoutStartSec=, respectively if it does not stop within
645           TimeoutStopSec=. Takes one of terminate, abort and kill. Both
646           options default to terminate.
647
648           If terminate is set the service will be gracefully terminated by
649           sending the signal specified in KillSignal= (defaults to SIGTERM,
650           see systemd.kill(5)). If the service does not terminate the
651           FinalKillSignal= is sent after TimeoutStopSec=. If abort is set,
652           WatchdogSignal= is sent instead and TimeoutAbortSec= applies before
653           sending FinalKillSignal=. This setting may be used to analyze
654           services that fail to start-up or shut-down intermittently. By
655           using kill the service is immediately terminated by sending
656           FinalKillSignal= without any further timeout. This setting can be
657           used to expedite the shutdown of failing services.
658
659       RuntimeMaxSec=
660           Configures a maximum time for the service to run. If this is used
661           and the service has been active for longer than the specified time
662           it is terminated and put into a failure state. Note that this
663           setting does not have any effect on Type=oneshot services, as they
664           terminate immediately after activation completed. Pass "infinity"
665           (the default) to configure no runtime limit.
666
667           If a service of Type=notify sends "EXTEND_TIMEOUT_USEC=...", this
668           may cause the runtime to be extended beyond RuntimeMaxSec=. The
669           first receipt of this message must occur before RuntimeMaxSec= is
670           exceeded, and once the runtime has extended beyond RuntimeMaxSec=,
671           the service manager will allow the service to continue to run,
672           provided the service repeats "EXTEND_TIMEOUT_USEC=..."  within the
673           interval specified until the service shutdown is achieved by
674           "STOPPING=1" (or termination). (see sd_notify(3)).
675
676       WatchdogSec=
677           Configures the watchdog timeout for a service. The watchdog is
678           activated when the start-up is completed. The service must call
679           sd_notify(3) regularly with "WATCHDOG=1" (i.e. the "keep-alive
680           ping"). If the time between two such calls is larger than the
681           configured time, then the service is placed in a failed state and
682           it will be terminated with SIGABRT (or the signal specified by
683           WatchdogSignal=). By setting Restart= to on-failure, on-watchdog,
684           on-abnormal or always, the service will be automatically restarted.
685           The time configured here will be passed to the executed service
686           process in the WATCHDOG_USEC= environment variable. This allows
687           daemons to automatically enable the keep-alive pinging logic if
688           watchdog support is enabled for the service. If this option is
689           used, NotifyAccess= (see below) should be set to open access to the
690           notification socket provided by systemd. If NotifyAccess= is not
691           set, it will be implicitly set to main. Defaults to 0, which
692           disables this feature. The service can check whether the service
693           manager expects watchdog keep-alive notifications. See
694           sd_watchdog_enabled(3) for details.  sd_event_set_watchdog(3) may
695           be used to enable automatic watchdog notification support.
696
697       Restart=
698           Configures whether the service shall be restarted when the service
699           process exits, is killed, or a timeout is reached. The service
700           process may be the main service process, but it may also be one of
701           the processes specified with ExecStartPre=, ExecStartPost=,
702           ExecStop=, ExecStopPost=, or ExecReload=. When the death of the
703           process is a result of systemd operation (e.g. service stop or
704           restart), the service will not be restarted. Timeouts include
705           missing the watchdog "keep-alive ping" deadline and a service
706           start, reload, and stop operation timeouts.
707
708           Takes one of no, on-success, on-failure, on-abnormal, on-watchdog,
709           on-abort, or always. If set to no (the default), the service will
710           not be restarted. If set to on-success, it will be restarted only
711           when the service process exits cleanly. In this context, a clean
712           exit means any of the following:
713
714           ·   exit code of 0;
715
716           ·   for types other than Type=oneshot, one of the signals SIGHUP,
717               SIGINT, SIGTERM, or SIGPIPE;
718
719           ·   exit statuses and signals specified in SuccessExitStatus=.
720
721           If set to on-failure, the service will be restarted when the
722           process exits with a non-zero exit code, is terminated by a signal
723           (including on core dump, but excluding the aforementioned four
724           signals), when an operation (such as service reload) times out, and
725           when the configured watchdog timeout is triggered. If set to
726           on-abnormal, the service will be restarted when the process is
727           terminated by a signal (including on core dump, excluding the
728           aforementioned four signals), when an operation times out, or when
729           the watchdog timeout is triggered. If set to on-abort, the service
730           will be restarted only if the service process exits due to an
731           uncaught signal not specified as a clean exit status. If set to
732           on-watchdog, the service will be restarted only if the watchdog
733           timeout for the service expires. If set to always, the service will
734           be restarted regardless of whether it exited cleanly or not, got
735           terminated abnormally by a signal, or hit a timeout.
736
737           Table 2. Exit causes and the effect of the Restart= settings on
738           them
739           ┌──────────────┬────┬────────┬────────────┬────────────┬─────────────┬──────────┬─────────────┐
740Restart       no always on-success on-failure on-abnormal on-abort on-watchdog 
741settings/Exit │    │        │            │            │             │          │             │
742causes        │    │        │            │            │             │          │             │
743           ├──────────────┼────┼────────┼────────────┼────────────┼─────────────┼──────────┼─────────────┤
744           │Clean exit    │    │ X      │ X          │            │             │          │             │
745           │code or       │    │        │            │            │             │          │             │
746           │signal        │    │        │            │            │             │          │             │
747           ├──────────────┼────┼────────┼────────────┼────────────┼─────────────┼──────────┼─────────────┤
748           │Unclean exit  │    │ X      │            │ X          │             │          │             │
749           │code          │    │        │            │            │             │          │             │
750           ├──────────────┼────┼────────┼────────────┼────────────┼─────────────┼──────────┼─────────────┤
751           │Unclean       │    │ X      │            │ X          │ X           │ X        │             │
752           │signal        │    │        │            │            │             │          │             │
753           ├──────────────┼────┼────────┼────────────┼────────────┼─────────────┼──────────┼─────────────┤
754           │Timeout       │    │ X      │            │ X          │ X           │          │             │
755           ├──────────────┼────┼────────┼────────────┼────────────┼─────────────┼──────────┼─────────────┤
756           │Watchdog      │    │ X      │            │ X          │ X           │          │ X           │
757           └──────────────┴────┴────────┴────────────┴────────────┴─────────────┴──────────┴─────────────┘
758           As exceptions to the setting above, the service will not be
759           restarted if the exit code or signal is specified in
760           RestartPreventExitStatus= (see below) or the service is stopped
761           with systemctl stop or an equivalent operation. Also, the services
762           will always be restarted if the exit code or signal is specified in
763           RestartForceExitStatus= (see below).
764
765           Note that service restart is subject to unit start rate limiting
766           configured with StartLimitIntervalSec= and StartLimitBurst=, see
767           systemd.unit(5) for details. A restarted service enters the failed
768           state only after the start limits are reached.
769
770           Setting this to on-failure is the recommended choice for
771           long-running services, in order to increase reliability by
772           attempting automatic recovery from errors. For services that shall
773           be able to terminate on their own choice (and avoid immediate
774           restarting), on-abnormal is an alternative choice.
775
776       SuccessExitStatus=
777           Takes a list of exit status definitions that, when returned by the
778           main service process, will be considered successful termination, in
779           addition to the normal successful exit status 0 and, except for
780           Type=oneshot, the signals SIGHUP, SIGINT, SIGTERM, and SIGPIPE.
781           Exit status definitions can be numeric termination statuses,
782           termination status names, or termination signal names, separated by
783           spaces. See the Process Exit Codes section in systemd.exec(5) for a
784           list of termination status names (for this setting only the part
785           without the "EXIT_" or "EX_" prefix should be used). See signal(7)
786           for a list of signal names.
787
788           Note that this setting does not change the mapping between numeric
789           exit statuses and their names, i.e. regardless how this setting is
790           used 0 will still be mapped to "SUCCESS" (and thus typically shown
791           as "0/SUCCESS" in tool outputs) and 1 to "FAILURE" (and thus
792           typically shown as "1/FAILURE"), and so on. It only controls what
793           happens as effect of these exit statuses, and how it propagates to
794           the state of the service as a whole.
795
796           This option may appear more than once, in which case the list of
797           successful exit statuses is merged. If the empty string is assigned
798           to this option, the list is reset, all prior assignments of this
799           option will have no effect.
800
801           Example 1. A service with the SuccessExitStatus= setting
802
803               SuccessExitStatus=TEMPFAIL 250 SIGKILL
804
805           Exit status 75 (TEMPFAIL), 250, and the termination signal SIGKILL
806           are considered clean service terminations.
807
808           Note: systemd-analyze exit-status may be used to list exit statuses
809           and translate between numerical status values and names.
810
811       RestartPreventExitStatus=
812           Takes a list of exit status definitions that, when returned by the
813           main service process, will prevent automatic service restarts,
814           regardless of the restart setting configured with Restart=. Exit
815           status definitions can either be numeric exit codes or termination
816           signal names, and are separated by spaces. Defaults to the empty
817           list, so that, by default, no exit status is excluded from the
818           configured restart logic. For example:
819
820               RestartPreventExitStatus=1 6 SIGABRT
821
822           ensures that exit codes 1 and 6 and the termination signal SIGABRT
823           will not result in automatic service restarting. This option may
824           appear more than once, in which case the list of restart-preventing
825           statuses is merged. If the empty string is assigned to this option,
826           the list is reset and all prior assignments of this option will
827           have no effect.
828
829           Note that this setting has no effect on processes configured via
830           ExecStartPre=, ExecStartPost=, ExecStop=, ExecStopPost= or
831           ExecReload=, but only on the main service process, i.e. either the
832           one invoked by ExecStart= or (depending on Type=, PIDFile=, ...)
833           the otherwise configured main process.
834
835       RestartForceExitStatus=
836           Takes a list of exit status definitions that, when returned by the
837           main service process, will force automatic service restarts,
838           regardless of the restart setting configured with Restart=. The
839           argument format is similar to RestartPreventExitStatus=.
840
841       RootDirectoryStartOnly=
842           Takes a boolean argument. If true, the root directory, as
843           configured with the RootDirectory= option (see systemd.exec(5) for
844           more information), is only applied to the process started with
845           ExecStart=, and not to the various other ExecStartPre=,
846           ExecStartPost=, ExecReload=, ExecStop=, and ExecStopPost= commands.
847           If false, the setting is applied to all configured commands the
848           same way. Defaults to false.
849
850       NonBlocking=
851           Set the O_NONBLOCK flag for all file descriptors passed via
852           socket-based activation. If true, all file descriptors >= 3 (i.e.
853           all except stdin, stdout, stderr), excluding those passed in via
854           the file descriptor storage logic (see FileDescriptorStoreMax= for
855           details), will have the O_NONBLOCK flag set and hence are in
856           non-blocking mode. This option is only useful in conjunction with a
857           socket unit, as described in systemd.socket(5) and has no effect on
858           file descriptors which were previously saved in the file-descriptor
859           store for example. Defaults to false.
860
861       NotifyAccess=
862           Controls access to the service status notification socket, as
863           accessible via the sd_notify(3) call. Takes one of none (the
864           default), main, exec or all. If none, no daemon status updates are
865           accepted from the service processes, all status update messages are
866           ignored. If main, only service updates sent from the main process
867           of the service are accepted. If exec, only service updates sent
868           from any of the main or control processes originating from one of
869           the Exec*= commands are accepted. If all, all services updates from
870           all members of the service's control group are accepted. This
871           option should be set to open access to the notification socket when
872           using Type=notify or WatchdogSec= (see above). If those options are
873           used but NotifyAccess= is not configured, it will be implicitly set
874           to main.
875
876           Note that sd_notify() notifications may be attributed to units
877           correctly only if either the sending process is still around at the
878           time PID 1 processes the message, or if the sending process is
879           explicitly runtime-tracked by the service manager. The latter is
880           the case if the service manager originally forked off the process,
881           i.e. on all processes that match main or exec. Conversely, if an
882           auxiliary process of the unit sends an sd_notify() message and
883           immediately exits, the service manager might not be able to
884           properly attribute the message to the unit, and thus will ignore
885           it, even if NotifyAccess=all is set for it.
886
887           Hence, to eliminate all race conditions involving lookup of the
888           client's unit and attribution of notifications to units correctly,
889           sd_notify_barrier() may be used. This call acts as a
890           synchronization point and ensures all notifications sent before
891           this call have been picked up by the service manager when it
892           returns successfully. Use of sd_notify_barrier() is needed for
893           clients which are not invoked by the service manager, otherwise
894           this synchronization mechanism is unnecessary for attribution of
895           notifications to the unit.
896
897       Sockets=
898           Specifies the name of the socket units this service shall inherit
899           socket file descriptors from when the service is started. Normally,
900           it should not be necessary to use this setting, as all socket file
901           descriptors whose unit shares the same name as the service (subject
902           to the different unit name suffix of course) are passed to the
903           spawned process.
904
905           Note that the same socket file descriptors may be passed to
906           multiple processes simultaneously. Also note that a different
907           service may be activated on incoming socket traffic than the one
908           which is ultimately configured to inherit the socket file
909           descriptors. Or, in other words: the Service= setting of .socket
910           units does not have to match the inverse of the Sockets= setting of
911           the .service it refers to.
912
913           This option may appear more than once, in which case the list of
914           socket units is merged. Note that once set, clearing the list of
915           sockets again (for example, by assigning the empty string to this
916           option) is not supported.
917
918       FileDescriptorStoreMax=
919           Configure how many file descriptors may be stored in the service
920           manager for the service using sd_pid_notify_with_fds(3)'s
921           "FDSTORE=1" messages. This is useful for implementing services that
922           can restart after an explicit request or a crash without losing
923           state. Any open sockets and other file descriptors which should not
924           be closed during the restart may be stored this way. Application
925           state can either be serialized to a file in /run, or better, stored
926           in a memfd_create(2) memory file descriptor. Defaults to 0, i.e. no
927           file descriptors may be stored in the service manager. All file
928           descriptors passed to the service manager from a specific service
929           are passed back to the service's main process on the next service
930           restart (see sd_listen_fds(3) for details about the precise
931           protocol used and the order in which the file descriptors are
932           passed). Any file descriptors passed to the service manager are
933           automatically closed when POLLHUP or POLLERR is seen on them, or
934           when the service is fully stopped and no job is queued or being
935           executed for it. If this option is used, NotifyAccess= (see above)
936           should be set to open access to the notification socket provided by
937           systemd. If NotifyAccess= is not set, it will be implicitly set to
938           main.
939
940       USBFunctionDescriptors=
941           Configure the location of a file containing USB FunctionFS[2]
942           descriptors, for implementation of USB gadget functions. This is
943           used only in conjunction with a socket unit with ListenUSBFunction=
944           configured. The contents of this file are written to the ep0 file
945           after it is opened.
946
947       USBFunctionStrings=
948           Configure the location of a file containing USB FunctionFS strings.
949           Behavior is similar to USBFunctionDescriptors= above.
950
951       OOMPolicy=
952           Configure the Out-Of-Memory (OOM) killer policy. On Linux, when
953           memory becomes scarce the kernel might decide to kill a running
954           process in order to free up memory and reduce memory pressure. This
955           setting takes one of continue, stop or kill. If set to continue and
956           a process of the service is killed by the kernel's OOM killer this
957           is logged but the service continues running. If set to stop the
958           event is logged but the service is terminated cleanly by the
959           service manager. If set to kill and one of the service's processes
960           is killed by the OOM killer the kernel is instructed to kill all
961           remaining processes of the service, too. Defaults to the setting
962           DefaultOOMPolicy= in systemd-system.conf(5) is set to, except for
963           services where Delegate= is turned on, where it defaults to
964           continue.
965
966           Use the OOMScoreAdjust= setting to configure whether processes of
967           the unit shall be considered preferred or less preferred candidates
968           for process termination by the Linux OOM killer logic. See
969           systemd.exec(5) for details.
970
971       Check systemd.exec(5) and systemd.kill(5) for more settings.
972

COMMAND LINES

974       This section describes command line parsing and variable and specifier
975       substitutions for ExecStart=, ExecStartPre=, ExecStartPost=,
976       ExecReload=, ExecStop=, and ExecStopPost= options.
977
978       Multiple command lines may be concatenated in a single directive by
979       separating them with semicolons (these semicolons must be passed as
980       separate words). Lone semicolons may be escaped as "\;".
981
982       Each command line is split on whitespace, with the first item being the
983       command to execute, and the subsequent items being the arguments.
984       Double quotes ("...") and single quotes ('...') may be used to wrap a
985       whole item (the opening quote may appear only at the beginning or after
986       whitespace that is not quoted, and the closing quote must be followed
987       by whitespace or the end of line), in which case everything until the
988       next matching quote becomes part of the same argument. Quotes
989       themselves are removed. C-style escapes are also supported. The table
990       below contains the list of known escape patterns. Only escape patterns
991       which match the syntax in the table are allowed; other patterns may be
992       added in the future and unknown patterns will result in a warning. In
993       particular, any backslashes should be doubled. Finally, a trailing
994       backslash ("\") may be used to merge lines.
995
996       This syntax is inspired by shell syntax, but only the meta-characters
997       and expansions described in the following paragraphs are understood,
998       and the expansion of variables is different. Specifically, redirection
999       using "<", "<<", ">", and ">>", pipes using "|", running programs in
1000       the background using "&", and other elements of shell syntax are not
1001       supported.
1002
1003       The command to execute may contain spaces, but control characters are
1004       not allowed.
1005
1006       The command line accepts "%" specifiers as described in
1007       systemd.unit(5).
1008
1009       Basic environment variable substitution is supported. Use "${FOO}" as
1010       part of a word, or as a word of its own, on the command line, in which
1011       case it will be erased and replaced by the exact value of the
1012       environment variable (if any) including all whitespace it contains,
1013       always resulting in exactly a single argument. Use "$FOO" as a separate
1014       word on the command line, in which case it will be replaced by the
1015       value of the environment variable split at whitespace, resulting in
1016       zero or more arguments. For this type of expansion, quotes are
1017       respected when splitting into words, and afterwards removed.
1018
1019       If the command is not a full (absolute) path, it will be resolved to a
1020       full path using a fixed search path determinted at compilation time.
1021       Searched directories include /usr/local/bin/, /usr/bin/, /bin/ on
1022       systems using split /usr/bin/ and /bin/ directories, and their sbin/
1023       counterparts on systems using split bin/ and sbin/. It is thus safe to
1024       use just the executable name in case of executables located in any of
1025       the "standard" directories, and an absolute path must be used in other
1026       cases. Using an absolute path is recommended to avoid ambiguity. Hint:
1027       this search path may be queried using systemd-path
1028       search-binaries-default.
1029
1030       Example:
1031
1032           Environment="ONE=one" 'TWO=two two'
1033           ExecStart=echo $ONE $TWO ${TWO}
1034
1035       This will execute /bin/echo with four arguments: "one", "two", "two",
1036       and "two two".
1037
1038       Example:
1039
1040           Environment=ONE='one' "TWO='two two' too" THREE=
1041           ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
1042           ExecStart=/bin/echo $ONE $TWO $THREE
1043
1044       This results in /bin/echo being called twice, the first time with
1045       arguments "'one'", "'two two' too", "", and the second time with
1046       arguments "one", "two two", "too".
1047
1048       To pass a literal dollar sign, use "$$". Variables whose value is not
1049       known at expansion time are treated as empty strings. Note that the
1050       first argument (i.e. the program to execute) may not be a variable.
1051
1052       Variables to be used in this fashion may be defined through
1053       Environment= and EnvironmentFile=. In addition, variables listed in the
1054       section "Environment variables in spawned processes" in
1055       systemd.exec(5), which are considered "static configuration", may be
1056       used (this includes e.g.  $USER, but not $TERM).
1057
1058       Note that shell command lines are not directly supported. If shell
1059       command lines are to be used, they need to be passed explicitly to a
1060       shell implementation of some kind. Example:
1061
1062           ExecStart=sh -c 'dmesg | tac'
1063
1064       Example:
1065
1066           ExecStart=echo one ; echo "two two"
1067
1068       This will execute echo two times, each time with one argument: "one"
1069       and "two two", respectively. Because two commands are specified,
1070       Type=oneshot must be used.
1071
1072       Example:
1073
1074           ExecStart=echo / >/dev/null & \; \
1075           ls
1076
1077       This will execute echo with five arguments: "/", ">/dev/null", "&",
1078       ";", and "ls".
1079
1080       Table 3. C escapes supported in command lines and environment variables
1081       ┌────────┬─────────────────────────┐
1082Literal Actual value            
1083       ├────────┼─────────────────────────┤
1084       │"\a"    │ bell                    │
1085       ├────────┼─────────────────────────┤
1086       │"\b"    │ backspace               │
1087       ├────────┼─────────────────────────┤
1088       │"\f"    │ form feed               │
1089       ├────────┼─────────────────────────┤
1090       │"\n"    │ newline                 │
1091       ├────────┼─────────────────────────┤
1092       │"\r"    │ carriage return         │
1093       ├────────┼─────────────────────────┤
1094       │"\t"    │ tab                     │
1095       ├────────┼─────────────────────────┤
1096       │"\v"    │ vertical tab            │
1097       ├────────┼─────────────────────────┤
1098       │"\\"    │ backslash               │
1099       ├────────┼─────────────────────────┤
1100       │"\""    │ double quotation mark   │
1101       ├────────┼─────────────────────────┤
1102       │"\'"    │ single quotation mark   │
1103       ├────────┼─────────────────────────┤
1104       │"\s"    │ space                   │
1105       ├────────┼─────────────────────────┤
1106       │"\xxx"  │ character number xx in  │
1107       │        │ hexadecimal encoding    │
1108       ├────────┼─────────────────────────┤
1109       │"\nnn"  │ character number nnn in │
1110       │        │ octal encoding          │
1111       └────────┴─────────────────────────┘
1112

EXAMPLES

1114       Example 2. Simple service
1115
1116       The following unit file creates a service that will execute
1117       /usr/sbin/foo-daemon. Since no Type= is specified, the default
1118       Type=simple will be assumed. systemd will assume the unit to be started
1119       immediately after the program has begun executing.
1120
1121           [Unit]
1122           Description=Foo
1123
1124           [Service]
1125           ExecStart=/usr/sbin/foo-daemon
1126
1127           [Install]
1128           WantedBy=multi-user.target
1129
1130       Note that systemd assumes here that the process started by systemd will
1131       continue running until the service terminates. If the program
1132       daemonizes itself (i.e. forks), please use Type=forking instead.
1133
1134       Since no ExecStop= was specified, systemd will send SIGTERM to all
1135       processes started from this service, and after a timeout also SIGKILL.
1136       This behavior can be modified, see systemd.kill(5) for details.
1137
1138       Note that this unit type does not include any type of notification when
1139       a service has completed initialization. For this, you should use other
1140       unit types, such as Type=notify if the service understands systemd's
1141       notification protocol, Type=forking if the service can background
1142       itself or Type=dbus if the unit acquires a DBus name once
1143       initialization is complete. See below.
1144
1145       Example 3. Oneshot service
1146
1147       Sometimes, units should just execute an action without keeping active
1148       processes, such as a filesystem check or a cleanup action on boot. For
1149       this, Type=oneshot exists. Units of this type will wait until the
1150       process specified terminates and then fall back to being inactive. The
1151       following unit will perform a cleanup action:
1152
1153           [Unit]
1154           Description=Cleanup old Foo data
1155
1156           [Service]
1157           Type=oneshot
1158           ExecStart=/usr/sbin/foo-cleanup
1159
1160           [Install]
1161           WantedBy=multi-user.target
1162
1163       Note that systemd will consider the unit to be in the state "starting"
1164       until the program has terminated, so ordered dependencies will wait for
1165       the program to finish before starting themselves. The unit will revert
1166       to the "inactive" state after the execution is done, never reaching the
1167       "active" state. That means another request to start the unit will
1168       perform the action again.
1169
1170       Type=oneshot are the only service units that may have more than one
1171       ExecStart= specified. For units with multiple commands (Type=oneshot),
1172       all commands will be run again.
1173
1174       For Type=oneshot, Restart=always and Restart=on-success are not
1175       allowed.
1176
1177       Example 4. Stoppable oneshot service
1178
1179       Similarly to the oneshot services, there are sometimes units that need
1180       to execute a program to set up something and then execute another to
1181       shut it down, but no process remains active while they are considered
1182       "started". Network configuration can sometimes fall into this category.
1183       Another use case is if a oneshot service shall not be executed each
1184       time when they are pulled in as a dependency, but only the first time.
1185
1186       For this, systemd knows the setting RemainAfterExit=yes, which causes
1187       systemd to consider the unit to be active if the start action exited
1188       successfully. This directive can be used with all types, but is most
1189       useful with Type=oneshot and Type=simple. With Type=oneshot, systemd
1190       waits until the start action has completed before it considers the unit
1191       to be active, so dependencies start only after the start action has
1192       succeeded. With Type=simple, dependencies will start immediately after
1193       the start action has been dispatched. The following unit provides an
1194       example for a simple static firewall.
1195
1196           [Unit]
1197           Description=Simple firewall
1198
1199           [Service]
1200           Type=oneshot
1201           RemainAfterExit=yes
1202           ExecStart=/usr/local/sbin/simple-firewall-start
1203           ExecStop=/usr/local/sbin/simple-firewall-stop
1204
1205           [Install]
1206           WantedBy=multi-user.target
1207
1208       Since the unit is considered to be running after the start action has
1209       exited, invoking systemctl start on that unit again will cause no
1210       action to be taken.
1211
1212       Example 5. Traditional forking services
1213
1214       Many traditional daemons/services background (i.e. fork, daemonize)
1215       themselves when starting. Set Type=forking in the service's unit file
1216       to support this mode of operation. systemd will consider the service to
1217       be in the process of initialization while the original program is still
1218       running. Once it exits successfully and at least a process remains (and
1219       RemainAfterExit=no), the service is considered started.
1220
1221       Often, a traditional daemon only consists of one process. Therefore, if
1222       only one process is left after the original process terminates, systemd
1223       will consider that process the main process of the service. In that
1224       case, the $MAINPID variable will be available in ExecReload=,
1225       ExecStop=, etc.
1226
1227       In case more than one process remains, systemd will be unable to
1228       determine the main process, so it will not assume there is one. In that
1229       case, $MAINPID will not expand to anything. However, if the process
1230       decides to write a traditional PID file, systemd will be able to read
1231       the main PID from there. Please set PIDFile= accordingly. Note that the
1232       daemon should write that file before finishing with its initialization.
1233       Otherwise, systemd might try to read the file before it exists.
1234
1235       The following example shows a simple daemon that forks and just starts
1236       one process in the background:
1237
1238           [Unit]
1239           Description=Some simple daemon
1240
1241           [Service]
1242           Type=forking
1243           ExecStart=/usr/sbin/my-simple-daemon -d
1244
1245           [Install]
1246           WantedBy=multi-user.target
1247
1248       Please see systemd.kill(5) for details on how you can influence the way
1249       systemd terminates the service.
1250
1251       Example 6. DBus services
1252
1253       For services that acquire a name on the DBus system bus, use Type=dbus
1254       and set BusName= accordingly. The service should not fork (daemonize).
1255       systemd will consider the service to be initialized once the name has
1256       been acquired on the system bus. The following example shows a typical
1257       DBus service:
1258
1259           [Unit]
1260           Description=Simple DBus service
1261
1262           [Service]
1263           Type=dbus
1264           BusName=org.example.simple-dbus-service
1265           ExecStart=/usr/sbin/simple-dbus-service
1266
1267           [Install]
1268           WantedBy=multi-user.target
1269
1270       For bus-activatable services, do not include a [Install] section in the
1271       systemd service file, but use the SystemdService= option in the
1272       corresponding DBus service file, for example
1273       (/usr/share/dbus-1/system-services/org.example.simple-dbus-service.service):
1274
1275           [D-BUS Service]
1276           Name=org.example.simple-dbus-service
1277           Exec=/usr/sbin/simple-dbus-service
1278           User=root
1279           SystemdService=simple-dbus-service.service
1280
1281       Please see systemd.kill(5) for details on how you can influence the way
1282       systemd terminates the service.
1283
1284       Example 7. Services that notify systemd about their initialization
1285
1286       Type=simple services are really easy to write, but have the major
1287       disadvantage of systemd not being able to tell when initialization of
1288       the given service is complete. For this reason, systemd supports a
1289       simple notification protocol that allows daemons to make systemd aware
1290       that they are done initializing. Use Type=notify for this. A typical
1291       service file for such a daemon would look like this:
1292
1293           [Unit]
1294           Description=Simple notifying service
1295
1296           [Service]
1297           Type=notify
1298           ExecStart=/usr/sbin/simple-notifying-service
1299
1300           [Install]
1301           WantedBy=multi-user.target
1302
1303       Note that the daemon has to support systemd's notification protocol,
1304       else systemd will think the service has not started yet and kill it
1305       after a timeout. For an example of how to update daemons to support
1306       this protocol transparently, take a look at sd_notify(3). systemd will
1307       consider the unit to be in the 'starting' state until a readiness
1308       notification has arrived.
1309
1310       Please see systemd.kill(5) for details on how you can influence the way
1311       systemd terminates the service.
1312

SEE ALSO

1314       systemd(1), systemctl(1), systemd-system.conf(5), systemd.unit(5),
1315       systemd.exec(5), systemd.resource-control(5), systemd.kill(5),
1316       systemd.directives(7), systemd-run(1)
1317

NOTES

1319        1. Incompatibilities with SysV
1320           https://www.freedesktop.org/wiki/Software/systemd/Incompatibilities
1321
1322        2. USB FunctionFS
1323           https://www.kernel.org/doc/Documentation/usb/functionfs.txt
1324
1325
1326
1327systemd 246                                                 SYSTEMD.SERVICE(5)
Impressum