-
Notifications
You must be signed in to change notification settings - Fork 130
[WIP] Systemd socket activation #505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
crates/rqbit/src/main.rs
Outdated
|
|
||
| // 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))) } |
There was a problem hiding this comment.
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}"); |
There was a problem hiding this comment.
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.
crates/rqbit/src/main.rs
Outdated
| Some(log_config.rust_log_reload_tx), | ||
| Some(log_config.line_broadcast), | ||
| ); | ||
| let systemd_listener = systemd_socket_activation().unwrap_or_else(|e| { |
There was a problem hiding this comment.
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= | |||
There was a problem hiding this comment.
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] | |||
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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?
ikatson
left a comment
There was a problem hiding this 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
This will make it possible to implement systemd socket activation in rqbit [1]. [1] ikatson/rqbit#505
16338b9 to
0771a2b
Compare
|
The PR to librqbit-dualstack-sockets is up: ikatson/librqbit-dualstack-sockets#3 |
|
I've tested this locally against ikatson/librqbit-dualstack-sockets#3 and it works. |
0771a2b to
4bbe826
Compare
This will make it possible to implement systemd socket activation in rqbit [1]. [1] ikatson/rqbit#505
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
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"
TcpListenerfrom a file descriptor (requiring changes to https://github.com/ikatson/librqbit-dualstack-sockets).The unit files (in the new
systemddirectory) 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).