[systemd-devel] Using Systemd "FD Store" facilitiy
Lennart Poettering
lennart at poettering.net
Tue Jan 12 06:32:45 PST 2016
On Tue, 12.01.16 01:50, Pathangi Janardhanan (path.jana at gmail.com) wrote:
> Hi,
>
> I had previously sent a mail on this but got no response, so wanted to
> check again.
>
> I am trying to use systemd as a way to store and restore the FDs used by a
> service, so that the service can provide continuation of service during an
> upgrade. for the purpose of trying it out, I am using a simple TCP echo
> server as my service
>
> The issues I see are :
>
> 1. I store the fds using sd_pid_notify_with_fds, and then do a systemctl
> restart of the service. Then I use sd_listen_fds and get all the fds back
> and the service continues without disturbance. But the problem is
>
> a. systemd continues to hold all these fds, so now if my service is done
> with the fd and closes the connection, this is not getting through to the
> client, as systemd continues to have this fd
systemd watches for POLLHUP/POLLERR on the fds, hence should normally
detect disconnected sockets automatically. This means that connections
made by remote peers do not require any work, but if you close
connections locally, then you have to add an explicit shutdown(), so
that the the POLLHUP is triggered and systemd notices.
> b. Even if the client closes the connection, my service gets it and closes
> the connection but systemd still holds on to this fd.
>
> so in essence once I store the fd with systemd using
> sd_pid_notify_with_fds, they do not go away untill I do a systemctl stop of
> my service
>
> This is making it difficult to use this service in the intended way. It
> would be nice
> if on sd_listen_fds, the sytemd passes all fds back to the service and
> internally cleared its state, so that only the service has the fds. (this
> is ofcourse only for
> those fds that the service had previously send in sd_pid_notify_with_fds,
> the other fds that the service gets as part of socket activation would
> continue to be held in systemd also.)
>
> Let me know if this sounds correct, or am I mis-understanding the way this
> service is to be used.
I figure adding an API that explicitly allows removing fds from
systemd's FD store would make sense. i.e. maybe something like an
FDSTORE_REMOVE=1 msg that takes the same fds again, and then compares
the fds with same_fd() and if they match closes both the newly passed
in fd and the stored one...
But that said, I think using shutdown() as suggested above is probably
the better and easier fix for your case.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list