Is it possible to specify a systemd dependency on any one of multiple units?
Currently, I have a unit Z that depends on at least one of unit A or unit B.
Configuring unit A to be
WantedBy unit Z and unit B to be
WantedBy unit Z mostly works.
However, if only one of units A or B is able to start, the boot process waits for the other unit to timeout before starting unit Z. I want to eliminate this timeout.
Units A and B require a timeout in order to function properly, however, once once of them has started, there is no need to wait for the other unit to timeout before starting unit Z.
Is there a way to specify that unit Z depends on either unit A or unit B, but does not need to wait for both unit A and unit B before starting unit Z?
In the Debian world, the packaging system uses
Provides to specify something similar to what I'm hoping to accomplish here.
What I'm Trying To Accomplish
Debian used to support a
keyscript option in
crypttab but did not reimplement that option when upstream rewrote the startup scripts for the move to
systemd. Previously, I used a
keyscript to read my key from a USB drive. Currently, I am using a
systemd unit file to take the place of the
keyscript option (unit A). That works perfectly. However, USB drives are prone to failure, so for redundancy, I want to carry a second copy of my key on a second USB drive. And I want to add a second
systemd unit file for that second USB drive (unit B), so that whichever USB drive is inserted,
systemd is able to use that USB drive and continue without a timeout.
Other Things I've Tried
Conflicts to specify that A conflicts with B, and B conflicts with A. Unfortunately, systemd processes the conflict before attempting to start either of units A or B, and removes one of these units from the scheduler before trying to start the remaining unit. So Z sometimes fails, for example, if A fails, but B would have succeeded, if B was already eliminated from consideration due to the conflict with A.
JobTimeoutSec to shorten the timeout. Unfortunately, this can result in Z failing, if A and B timeout.
Michael Hampton's suggestions. As he mentions, the NTP example creates a weak dependency between each client and the target. Each NTP client wants the target, but the target does not depend on each of the NTP clients, so this works. However, as best I can tell, a weak dependency does not pull in the unit unless the unit also has an
[Install] section specifying an additional dependency. So when I pull in my units A and B, the
WantedBy in the
[Install] section creates the blocking timeout. If I remove the
[Install] section, units A and B are ignored.