How to stop unneeded services?

Lennart Poettering mzerqung at
Fri Nov 21 20:40:41 UTC 2014

On Fri, 21.11.14 13:52, Peter Lemenkov (lemenkov at wrote:

> Hello All!
> Perhaps a silly question but I'm stuck and need your help, my fellow fedorians.
> I've got a service foo.service which Requires=bar.socket (which in
> turn runs bar.service). So if I start foo.service then systemd opens
> bar.socket, captures first packet and runs bar.service (which isn't
> intended to be started manually btw). So far everything works as
> expected.
> I was asked if it's possible to automatically stop bar.service (and
> bar.socket) if no services which requires these two are active. I
> played with StopWhenUnneeded +
> BindsTo but without much success.
> I believe this sounds like a generic pattern so perhaps someone
> already implemented it. Could somebody point me on working example?
> Any other help would be greatly appreciated.

This concept we usually refer to as "exit-on-idle". 

It is impossible to detect from the outside if a daemon is fully idle
though (example: some client connects to a daemon, passes it some
request, then disconnects. daemon then processes the request
eventually calling the client back when it is ready. there's no way
from the outside to see if the daemon is still processing the request,
or is just idly hanging around), hence a scheme like this cannot be
implemented from the outside, it needs to be implemented by the daemon
in question itself.

For networked services a logic like this is relatively easy to
implement: if a daemon figures out that it has nothing to process
anymore, it can simply exit(), and that's it.


Lennart Poettering, Red Hat

More information about the devel mailing list