linux - 如果重新启动其依赖服务,如何重新启动服务

标签 linux systemd

一个服务(例如 bar.service)依赖于另一个服务(例如 foo.service),如下所示

酒吧的服务文件:

[Unit]
After=foo.service
Requires=foo.service
...

如果 foo.service 重新启动(手动或由于错误),bar.service 如何自动重新启动?

最佳答案

您可以使用 PartOf

[Unit]
After=foo.service
Requires=foo.service
PartOf=foo.service

来自 systemd.unit 手册页:

PartOf=

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.

关于linux - 如果重新启动其依赖服务,如何重新启动服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36043964/

相关文章:

linux - OpenSuse 13.2 zypper 不工作

systemd - 如何确保systemd中的服务启动之前有延迟?

networking - 在 systemd 中使用 CAP_NET_RAW 运行无人(或动态用户)

c - 如何识别无效的内存地址?

linux - 学习qplot(gnuplot)

linux - 在 Linux 中通过系统调用获取页面属性

mysql - bash 中如何解析另一个命令的输入?我们如何重定向错误并传递输入?

linux - 来自可执行脚本的 systemd 环境变量

c - 检测systemd的可靠方法

linux - 如何将 Systemd 服务标准输出从 ExecStart 传输到 shell,例如。 bash ?