Crates.io | sd-listen-fds |
lib.rs | sd-listen-fds |
version | 0.2.0 |
source | src |
created_at | 2023-07-31 19:50:01.846628 |
updated_at | 2023-08-27 21:25:39.508322 |
description | Minimal, pure-rust helper to accept file descriptors from systemd |
homepage | |
repository | https://github.com/Ralith/sd-listen-fds |
max_upload_size | |
id | 931176 |
size | 20,693 |
Exposes file descriptors passed in by systemd, the Linux init daemon, without dependencies, foreign or otherwise. Enables easy implementation of socket-activated services in pure Rust.
Unlike services that open sockets themselves, socket-activated
services are started on-demand, may start up concurrently with their
dependencies, and may be restarted without losing inbound
data. Portable applications can call sd_listen_fds::get()
and open
their own socket if it succeeds with an empty Vec
.
See also the
sd_listen_fds
API exposed by the foreign libsystemd
library. Compared to using
libsystemd
bindings, this crate is smaller, safer, and builds
everywhere.
let fds = sd_listen_fds::get().unwrap();
let (_name, fd) = fds
.into_iter()
.next()
.expect("must be launched as a systemd socket-activated service");
let socket = TcpListener::from(fd);
my-service.socket (see also systemd.socket)
[Socket]
# TCP port number. Other types of sockets are also possible.
ListenStream=1234
[Install]
WantedBy=sockets.target
[Unit]
Description=My Rust service
Documentation=https://example.com/my-service/
my-service.service (see also systemd.service)
[Service]
ExecStart=/path/to/my-service
[Unit]
Requires=my-service.socket
Description=My Rust service
Documentation=https://example.com/my-service/
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.