创建新的 systemd 服务时,何时需要将 RemainAfterExit 选项设置为 true? [英] When should the option RemainAfterExit needs to be set true when creating new systemd services?

查看:40
本文介绍了创建新的 systemd 服务时,何时需要将 RemainAfterExit 选项设置为 true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一些服务.其中一些将类型"选项设置为 oneshot.但是当需要将RemainAfterExit"选项设置为真时,我仍然感到困惑.(不仅是该服务在退出后也需要处于活动状态).

I am trying to write a few services. Some of them have 'type' option set to oneshot. But i am still confused when the option 'RemainAfterExit' needs to be set true. (not just that service needs to be active even after exiting).

推荐答案

对服务使用 RemainAfterExit=yes,这会以某种方式改变系统的状态.当您希望恢复该状态时,您只需停止服务即可.然后您可以重新启动它,但必须先停止它.一个示例是在文件系统中创建一个标志以供其他应用程序使用的服务.启动时,它创建标志文件,然后存在,但该服务由 systemd 保持活动状态.然后你可以停止它,它会删除标志文件.

Use RemainAfterExit=yes for services, which somehow change state of the system. When you want that state reverted, you just stop the service. Then you can start it again, but not without first stopping it. An example would be service which creates a flag in filesystem to be used by some other application. On start, it create the flag file, then exists, but the service is kept as active by systemd. Then you can stop it and it will remove the flag file.

对服务使用 RemainAfterExit=no,这些服务会执行一些操作,但不会更改系统的状态.一个例子是清理 /tmp 的服务.您启动它,它会完成它的工作,然后处于非活动状态(无需停止它).而且您可以随时重新启动它,并将再次对其工作(清理).

Use RemainAfterExit=no for services, which do some action, but do not change the state of the system. An example would be a service to cleanup /tmp. You start it, it will do its work and then be inactive (no need to stop it). And you can start it again anytime and will again to its work (cleanup).

这篇关于创建新的 systemd 服务时,何时需要将 RemainAfterExit 选项设置为 true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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