[systemd-devel] Unit that depends on A or B

Mathijs Kwik mathijs at bluescreen303.nl
Thu Jun 2 14:14:59 UTC 2016


Hi all,

On my system, I can setup 2 VPN connections, which are mutually 
exclusive as they reach the same subnet for the most part.
Let's call these A and B. A is faster than B, but B gives access to some 
extra subnets.

Now, I have a unit(some-dht.service) that needs a VPN connection but 
does not really care which one.
Another unit (super-secret.service) really needs VPN B.

What I would like is the following:
If no VPN is up, starting some-dht.service should start VPN A (as it's 
the fastest).
But if B is already up, starting some-dht.service should not try to 
switch to VPN A, as that brings down B and super-secret.service with it.
Of course if A or B stops, some-dht.service and super-secret.service 
should both stop as well.

Having 2 copies of some-dht (some-dht-at-A.service, 
some-dht-at-B.service) is a no-go, as that would bubble up into my 
top-level targets and scale badly when I need another choice-construct 
like this.
(at-work-with-vpn-A-and-soundcard-X.target)
(at-work-with-vpn-A-and-soundcard-Y.target)
(at-work-with-vpn-B-and-soundcard-X.target)
(at-work-with-vpn-B-and-soundcard-Y.target)

Not mentioning the requirement (on A or B) to systemd and resorting to 
some script that decides which units to bring up does not sound like a 
solution either.

Can I achieve this in some way?

regards,
Mathijs



More information about the systemd-devel mailing list