问题描述
一个服务(例如bar.service)依赖于另一个服务(例如foo.service),如下所示
A service (say bar.service) is dependent on another service (say foo.service), like below
酒吧的服务文件:
[Unit]
After=foo.service
Requires=foo.service
...
如果foo.service重新启动(无论是手动还是由于错误),bar.service也如何自动重新启动?
If foo.service is restarted (either manually or due to a bug), how can bar.service be automatically restarted as well?
推荐答案
您可以使用PartOf
.
[Unit]
After=foo.service
Requires=foo.service
PartOf=foo.service
在systemd.unit
手册页中:
配置与Requires =类似的依赖关系,但仅限于停止和重新启动单元.当systemd停止或重新启动此处列出的单元时,操作将传播到该单元.请注意,这是一种单向依赖性,对此单位的更改不会影响列出的单位.
Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.
这篇关于如果重新启动依赖服务,如何重新启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!