[systemd-devel] Services with multiple pre-requisites

freedesktop at priatel.co.uk freedesktop at priatel.co.uk
Mon Dec 21 14:43:22 UTC 2020


Hi

I have two "primary" services running on a Linux server with `systemd` that
may be started at approximately the same time, or could just as easily be
started days apart. When started, they take a few seconds to reach "ready"
state, and can signal that readiness however I choose.

I have a third (and fourth, fifth, etc...) service which:
  * must not start before both Service 1 & Service 2 are ready
  * must start as soon as possible once both Service 1 & Service 2 are ready
  * must be stopped as soon as possible if either Service 1 or Service 2
terminates

I've been trying to do this using systemd.targets, but while I can trivially
get Service 3 to start when Service 1 'starts' a target, I've not found how
to get it to depend on both Service 1's target & Service 2's target.

Here's an example of what I've tried:

```
[Unit]
Description=Service 3
PartOf=Service1.target Service2.target
After=Service1.target Service2.target

[Service]
ExecStart=<<start service 3>>

[Install]
WantedBy=Service1.target Service2.target
```

Then Service 1 & Service 2 would trigger `systemctl start
Service[12].target` when they reach readiness, and `systemctl stop
Service[12].target` when they terminate.

However, Service 3 starts as soon as either Service1.target or
Service2.target occurs. What I need is for Service 3 to start when both
Service1.target and Service2.target have occurred. (It terminates correctly,
though.)

Am I missing something obvious?

Thanks

Martin



More information about the systemd-devel mailing list