https://github.com/ralith/sd-listen-fds
Minimal self-contained crate to accept file descriptors from systemd
https://github.com/ralith/sd-listen-fds
Last synced: 10 months ago
JSON representation
Minimal self-contained crate to accept file descriptors from systemd
- Host: GitHub
- URL: https://github.com/ralith/sd-listen-fds
- Owner: Ralith
- License: apache-2.0
- Created: 2023-07-27T07:00:53.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-27T21:25:33.000Z (almost 3 years ago)
- Last Synced: 2025-01-12T06:40:33.878Z (over 1 year ago)
- Language: Rust
- Size: 11.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# sd-listen-fds
[](https://docs.rs/sd-listen-fds/)
[](LICENSE-APACHE)
[](LICENSE-MIT)
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](https://www.freedesktop.org/software/systemd/man/sd_listen_fds.html)
API exposed by the foreign `libsystemd` library. Compared to using
`libsystemd` bindings, this crate is smaller, safer, and builds
everywhere.
### Example
```rust
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](https://www.freedesktop.org/software/systemd/man/systemd.socket.html))
```ini
[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](https://www.freedesktop.org/software/systemd/man/systemd.service.html))
```ini
[Service]
ExecStart=/path/to/my-service
[Unit]
Requires=my-service.socket
Description=My Rust service
Documentation=https://example.com/my-service/
```
## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
### Contribution
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.