#socket #systemd #socketactivation #listenfd

listenfd

A simple library to work with listenfds passed from the outside (systemd/catflap socket activation)

6 releases

Uses old Rust 2015

0.3.3 May 20, 2018
0.3.2 May 20, 2018
0.2.0 May 17, 2018
0.1.1 May 17, 2018

#15 in #systemd

Download history 4172/week @ 2020-11-07 4921/week @ 2020-11-14 3410/week @ 2020-11-21 4115/week @ 2020-11-28 3312/week @ 2020-12-05 3747/week @ 2020-12-12 2611/week @ 2020-12-19 2896/week @ 2020-12-26 4913/week @ 2021-01-02 4374/week @ 2021-01-09 3759/week @ 2021-01-16 4145/week @ 2021-01-23 3678/week @ 2021-01-30 3733/week @ 2021-02-06 3787/week @ 2021-02-13 3444/week @ 2021-02-20

22,363 downloads per month
Used in 17 crates (16 directly)

MIT/Apache

15KB
244 lines

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 and catflap on unix only. catflap is very convenient in combination with cargo-watch for development purposes whereas systemd is useful for production deployments on linux.

Example

extern crate listenfd;
use listenfd::ListenFdManager;

let mut manager = ListenFdManager::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) = manager.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 -p 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.

Dependencies

~71KB