[systemd-devel] Graceful Socket Service Restarts

Evan Klitzke evan at eklitzke.org
Fri Aug 26 18:17:01 UTC 2016


Hi,

I'm writing a network service that I would like systemd to manage. I'm
trying to implement graceful restarts, and I'm interested in using the
sd_listen/sd_notify interface. I have a basic POC but I'm interested
in improving it.

What I want is something like this:
 * systemd sends SIGTERM to old process
 * old process sends the listen socket back to systemd using
sd_notify, but retains file descriptors for client connections
 * systemd starts new process while old process is still running
 * new process gets the listen socket using sd_listen and starts
handling new requests
 * old process continues to try to complete outstanding requests for
client connections before exiting, but systemd will send SIGKILL if it
doesn't complete within N seconds

So what's unusual about this is that for some period of time there
will be two processes for the same service running simultaneously.

I've considered using SO_REUSEPORT but I don't see how to write a
systemd policy that will let me run two instances of the same service
at once in the manner I described.

I also understand that I can avoid having two processes running at
once if I write the code to transfer *all* sockets to systemd and back
using the listen/notify interfaces, but I'm hoping that at least
initially I can avoid doing this so I don't have to try to write a
full client socket state serialization mechanism.

What's the best way to do this?

Thanks,
Evan Klitzke


More information about the systemd-devel mailing list