Skip to content

Commit

Permalink
use s6 to restart the dumphfdl service and use s6 wrap instead of awk…
Browse files Browse the repository at this point in the history
…/echo stuff for messages in all scripts
  • Loading branch information
fredclausen committed Dec 9, 2023
1 parent 60a8994 commit 64b4f3c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
18 changes: 10 additions & 8 deletions rootfs/etc/s6-overlay/scripts/01-dumphfdl
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
#!/command/with-contenv bash
# shellcheck shell=bash

source /scripts/common

if [[ -z "$SOAPYSAMPLERATE" ]]; then
echo "SOAPYSAMPLERATE is not set, exiting"
"${s6wrap[@]}" echo "SOAPYSAMPLERATE is not set, exiting"
exit 1
fi

if [[ -z "$GAIN" ]]; then
echo "GAIN is not set, exiting"
"${s6wrap[@]}" echo "GAIN is not set, exiting"
exit 1
fi

if [[ -z "$GAIN_TYPE" ]]; then
echo "GAIN_TYPE is not set, exiting"
"${s6wrap[@]}" echo "GAIN_TYPE is not set, exiting"
exit 1
fi

if [[ -z "$SOAPYSDRDRIVER" ]]; then
echo "SOAPYSDRDRIVER is not set, exiting"
"${s6wrap[@]}" echo "SOAPYSDRDRIVER is not set, exiting"
exit 1
fi

if [[ -n "${SERVER}" && -z "${SERVER_PORT}" ]]; then
echo "SERVER is set but SERVER_PORT is not set, exiting"
"${s6wrap[@]}" echo "SERVER is set but SERVER_PORT is not set, exiting"
exit 1
fi

if [[ -n "$ZMQ_MODE" ]]; then
if [[ -z "$ZMQ_ENDPOINT" ]]; then
echo "ZMQ_MODE mode set to '${ZMQ_MODE}, but ZMQ_ENDPOINT is not set, exiting"
"${s6wrap[@]}" echo "ZMQ_MODE mode set to '${ZMQ_MODE}, but ZMQ_ENDPOINT is not set, exiting"
exit 1
fi
fi

if [[ -n "$ZMQ_ENDPOINT" ]]; then
if [[ -z "$ZMQ_MODE" ]]; then
echo "ZMQ_ENDPOINT mode set to '${ZMQ_ENDPOINT}, but ZMQ_MODE is not set, exiting"
"${s6wrap[@]}" echo "ZMQ_ENDPOINT mode set to '${ZMQ_ENDPOINT}, but ZMQ_MODE is not set, exiting"
exit 1
fi
fi

if [[ -z "$FEED_ID" ]]; then
echo "FEED_ID is not set, exiting"
"${s6wrap[@]}" echo "FEED_ID is not set, exiting"
exit 1
fi

Expand Down
5 changes: 2 additions & 3 deletions rootfs/etc/s6-overlay/scripts/hfdl_feeder
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [[ -n ${SERVER} ]]; then
if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15556\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then
sleep 1
if [[ ! ${QUIET_LOGS,,} =~ true ]]; then
echo "[hfdl_feeder] vdlm_server not running, exiting"
"${s6wrap[@]}" echo "vdlm_server not running, exiting"
fi
exit
fi
Expand All @@ -17,8 +17,7 @@ if [[ -n ${SERVER} ]]; then

SERVER_ADDR="UDP:${SERVER}:${SERVER_PORT}"
# shellcheck disable=SC2016
socat -d TCP:127.0.0.1:15556 "$SERVER_ADDR" \
2>&1 | stdbuf -oL awk '{print "[hfdl_feeder] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
"${s6wrap[@]}" socat -d TCP:127.0.0.1:15556 "$SERVER_ADDR"

sleep 5
else
Expand Down
3 changes: 1 addition & 2 deletions rootfs/etc/s6-overlay/scripts/hfdl_server
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# Listens for the output of dumphfdl (UDP), and makes it available for multiple processes at TCP port 15555
# shellcheck disable=SC2016
socat -u udp-listen:5556,fork stdout | ncat -4 --keep-open --listen 0.0.0.0 15556 \
2>&1 | stdbuf -oL awk '{print "[hfdl_server] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
"${s6wrap[@]}" socat -u udp-listen:5556,fork stdout | ncat -4 --keep-open --listen 0.0.0.0 15556

sleep 5
10 changes: 5 additions & 5 deletions rootfs/etc/s6-overlay/scripts/hfdl_stats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -o pipefail
if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15556\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then
sleep 1
if [[ ! ${QUIET_LOGS,,} =~ true ]]; then
echo "[hfdl_stats] hfdl_server not running, exiting"
"${s6wrap[@]}" echo "[hfdl_stats] hfdl_server not running, exiting"
fi
exit
fi
Expand All @@ -16,7 +16,7 @@ fi
while true; do

# capture 5 mins of flows
timeout --foreground 300s socat -u TCP:127.0.0.1:15556 CREATE:/run/hfdl/hfdl.past5min.json
"${s6wrap[@]}" timeout --foreground 300s socat -u TCP:127.0.0.1:15556 CREATE:/run/hfdl/hfdl.past5min.json

# if the port isn't reachable, this file isn't created, either container is shutting down or hfdl_server isn't reachable
# in both cases let's exit, if this should still be running it will be restarted
Expand All @@ -25,7 +25,7 @@ while true; do
fi

# shellcheck disable=SC2016
echo "$(sed 's/}{/}\n{/g' /run/hfdl/hfdl.past5min.json | wc -l) hfdl messages received in last 5 mins" | stdbuf -oL awk '{print "[hfdl_stats] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
"${s6wrap[@]}" echo "$(sed 's/}{/}\n{/g' /run/hfdl/hfdl.past5min.json | wc -l) hfdl messages received in last 5 mins"

# rotate files keeping last 2 hours
for i in {24..1}; do
Expand All @@ -39,8 +39,8 @@ while true; do
if [[ $(find /run/hfdl -type f -name 'hfdl.*.json' | wc -l) -gt 6 ]]; then
# now check the last 6 files for messages
if [[ $(sed 's/}{/}\n{/g' /run/hfdl/hfdl.{0..5}.json | wc -l) -eq 0 ]]; then
echo "[hfdl_stats] No messages received in last 30 minutes, killing dumphfdl to rerun the frequency optimizer"
pkill dumphfdl
"${s6wrap[@]}" echo " No messages received in last 30 minutes, killing dumphfdl to rerun the frequency optimizer"
s6-svc -r /run/service/dumphfdl
rm -f /run/hfdl/hfdl.*.json
exit
fi
Expand Down

0 comments on commit 64b4f3c

Please sign in to comment.