Files

19 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Restart the scanner when the HackRF stream is dead (USB re-enumeration / brownout leaves
# rtl_airband looping on "readStream failed: TIMEOUT" forever).
systemctl is-active -q sdr-scanner.service || exit 0
# only judge a process that has been up for > 45 s (old errors stay in the journal window)
start_us=$(systemctl show -p ExecMainStartTimestampMonotonic --value sdr-scanner.service)
now_us=$(awk "{printf \"%d\", \$1*1000000}" /proc/uptime)
[ $(( (now_us - start_us) / 1000000 )) -ge 45 ] || exit 0
n=$(journalctl -u sdr-scanner.service --since "-40s" --no-pager -q 2>/dev/null | grep -c "readStream failed" || true)
if [ "${n:-0}" -ge 10 ]; then
# a restart alone does not wake a HackRF wedged by the hourly hackrf_sweep (2026-10-23: 9 h of TIMEOUT loops);
# a USB reset of that one device does (no port power switching: the webcam shares the hub)
echo "HackRF stream dead ($n errors in 40 s), USB reset of the HackRF and restart of sdr-scanner"
systemctl stop sdr-scanner.service
usbreset 1d50:6089 || echo "usbreset failed"
sleep 2
systemctl start sdr-scanner.service
fi