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.

  • 1
    You need to be more specific. What should happen if such a service is disabled? – Michael Hampton May 1 '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 1 '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 1 '16 at 23:46
  • :-) What I said: if a dependent service is disabled, starting cfengine3.service should not touch it. – bronto May 2 '16 at 8:12

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).

  • 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, and ditched it because it didn't allow a service to be started by hand. – bronto May 1 '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 1 '16 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.