Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mitsuhiko/listenfd
Helper crate to work with systemd/catflap socket activation
https://github.com/mitsuhiko/listenfd
Last synced: 1 day ago
JSON representation
Helper crate to work with systemd/catflap socket activation
- Host: GitHub
- URL: https://github.com/mitsuhiko/listenfd
- Owner: mitsuhiko
- License: apache-2.0
- Created: 2018-05-17T00:35:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-31T13:28:53.000Z (12 months ago)
- Last Synced: 2025-01-09T13:29:50.827Z (9 days ago)
- Language: Rust
- Size: 38.1 KB
- Stars: 172
- Watchers: 6
- Forks: 14
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# listenfd
[![Build Status](https://github.com/mitsuhiko/listenfd/workflows/Tests/badge.svg?branch=master)](https://github.com/mitsuhiko/listenfd/actions?query=workflow%3ATests)
[![Crates.io](https://img.shields.io/crates/d/listenfd.svg)](https://crates.io/crates/listenfd)
[![License](https://img.shields.io/github/license/mitsuhiko/listenfd)](https://github.com/mitsuhiko/listenfd/blob/master/LICENSE)
[![rustc 1.42.0](https://img.shields.io/badge/rust-1.42%2B-orange.svg)](https://img.shields.io/badge/rust-1.42%2B-orange.svg)
[![Documentation](https://docs.rs/listenfd/badge.svg)](https://docs.rs/listenfd)listenfd is a crate that provides support for working with externally managed
and passed file descriptors. This lets you work with systems that support
socket activation or similar.Currently this supports systemd (including systemd-socket-activate) on Unix and
[systemfd](https://github.com/mitsuhiko/systemfd) on Unix and Windows.
systemfd is very convenient in combination with cargo-watch for development
purposes whereas systemd is useful for production deployments on linux.## Example
```rust
use listenfd::ListenFd;let mut listenfd = ListenFd::from_env();
let mut server = make_a_server();// if we are given a tcp listener on listen fd 0, we use that one
server = if let Some(listener) = listenfd.take_tcp_listener(0)? {
server.listen(listener)
// otherwise fall back to local listening
} else {
server.bind("127.0.0.1:3000")?
};
```You can then use this with cargo watch and systemfd:
```
$ cargo install systemfd cargo-watch
systemfd --no-pid -s http::3000 -- cargo watch -x run
```Now systemfd will open the socket and keep it open. cargo watch will recompile
the code on demand and the server will pick up the socket that systemfd opened.
No more connection resets.## License and Links
- [Documentation](https://docs.rs/listenfd/)
- [Issue Tracker](https://github.com/mitsuhiko/listenfd/issues)
- [Examples](https://github.com/mitsuhiko/listenfd/tree/main/examples)
- License: [Apache-2.0](https://github.com/mitsuhiko/listenfd/blob/main/LICENSE)