What is the difference between Systemd Service Type oneshot and simple

倾然丶 夕夏残阳落幕 提交于 2019-12-03 04:13:48

问题


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.


回答1:


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 have ExecStop= (useful together with RemainAfterExit=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 with KillMode=none, but only do this if you know what you are doing).



回答2:


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.



来源:https://stackoverflow.com/questions/39032100/what-is-the-difference-between-systemd-service-type-oneshot-and-simple

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!