1

I am trying to understand if there is a way to create a soft dependency between systemd services. Basically, I'd like to create an "umbrella" service that starts other services marked as (soft-) dependencies, but if and only if they are enabled -- the umbrella should never start a dependant service that is disabled.

More specifically, I have received a pull request for cfengine-systemd that aims to create such an umbrella unit. Unfortunately, the proposed cfengine3.service unit doesn't honour the enabled/disabled state of the dependant units and starts them in any case.

I had tried myself to do the same previously by means of a target unit, but failed shamefully.

Any clues?

Thanks in advance

Update following Michael's question: I would say that if cfengine3.service is disabled, systemd should not try to start the dependant services.

bronto
  • 121
  • 11
  • 1
    You need to be more specific. What should happen if such a service is disabled? – Michael Hampton May 01 '16 at 15:48
  • That's a very good question! I didn't think about that specifically and I don't know if the author of the PR did either. I would say that if the `cfengine3.service` is disabled, systemd should not try to start the dependant services either. – bronto May 01 '16 at 16:02
  • Actually I meant the reverse: What should happen if one of the dependent services is disabled, and you try to start cfengine3.service? – Michael Hampton May 01 '16 at 23:46
  • :-) What I said: if a dependent service is disabled, starting `cfengine3.service` should not touch it. – bronto May 02 '16 at 08:12

1 Answers1

1

Enabled/disabled states control if services are started/not started at boot. In this context I would suggest that the dependent services should stay disabled, and only the state of the umbrella service should be changed. To make umbrella service to start only some of the dependencies, they should be soft-linked into .requires directory of the umbrella service (for example into /etc/systemd/system/umbrella-unit.service/requires directory).

Ektich
  • 81
  • 4
  • Replying point by point: 1) assuming that such an "umbrella unit" can exist, IMO it should never try to start a sub-unit that is disabled; 2) I know how enable/disable and start/stop work, in particular I know that a disabled service can still be started manually. If the dependant services should stay disabled, then I can't really make sense of having them as separate units; 3) [I used the masking approach, too](https://github.com/brontolinux/cfengine-systemd/blob/522ff9f95d13e953b3367568163bd2c7abb7405d/README.md), and ditched it because it didn't allow a service to be started by hand. – bronto May 01 '16 at 19:43
  • While I admit to just getting up to speed on `systemd`, my reading is that a disabled unit will "no longer be activated on boot, by socket or bus activation or by hardware plug (or any other trigger that applies to it)," while manual activation is still allowed. Subtle, but I think `systemd` aims to not be "tied" to such "timeline" things as boot, network up, etc. – Colt May 01 '16 at 23:53