Skip to content

Conversation

@Stebalien
Copy link

I'm submitting this early for feedback in case you aren't interested in maintaining/accepting this feature.

This PR implements systemd socket activation support (WIP). It makes it possible to auto-start rqbit (via systemd) when the user opens the webui, connects to the API, etc.

Implementation wise, this patch simply checks if the process has been passed a file descriptor by systemd and, if so, it uses that file descriptor as the API socket instead of opening a new one. This change doesn't add any new dependencies.

The main remaining TODO item is to implement a way to create a "dual stack" TcpListener from a file descriptor (requiring changes to https://github.com/ikatson/librqbit-dualstack-sockets).

The unit files (in the new systemd directory) are provided for documentation purposes and will likely need to be modified by the end-user (I'll add a README to the systemd directory later).


// TODO: Needs support from the dual-stack socket library.
// TODO: Consider checking if this is actually a TCP listener?
unsafe { Ok(Some(TcpListener::from_raw_fd(3))) }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FromRawFd trait isn't implemented here yet.

Some(log_config.line_broadcast),
);
let systemd_listener = systemd_socket_activation().unwrap_or_else(|e| {
error!("systemd socket-activation failed: {e}");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm preferring to log and move on rather than fail, but I'm happy to fail instead.

Some(log_config.rust_log_reload_tx),
Some(log_config.line_broadcast),
);
let systemd_listener = systemd_socket_activation().unwrap_or_else(|e| {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to pass the socket into start_http_api instead, that'll just require a little more refactoring.

@@ -0,0 +1,36 @@
#RQBIT_LOG_LEVEL_CONSOLE=
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a listing of all supported environment variables. It doesn't need to exist, it's just a nice way to let the user know what they can configure (I'll need to add documentation/defaults, this is just a first pass).

@@ -0,0 +1,8 @@
[Unit]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unit isn't actually related to socket activation. Instead, it activates rqbit when a file is added to the downloads directory.


[Service]
EnvironmentFile=-%E/rqbit/rqbit.conf
ExecStart=rqbit server start "${XDG_DOWNLOAD_DIR}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace XDG_DOWNLOAD_DIR with RQBIT_DOWNLOADS_DIRECTORY, requiring it to be set in rqbit.conf?

Copy link
Owner

@ikatson ikatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, it certainly sounds useful so please go ahead and submit one this is ready

Stebalien added a commit to Stebalien/librqbit-dualstack-sockets that referenced this pull request Nov 3, 2025
This will make it possible to implement systemd socket activation in
rqbit [1].

[1] ikatson/rqbit#505
@Stebalien Stebalien force-pushed the steb/systemd-socket-activation branch from 16338b9 to 0771a2b Compare November 3, 2025 21:17
@Stebalien
Copy link
Author

The PR to librqbit-dualstack-sockets is up: ikatson/librqbit-dualstack-sockets#3

@Stebalien
Copy link
Author

I've tested this locally against ikatson/librqbit-dualstack-sockets#3 and it works.

@Stebalien Stebalien force-pushed the steb/systemd-socket-activation branch from 0771a2b to 4bbe826 Compare November 3, 2025 23:51
Stebalien added a commit to Stebalien/librqbit-dualstack-sockets that referenced this pull request Nov 4, 2025
This will make it possible to implement systemd socket activation in
rqbit [1].

[1] ikatson/rqbit#505
Stebalien added a commit to Stebalien/librqbit-dualstack-sockets that referenced this pull request Nov 22, 2025
This will make it possible to implement systemd socket activation in
rqbit [1]. This is restricted to Linux because MacOS is missing some
getsockopt features needed by `Socket::protocol` and
`Socket::is_listener`.

[1] ikatson/rqbit#505
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants