mitsuhiko / systemfd

Development helper utility for helping with auto reloading for projects supporting systemd socket activation
Apache License 2.0
468 stars 17 forks source link

Supports graceful updates? #15

Closed johalun closed 1 year ago

johalun commented 2 years ago

Hey! Very interesting project but there are some parts I don't understand. Take

systemfd -s http::5000 -- my-server-executable

for example. Can I use this to do a graceful update of the binary? That is, start a new release of my-server-executable that listens to the same port (with SO_REUSEPORT) and starts taking new requests while the old running binary stops accepting requests and terminates when all current request are completed (given that I have some IPC in place to tell the old binary to stop listening when the new is launched).

Similarly, how is the transition of the listening socket handled with cargo watch? Is it graceful like described above or will there be interruptions in traffic?

mitsuhiko commented 1 year ago

Since listenfd passes through multiple processes you can hook a process monitor in place that restarts. This could just be a bash script for instance that spawns your executable in a loop in the most basic case. Then you just kill your executable and when it respawns the latest version is going to pick up.

cargo watch is not super graceful, i think it just kills the process but I'm not sure.