gpt4 book ai didi

linux - systemd 中单元组的复杂重启

转载 作者:太空宇宙 更新时间:2023-11-04 10:20:21 25 4
gpt4 key购买 nike

我的应用由 haproxy 单元和 5 个应用单元(app@1、app@2 等)组成。

我有一个用于重启的 bash 脚本

systemctl reload hapoxy
echo "disable server myapp/app-1" | socat stdio /var/run/haproxy-admin
systemctl restart 'app@1'
echo "enable server myapp/app-1" | socat stdio /var/run/haproxy-admin
echo "disable server myapp/app-2" | socat stdio /var/run/haproxy-admin
systemctl restart 'app@2'
echo "enable server myapp/app-2" | socat stdio /var/run/haproxy-admin
...
cache warm-up
other stuff

但我想知道,有没有办法通过 systemd 运行重启?

附言我将 myapp.target 与这些单元和 haproxy 作为依赖项,但目标文件没有重启命令。

最佳答案

您可以使用 PartOf=。来自 man 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.

所以你可以创建一个新的单元文件,然后让所有你想重新启动的东西一起“PartOf=”这个新单元。然后重新启动新单元将重新启动您想要的一切。

此主题在 How to create a virtual systemd service to stop/start several instances together? 中有更多讨论。

关于linux - systemd 中单元组的复杂重启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44152774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com