systemd 的“oneshot"和“simple"服务类型有什么区别? [英] What is the difference between systemd's 'oneshot' and 'simple' service types?

查看:53
本文介绍了systemd 的“oneshot"和“simple"服务类型有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

systemd 服务 Type oneshotsimple 有什么区别?这个链接 声明使用 simple 而不是 oneshot 作为计时器.我无法正确理解.

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.

推荐答案

Type=oneshot 服务单元:

  • 在启动操作上阻塞,直到第一个进程退出,其状态将报告为正在激活";

  • blocks on a start operation until the first process exits, and its state will be reported as "activating";

一旦第一个进程退出,就会从激活"直接转换为非活动",除非设置了 RemainAfterExit=true(在这种情况下,它在没有进程的情况下变为活动"!);

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!);

可能有任意数量(0个或更多)的ExecStart=指令,它们将按顺序执行(等待每个启动的进程退出,然后再启动下一个);

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= 但有 ExecStop=(与 RemainAfterExit=true 一起用于安排事情在系统上运行关机).

may leave out ExecStart= but have ExecStop= (useful together with RemainAfterExit=true for arranging things to run on system shutdown).

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!);

一旦第一个进程退出,就会从活动"转换为非活动"(没有 RemainAfterExit= 选项);

once the first process exits, transitions from "active" to "inactive" (there is no RemainAfterExit= option);

通常不鼓励使用,因为无法区分由于配置错误而在启动时退出"和运行时 500 毫秒后崩溃"等情况.

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.

Type=oneshotType=simple 单位:

  • 忽略第一个进程的任何子进程,因此不要将这些模式用于分叉进程(注意:您可以将 Type=oneshotKillMode=none但只有在您知道自己在做什么的情况下才能这样做).
  • 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).

这篇关于systemd 的“oneshot"和“simple"服务类型有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆