简体   繁体   English

系统服务依赖

[英]Systemd services dependency

I am trying to manage three services using systemd. 我正在尝试使用systemd管理三个服务。 The structure of the service is as follows: 服务结构如下:

在此输入图像描述

When A target is started/stopped/enabled, this should be propagated to the other services (A0, A1, A2). 当启动/停止/启用目标时,应将其传播到其他服务(A0,A1,A2)。

However, it should still be possible to start/stop/enable A0-A2 independently from each other and A. 但是,仍然可以相互独立地启动/停止/启用A0-A2和A.

So far A.target looks similar to this: 到目前为止A.target看起来与此类似:

[Unit]
DefaultDependencies=no
Wants=A0.service
Wants=A1.service
Wants=A2.service

[Install]
WantedBy=multi-user.target
Also=A0.service
Also=A1.service
Also=A2.service

A0.service: A0.service:

[Unit]
Requires=some-other.service
After=some-other.service
BindsTo=A.target
DefaultDependencies=no

[Install]
WantedBy=multi-user.target

Starting/stopping works fine, however when I start a single service (eg. A0) all the other services are started as well. 启动/停止工作正常,但是当我启动单个服务(例如A0)时,所有其他服务也会启动。 Why is that and what is a proper way to fix this? 为什么这样,解决这个问题的正确方法是什么?

Seems like the combination between "Wants" within A.target and "BindsTo" within A0.service led to the problem. 似乎A.target中的“Wants”与A0.service中的“BindsTo”之间的组合导致了问题。 Changing "BindsTo" to "PartOf" fixed the problem. 将“BindsTo”更改为“PartOf”可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM