cloudflare / shellflip

Graceful process restarts in Rust
https://blog.cloudflare.com/oxy-the-journey-of-graceful-restarts/
BSD 3-Clause "New" or "Revised" License
250 stars 7 forks source link

How to actually use this in a systemd setup? #4

Open curvature opened 1 month ago

curvature commented 1 month ago

The example in the repo shows how to gracefully restart a standalone executable. In the case of systemd managed services, how can one make the spawned child process to be managed by systemd? The child process creation is encapsulated in the library(the Command::spawn call) and as far as I know this kind of child processes are not directly managed by systemd, meaning when the parent process eventually exits, the systemd will think the service is down and try to restart it, disregarding the child process.

Not a Linux expert myself but I do want to use this in my Rust project. Any help is greatly appreciated.

cbranch commented 1 month ago

systemd will think the service is down and try to restart it

In our experience, systemd will manage a forked process as the main PID once the previous main process terminates. What unit settings are you using where you observe this behaviour?

curvature commented 1 month ago

systemd will think the service is down and try to restart it

In our experience, systemd will manage a forked process as the main PID once the previous main process terminates. What unit settings are you using where you observe this behaviour?

Initially I observed this behavior on Debian 12 with a usual service unit, later I learned from tableflip that I need to add a line PIDFile=/path/to/pid-file to the service section. It then worked for my golang project with tableflip. I'm still adapting my Rust project for shellfilp, in the meantime I found out that shellflip is sending notifications on the Unix socket with path reading from env var NOTIFY_SOCKET. Does this mean I should setup the service unit with type notify? I previously always use simple type(for tableflip as well), which might be the reason the issue arises in the first place?

Thanks for your help.