Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, this is my first attempt to teach Radicale systemd socket activation. Comments are more than welcome.
Context
systemd can open and bind sockets (of various types and not only sockets), wait for an incoming connection and start a service when a connection appears. It is a bit like inetd but with its own protocol that allows passing multiple listening sockets. systemd can give a service a socket either before or after
accept(2)
. This patch assumes Radicale shall receive a listening socket, callaccept(2)
and wait for any later incoming connections.The patch
The protocol for grabbing open sockets is rather simple but I decided to use
listen_fds()
function from thesystemd.daemon
module anyway. The module, however, is not required for Radicale to work the old way, neither on Linux nor on any other systems. BTW launchd on macos has its own socket activation protocol and it should be possible to implement both protocols side-by-side.When Radicale detects open sockets during startup it ignores server.hosts configuration option from the configuration file and uses the passed sockets.
I decided to implement this functionality as a separate class to give a better overview of changes required to implement it. What bugs me a bit is that I had to copy the contents of
server_bind()
from WSGIServer and HTTPServer to avoid binding a socket that has already been bound by systemd. Is there a better way?Future work.
systemd doesn't mind if a service decides to exit and activates it upon next incoming connection. Radicale can exit after some time of inactivity to preserve resources on smaller systems.