jesec / rtorrent

stable, high-performance and low resource consumption BitTorrent client
GNU General Public License v2.0
192 stars 38 forks source link

Feature request: Suport systemd notify #39

Open vamega opened 2 years ago

vamega commented 2 years ago

Would you be open to accepting a patch that lets rtorrent notify systemd when it is ready? This would allow writing of systemd service files that start flood/rutorrent after rtorrent has started up.

The systemd service type would switch to Type=notify.

Assuming you're okay with this, my plan would be the following.

I'm thinking I'll have this behind a configure flag, since the simplest approach would involve calling sd_notify. -DUSE_SYSTEMD seems like the reasonable flag for CMake.

I'm less familiar with Bazel, any pointers to how to support a build option like that with Bazel would be appreciated.

kannibalox commented 2 years ago

Not to say that having it directly in the code wouldn't be useful, but you can already accomplish your goal with the available event bindings and systemd-notify:

# Startup
method.set_key = event.system.startup_done, notify_systemd, "execute=/bin/systemd-notify,--ready,--status,(cat,SESSION=,(session.name)),--pid,(system.pid)"
# Shutdown
method.set_key = event.system.shutdown, notify_systemd, "execute=/bin/systemd-notify,STOPPING=1"
jesec commented 2 years ago

Great idea.

I don't want the binary to link against libsystemd, though. Is there a standalone solution?

vamega commented 2 years ago

@kannibalox thanks I wasn’t aware of that. Should have looked at the configuration options more closely.

@jesec I could probably make this work by opening a Unix datagtam socket and sending the data myself.

Is there a reason you’re opposed to linking against systemd?

jesec commented 2 years ago

Not all systems have systemd or libsystemd. You may find this useful: https://github.com/lnicola/sd-notify.

i knew this project is not in Rust, but you can check out the logic.