On Wed, May 6, 2026 at 1:38 PM sebastian hjorth <[email protected]> wrote: > > Hi all, > I've stumbled upon something with systemd that I don't quite understand. > I'm trying to have service-A start when foo.target starts. Service-A pulls in > service-B as well. That works well but I want service-B to stop with > service-A, without setting PartOf or BindsTo for service-B. > > Service-A uses BindTo foo.target and stops along with it. I'm trying to have > service-B stop along with service-A using PropagatesStopTo=. My expectation > is that it would cause service-B to stop when service-A is stopped, but that > does not seem to be the case. Stopping foo.target stops service-A but > service-B keeps running. I'm purposely not using BindTo from service-B > because I want the service to be able to run independently in some cases..
PropagatesStopTo does exactly what it says - it propagates Stop requests. When a unit is stopped due to BindsTo, there is no Stop request, so there is nothing to propagate. > > Here's a working example of what I am trying to explain: > > #!/bin/bash > > cat > /etc/systemd/system/foo.target <<END > [Unit] > Description=Target > END > > cat > /etc/systemd/system/service-A.service <<END > [Unit] > Description=Service A > Wants=service-B.service > BindsTo=foo.target > PropagatesStopTo=service-B.service > > [Install] > WantedBy=foo.target > [Service] > Type=oneshot > RemainAfterExit=yes > ExecStart=/bin/true > END > > cat > /etc/systemd/system/service-B.service <<END > [Unit] > Description=Service A > [Service] > # Any service that "hangs" will do. I just want to test that systemd will > stop the process. > ExecStart=nc -l 9000 > END > > systemctl stop service-A.service service-B.service foo.target > systemctl daemon-reload > systemctl enable service-A > > systemctl start foo.target > # Service B is now running > echo "service-B: " $(systemctl is-active service-B) > systemctl stop foo.target > # service-A is now stopped > echo "service-A: " $(systemctl is-active service-A) > # Expected the same for service-B because of StopPropagatesFrom but its still > running > echo "service-B: " $(systemctl is-active service-B) > > > Have I misunderstood the use of PropagatesStopTo? You misunderstood the use of BindsTo (which is not surprising). > Can I achieve my goal some other way? > Use PropagateStopTo=A.service in foo.target instead of BindsTo=foo.target in A.service. Targets cannot unexpectedly fail, so BindsTo makes little sense.
