You are not logged in.

#1 2015-02-09 19:00:54

jernst
Member
From: Silicon Valley
Registered: 2014-03-04
Posts: 290
Website

Dynamic systemd dependencies

Systemd services can be declared to have dependencies. For example, a.service may require b.service, which means that whenever a.service gets started, b.service gets started, too.

Is there a way of making those dependencies more dynamic?

For example, let's say that I'd like a.service to depend on morning.service in the morning, and afternoon.service in the afternoon? Or some other condition, like whether I'm connected via WiFi or ethernet, or whatever.

I've tried to manage this manually, by having the a.service script execute

systemctl start b.service

during its own activation, but systemd ends up in a deadlock if I do that. My next attempt will be to do the same, but as a background process in the hope that this avoids the deadlock.

But is there a better way?

Offline

#2 2015-02-09 20:56:42

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Dynamic systemd dependencies

I think that most of those things don't need a dynamically changing systemd service. They would need the activation of the right services. In my (admittedly limited) understanding of systemd, services are meant to be just that. A service running in the background with control signals coming from different parts of the system. It is meant to make sure that the needed dependencies for the software are solved.

I think that your problem is better solved using timers and something like udev to control which services are run on arbitrary conditions. Maybe targets are also useful in this case.

Offline

Board footer

Powered by FluxBB