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

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

问题描述

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

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天全站免登陆