Skip to content

Commit

Permalink
fix message monitor (#104)
Browse files Browse the repository at this point in the history
* fix message monitor

* Restart When Stale set to default-TRUE

* Restart When Stale is default `true`
  • Loading branch information
kx1t authored Apr 2, 2024
1 parent 73a107b commit 5939713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ You should now be feeding ADSB-ES & UAT to the "new" aggregators, FlightAware, a
| `LAT` | Latitude of your receiver. Only required if you want range statistics for InfluxDB, Prometheus, or tar1090/ultrafeeder graphs. | Unset |
| `LON` | Longitude of your receiver. Only required if you want range statistics for InfluxDB, Prometheus, or tar1090/ultrafeeder graphs. | Unset |
| `DUMP978_MSG_MONITOR_INTERVAL` | Interval between runs of the Message Monitor that checks if new messages are received. Format of value is anything that is accepted by the Linux `sleep` command | Unset (30 minutes) |
| `DUMP978_MSG_MONITOR_RESTART_WHEN_STALE` | If set to `true`/`on`/`yes`/`1`, the receiver process is restarted when no messages are received during the monitoring interval | Unset (`false`) |
| `DUMP978_MSG_MONITOR_RESTART_WHEN_STALE` | If set to `true`/`on`/`yes`/`1`, the receiver process is restarted when no messages are received during the monitoring interval | `true` |

### `dump978-fa` General Options

Expand Down
15 changes: 11 additions & 4 deletions rootfs/etc/s6-overlay/scripts/message-monitor
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
source /scripts/common
mkdir -p /run/stats
s6wrap=(s6wrap --quiet --prepend="$(basename "$0")" --timestamps --args)

# Adjustment Timeframe is the same as used for AutoGain, with a default of 0800-1800 "container time" if omitted
READSB_AUTOGAIN_ADJUSTMENT_TIMEFRAME="${DUMP978_AUTOGAIN_ADJUSTMENT_TIMEFRAME:-${READSB_AUTOGAIN_ADJUSTMENT_TIMEFRAME:-0800-1800}}"

# Restart When Stale is default-TRUE. This is acceptable - worst case, we'd restart the dump978 s6 service once every 30 minutes
DUMP978_MSG_MONITOR_RESTART_WHEN_STALE="${DUMP978_MSG_MONITOR_RESTART_WHEN_STALE:-true}"

while :
do
# Make sure we're receiving messages from the SDR
Expand Down Expand Up @@ -35,14 +40,16 @@ do
"${s6wrap[@]}" echo "[STARTING] Receiver starting: No messages have been received as the container is still starting"
new_msg_count=0
elif (( new_msg_count == old_msg_count )); then
# only print and restart if we're within the adjustment timeframe
if (( $(date +%s) < $(date -d "${READSB_AUTOGAIN_ADJUSTMENT_TIMEFRAME%%-*} today" +%s) )); then
"${s6wrap[@]}" echo "[WARNING] Receiver appears stale: No messages received since last run of the Messages Monitor ($secs_since_last_check secs ago)"

"${s6wrap[@]}" echo "[WARNING] Receiver appears stale: No messages received since last run of the Messages Monitor ($secs_since_last_check secs ago)"
# only restart if we're within the adjustment timeframe
if (( $(date +%s) >= $(date -d "${READSB_AUTOGAIN_ADJUSTMENT_TIMEFRAME%%-*} today" +%s) )) \
&& (( $(date +%s) <= $(date -d "${READSB_AUTOGAIN_ADJUSTMENT_TIMEFRAME##*-} today" +%s) )); then
if chk_enabled "$DUMP978_MSG_MONITOR_RESTART_WHEN_STALE"; then
"${s6wrap[@]}" echo "[WARNING] Restarting the dump978 service..."
s6-svc -r /run/service/dump978 2>/dev/null || true
fi
else
"${s6wrap[@]}" echo " No action is taken since we're outside the Adjustment Timeframe of ${READSB_AUTOGAIN_ADJUSTMENT_TIMEFRAME}"
fi
elif (( new_msg_count > old_msg_count )); then
"${s6wrap[@]}" echo "[INFO] Receiver is OK: $(( new_msg_count - old_msg_count )) messages received since last run of the Messages Monitor ($secs_since_last_check secs ago)"
Expand Down

0 comments on commit 5939713

Please sign in to comment.