Expand description
Systemd socket activation for HTTP listeners
Provides transparent socket activation support - if systemd passes a
pre-bound socket via LISTEN_FDS, we use it; otherwise we bind normally.
§How Socket Activation Works
- Systemd creates and binds the socket before starting the service
- Systemd sets
LISTEN_FDS=1andLISTEN_PID=<pid>environment variables - The service receives the socket as file descriptor 3 (SD_LISTEN_FDS_START)
- The service uses the pre-bound socket instead of binding itself
§Benefits
- Zero-downtime restarts (systemd holds the socket during restart)
- Faster startup (socket already bound)
- Privilege separation (systemd can bind privileged ports)
§Usage
ⓘ
use hyprstream_core::systemd::socket::get_listener;
// Get listener - uses systemd socket if available, otherwise binds normally
let listener = get_listener("0.0.0.0:3000").await?;
// Use with axum
axum::serve(listener, app).await?;§Systemd Configuration
# hyprstream.socket
[Socket]
ListenStream=0.0.0.0:3000
ReusePort=yes
[Install]
WantedBy=sockets.targetFunctions§
- get_
all_ tcp_ listeners - Get all TCP listeners passed by systemd
- get_
listener - Get a TCP listener, using systemd socket activation if available
- get_
listener_ addr - Get a TCP listener for a specific socket address
- has_
socket - Check if running with systemd socket activation
- listen_
fd_ count - Get the number of file descriptors passed by systemd