我有“serviceA”和“serviceB”。“serviceA”每 12 小时运行一次计时器,“serviceB”每 15 分钟运行一次。如果“serviceB”当前正在运行,我想确保“serviceA”永远不会运行,反之亦然。我还想确保如果“serviceA”被触发并且“serviceB”当前正在运行,它不会杀死“serviceB”。
我怎样才能用 systemd 做到这一点?
使用ExecStartPre:
从联机帮助页 ExecStartPre 条目:
如果这些命令中的任何一个(不带“-”前缀)失败,则其余命令不会执行,并且该单元被视为失败。
[Unit]
Description=Service A 12 hours on timer
[Service]
Type=oneshot
# Check and see if serviceB is running
ExecStartPre="! systemctl is-active --quiet serviceB"
Restart=no
...
Run Code Online (Sandbox Code Playgroud)
[Unit]
Description=Service B 15 mins on timer
[Service]
Type=oneshot
# Check and see if serviceA is running
ExecStartPre="! systemctl is-active --quiet serviceA"
Restart=no
...
Run Code Online (Sandbox Code Playgroud)
如果使用该Conflicts指令,则当设置了该指令的服务启动时,指定的一个或多个服务将停止。您提到:
我还想确保“serviceA”在被触发并且“serviceB”当前正在运行时不会杀死“serviceB”。
然而,从联机帮助页来看,这是一种双向关系:
如果一个单元在另一个单元上有 Conflicts= 设置,则启动前者将停止后者,反之亦然。
所以你必须避免冲突指令。
| 归档时间: |
|
| 查看次数: |
107 次 |
| 最近记录: |