Add recording cleanup container to remove noise files

Alpine-based sdr-cleanup container runs a find loop every 5 minutes,
deleting MP3 files under 3 KB (configurable via SIZE_THRESHOLD env var)
to keep the web browser and Samba share free of false-positive recordings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael Smith
2026-03-21 18:32:17 +00:00
parent d3effff7db
commit 94fdaf7644
8 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
## Context
The SDR recorder running in Docker on `sdr-pi` writes MP3 files to `/home/m/recordings/` (mounted from the host). Despite squelch tuning, many files are noise — today's data shows 91 files totaling 476 KB, with the majority under 2 KB. These clutter the Nginx web browser and Samba share, making it hard to find real transmissions.
The recorder container runs as root (required for USB/SDR hardware access) and writes files owned by root, so cleanup must also run as root.
## Goals / Non-Goals
**Goals:**
- Automatically remove recordings that are too small to contain real audio
- Make the size threshold easily adjustable via environment variable
- Keep everything version-controlled in docker-compose
- Run frequently enough that the web/Samba views stay clean
**Non-Goals:**
- Duration-based or content-based analysis (too complex, needs extra tools)
- Age-based retention policy (handled manually for now)
## Decisions
### Dedicated cleanup container in docker-compose
Add a lightweight Alpine container (`sdr-cleanup`) to docker-compose that shares the `/home/m/recordings` volume. This follows Docker's separation-of-concerns model — one container per responsibility. The container runs a simple `find -delete` loop with `sleep` instead of requiring a cron daemon. Since it runs as root (Alpine default), it can delete the root-owned files written by the recorder.
Alternatives considered:
- **Host crontab**: Simplest, but files are root-owned so needs `sudo crontab`, and isn't version-controlled in docker-compose
- **Cron inside recorder container**: Not our image, would need custom build
- **Systemd timer on host**: More ceremony than cron for the same result
### File size threshold as the filter heuristic
Use file size (default 3 KB) rather than MP3 duration. This avoids needing `ffprobe` or similar tools. From today's data, files under 3 KB are consistently noise — real transmissions start around 5 KB. Configurable via `SIZE_THRESHOLD` environment variable in docker-compose.
### 5-minute sleep loop
Run every 5 minutes via `sleep 300` in a loop. Lightweight and keeps the browsing experience clean.
### Only delete files older than 1 minute
Add a minimum age filter (`-mmin +1`) to avoid deleting files still being written by rtl_airband.
## Risks / Trade-offs
- **Threshold too aggressive** → Real short transmissions deleted. Mitigation: start conservative at 3 KB, tune via environment variable.
- **Race condition with active writes** → The `-mmin +1` guard ensures we never delete a file rtl_airband is still writing.
- **Container restart** → If the cleanup container crashes, `restart: unless-stopped` brings it back. No state to lose.