如果重新启动依赖服务,如何重新启动服务 [英] How to restart a service if its dependent service is restarted

查看:237
本文介绍了如果重新启动依赖服务,如何重新启动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个服务(例如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手册页中:

PartOf =

PartOf=

配置与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.

这篇关于如果重新启动依赖服务,如何重新启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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