[systemd-devel] Why systemd keeps references on passed sockets ?

Lennart Poettering lennart at poettering.net
Mon Sep 7 14:38:52 UTC 2020


On So, 06.09.20 22:23, Francis Moreau (francis.moro at gmail.com) wrote:

> > It's how socket activation works really (at least with Accept=no): pid
> > 1 allocate the socket and activates your service every time something
> > happens on it, except if your service is already running. Thus a
> > service can auto-start, process one or more events on it, can exit
> > when idle, or even crash, it doesn't matter, no traffic is lost
> > (except the very datagram it was processing or the connection that it
> > was handling when it crashed), and as soon as POLLIN is seen on the
> > socket again the service is started again can continue where it left
> > off.
> >
> > You are apparently looking for a different model? i.e. where automatic
> > restart and exit-on-idle do not exist? A model like that is currently
> > not implemented. Can you elaborate on the usecase?
> >
>
> My service is listening several sockets (which are all pased by
> systemd) but depending on user configuration my service may not need
> to use all sockets and in this case it would be great if the sockets
> not needed stop receiving messages and theirs resources are
> released.

Hmm, I see.

>  I tried to close the socket but nothing seems to happen.
>
> Couldn't systemd react on the socket close and if the service still
> runs then it closes the socket until it detects the service is stopped
> ?

"React on the socket close?" — What do you mean by that?

Note that on Linux you can invoke shutdown() on a listening socket
(i.e. not just on the connection socket, but on a listening
socket). iirc in that case systemd actually notices and will put the
.socket unit in failure mode...

Would that work for you? (Maybe we could even tweak this a bit in
systemd, so that when you invoke shutdown() on the socket systemd
holds for you we do not consider that a failure anymore, but a clean
way to tell systemd to stop the socket).

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list