Broadcast Fixes // StreamRelay Lab
Hardening mediamtx.service with LimitNOFILE=1048576
Running MediaMTX via a hardened systemd unit guarantees clean /dev/shm directory creation, 1M+ open socket capacity, and instant restarts without Docker NAT overhead.
Measured MediaMTX & FFmpeg Telemetry
Native systemd execution avoids Docker userland proxy packet overhead on UDP :8189/:8890 and exposes exact process RSS and CPU metrics cleanly to journalctl.
| Subsystem / Signal | Measured Target | Operational Impact |
|---|---|---|
| Open File Limit | LimitNOFILE=1048576 | Handles 3,000+ viewers + TLS proxies |
| Restart Policy | Restart=always (2s) | Zero manual intervention on transient errors |
| Memory Protection | MemoryHigh=85% | Leaves headroom for OS & FFmpeg workers |
Step-by-Step Triage & Config Remediation
- Create dedicated unprivileged user: Add a non-root mediamtx system user owning /opt/mediamtx and /dev/shm/mediamtx-hls.
- Install hardened unit file: Set LimitNOFILE=1048576 and ExecStartPre to initialize /dev/shm/mediamtx-hls.
- Enable and inspect logs: Run systemctl enable --now mediamtx and tail journalctl -u mediamtx -f.
[Unit] Description=MediaMTX Live RTMP/HLS/WebRTC Relay After=network-online.target [Service] User=mediamtx Group=mediamtx LimitNOFILE=1048576 ExecStartPre=/bin/mkdir -p /dev/shm/mediamtx-hls ExecStart=/usr/local/bin/mediamtx /etc/mediamtx/mediamtx.yml Restart=always RestartSec=2 [Install] WantedBy=multi-user.target
Diagnostic FAQ
Is systemd better than Docker for WebRTC WHEP?
For WebRTC UDP :8189 and SRT :8890, bare-metal systemd (or Docker network_mode: host) avoids conntrack NAT table bottlenecks.
How do I reload config without killing viewers?
MediaMTX watches mediamtx.yml and hot-reloads path configuration dynamically for most parameter updates.