What is the difference between systemd
service Type
oneshot
and simple
?
This link states to use simple
instead of oneshot
for timers. I am not able to understand it correctly.

- 2,702
- 1
- 21
- 22

- 6,936
- 6
- 35
- 44
2 Answers
The Type=oneshot
service unit:
blocks on a start operation until the first process exits, and its state will be reported as "activating";
once the first process exits, transitions from "activating" straight to "inactive", unless
RemainAfterExit=true
is set (in which case it becomes "active" with no processes!);may have any number (0 or more) of
ExecStart=
directives which will be executed sequentially (waiting for each started process to exit before starting the next one);may leave out
ExecStart=
but haveExecStop=
(useful together withRemainAfterExit=true
for arranging things to run on system shutdown).
The Type=simple
service unit:
does not block on a start operation (i. e. becomes "active" immediately after forking off the first process, even if it is still initializing!);
once the first process exits, transitions from "active" to "inactive" (there is no
RemainAfterExit=
option);is generally discouraged because there is no way to distinguish situations like "exited on start because of a configuration error" from "crashed after 500ms of runtime" and suchlike.
Both Type=oneshot
and Type=simple
units:
- ignore any children of the first process, so do not use these modes with forking processes (note: you may use
Type=oneshot
withKillMode=none
, but only do this if you know what you are doing).

- 2,386
- 1
- 19
- 32
-
2intelfx says that the `Type=oneshot` service unit "can have no `ExecStart=`". This is not true. In fact, services of type `oneshot` can have multiple `ExecStart=` directives. See any recent man page for `systemd.service` for more information. – rlandster Oct 22 '17 at 01:09
-
2@rlandster: Why is this "not true"? [systemd.service(5)](https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart=) says under `ExecStart=`: "Unless Type= is oneshot, exactly one command must be given. When Type=oneshot is used, zero or more commands may be specified." – intelfx Oct 22 '17 at 01:22
-
1agree that "can have no" is confusing. that is not true. but i think you can't have `ExecReload` – Tony Apr 02 '18 at 01:43
-
7By "can have no" I assume that @intelfx meant "can have zero or more," or "does not require a," and not "can't have any." However, rewording it for clarity would help future readers. – seh May 01 '18 at 18:17
-
1"Can even have no" would be better wording perhaps – Manchineel Jul 15 '20 at 09:07
From systemd's point of view, Type=simple
is kind of fire and forget. Systemd just forks a process defined in ExecStart=
and goes on its way, even if the process fails to start.

- 19,179
- 10
- 84
- 156

- 2,317
- 1
- 17
- 19
-
26`Type=simple` processes are still monitored by systemd, and will be restarted depending on the value of the `Restart` setting. – ldx.a.ldy.c Feb 01 '18 at 16:51