What is the difference between Systemd Service Type oneshot and simple
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKPz5qhCkKGdpPJ0wkSm5JqlliSJoZg92-H4DuCruovhkVFuXerCphZt9wys_Gr3uwQyXObMHDwattjG5BSeCEl_LdDq1GPLct8qYyRyX4fZ9C93oW-TX7IGZLYDwqRgfFCXA4aUxkBAcS/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6VebLk98DYwS3K2nWZSCatab-q4HrSuRk91M4fQA8SHrKU_-x-lq1n780pSU_bIVLqMRv6pc3dhhh-Y2PUwBS9mM0BxvY1eM6XsM-e7Diu4z-wAoeDG0vB3-2_1U9RE8sO0lg4PHiIXbI/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
What is the difference between Systemd Service Type oneshot and simple
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.
systemd
Type
oneshot
simple
simple
oneshot
2 Answers
2
The Type=oneshot
service unit:
Type=oneshot
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!);
RemainAfterExit=true
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);
ExecStart=
may leave out ExecStart=
but have ExecStop=
(useful together with RemainAfterExit=true
for arranging things to run on system shutdown).
ExecStart=
ExecStop=
RemainAfterExit=true
The Type=simple
service unit:
Type=simple
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);
RemainAfterExit=
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:
Type=oneshot
Type=simple
Type=oneshot
KillMode=none
Type=oneshot
ExecStart=
oneshot
ExecStart=
systemd.service
@rlandster: Why is this "not true"? systemd.service(5) 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 1:22
ExecStart=
agree that "can have no" is confusing. that is not true. but i think you can't have
ExecReload
– Tony
Apr 2 at 1:43
ExecReload
By "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 1 at 18:17
@rlandster alright, reworded for clarity
– intelfx
May 2 at 19:13
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.
Type=simple
ExecStart=
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 1 at 16:51
Type=simple
Restart
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
intelfx says that the
Type=oneshot
service unit "can have noExecStart=
". This is not true. In fact, services of typeoneshot
can have multipleExecStart=
directives. See any recent man page forsystemd.service
for more information.– rlandster
Oct 22 '17 at 1:09