Skip to content

Commit

Permalink
updates to use s6 wrap and remove serial detection
Browse files Browse the repository at this point in the history
  • Loading branch information
fredclausen committed Dec 31, 2023
1 parent 6b166a8 commit 931a898
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 66 deletions.
34 changes: 11 additions & 23 deletions rootfs/etc/s6-overlay/scripts/01-vdlm2dec
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/command/with-contenv bash
# shellcheck shell=bash

# shellcheck disable=SC1091
source /scripts/common

# FEED_ID needs to be set

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

# FREQUENCIES needs to be set

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

Expand All @@ -23,7 +27,7 @@ read -ra SPLIT_FREQS <<< "${FREQUENCIES}"
# We can only have 6 total frequencies

if [[ "${#SPLIT_FREQS[@]}" -gt 8 ]]; then
echo "FREQUENCIES is too long, exiting"
"${s6wrap[@]}" echo "FREQUENCIES is too long, exiting"
exit 1
fi

Expand All @@ -34,7 +38,7 @@ for i in "${SPLIT_FREQS[@]}"
do
:
if [[ $(echo "$i > 118.0" | bc) -eq 0 || $(echo "$i < 137.0" | bc) -eq 0 ]]; then
echo "FREQUENCY $i is not in the range of 118.0 - 137.0, exiting"
"${s6wrap[@]}" echo "FREQUENCY $i is not in the range of 118.0 - 137.0, exiting"
exit 1
fi
FREQ_STRING+=" $i"
Expand All @@ -43,38 +47,22 @@ done
# Make sure mode is valid

if [[ "${MODE}" != @(J|j|P|p|A|a) ]]; then
echo "MODE is not valid, exiting"
"${s6wrap[@]}" echo "MODE is not valid, 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

# DEVICE_ID or SERIAL needs to be set

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

OUTPUT_DEVICE_ID="$(timeout 1s rtl_test -d $((RANDOM+99)) 2>&1 | grep -P -e "SN: $SERIAL" | sed -n 's/^\s*\([0-9]\+\):.*$/\1/p')"

if [[ -z "${OUTPUT_DEVICE_ID}" ]]; then
echo "Could not find device ID for serial '$SERIAL'"
"${s6wrap[@]}" echo "SERIAL is not set, exiting"
exit 1
fi

rm -rf /etc/s6-overlay/scripts/vdlm2dec > /dev/null 2>&1
if [[ -n "${OUTPUT_DEVICE_ID}" ]]; then
cp /etc/templates/run /etc/s6-overlay/scripts/vdlm2dec
else
cp /etc/templates/bad /etc/s6-overlay/scripts/vdlm2dec
fi

s6-chmod 0755 /etc/s6-overlay/scripts/vdlm2dec

mkdir -p /run/acars
touch /run/acars/vdlm2.past5min.json

Expand Down
9 changes: 7 additions & 2 deletions rootfs/etc/s6-overlay/scripts/02-gdbcheck
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/command/with-contenv bash
#shellcheck shell=bash

# shellcheck disable=SC1091
source /scripts/common

# if GDB is set, install GDB

if [ -n "$GDB" ]; then
echo "Installing GDB"
apt-get update && apt-get install -y gdb
# shellcheck disable=SC2154
"${s6wrap[@]}" echo "Installing GDB"
"${s6wrap[@]}" apt-get update && apt-get install -y gdb
fi
28 changes: 12 additions & 16 deletions rootfs/etc/templates/run → rootfs/etc/s6-overlay/scripts/vdlm2dec
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/command/with-contenv bash
#shellcheck shell=bash

SCRIPT_NAME="$(basename "$0")"
SCRIPT_NAME="${SCRIPT_NAME%.*}"

# shellcheck disable=SC2034
s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args)
# Require that vdlm_server is running
if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15555\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then
sleep 1
if [[ ! ${QUIET_LOGS,,} =~ true ]]; then
echo "[vdlm2dec] vdlm_server not running, exiting"
"${s6wrap[@]}" echo "vdlm_server not running, exiting"
fi
exit
fi
Expand All @@ -14,14 +19,6 @@ VDLM_BIN="/usr/local/bin/vdlm2dec"
# shellcheck disable=SC2001
FREQ_STRING=""

DEVICE_ID="$(timeout 1s rtl_test -d $((RANDOM+99)) 2>&1 | grep -P -e "SN: $SERIAL" | sed -n 's/^\s*\([0-9]\+\):.*$/\1/p')"

if [[ -z "${DEVICE_ID}" ]]; then
echo "Could not find device ID for serial '$SERIAL'"
sleep 60
exit 1
fi

if [ -z "$GAIN" ]; then
GAIN="400"
fi
Expand Down Expand Up @@ -50,8 +47,8 @@ if [ -n "${SERVER}" ]; then
fi

# Specify device ID
if [ -n "${DEVICE_ID}" ]; then
VDLM_CMD+=("-r" "$DEVICE_ID")
if [ -n "${SERIAL}" ]; then
VDLM_CMD+=("-r" "$SERIAL")
fi

# shellcheck disable=SC2206
Expand All @@ -68,11 +65,11 @@ fi

set -eo pipefail

echo "[vdlm2dec] Starting: '$VDLM_BIN" "${VDLM_CMD[*]}'"
"${s6wrap[@]}" echo "Starting: '$VDLM_BIN" "${VDLM_CMD[*]}'"

if [[ ${QUIET_LOGS,,} =~ true ]]; then
# shellcheck disable=SC2016
"$VDLM_BIN" "${VDLM_CMD[@]}" 2>&1 | \
"${s6wrap[@]}" "$VDLM_BIN" "${VDLM_CMD[@]}" 2>&1 | \
stdbuf -oL sed --unbuffered '/^$/d' | \
stdbuf -oL awk '! /^dumpvdl2/' | \
stdbuf -oL awk '! /^Sampling rate set/' | \
Expand All @@ -89,11 +86,10 @@ if [[ ${QUIET_LOGS,,} =~ true ]]; then
stdbuf -oL awk '! /^Set center freq. /' | \
stdbuf -oL awk '! /^Decoding [0-9]+ channels/' | \
stdbuf -oL awk '! /^Allocating [0-9]+ zero-copy buffers/' | \
stdbuf -oL awk '{print "[vdlm2dec] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
stdbuf -oL awk '{print $0}'
else
# shellcheck disable=SC2016
"$VDLM_BIN" "${VDLM_CMD[@]}" \
2>&1 | stdbuf -oL sed --unbuffered '/^$/d' | stdbuf -oL awk '{print "[vdlm2dec] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
"${s6wrap[@]}" "$VDLM_BIN" "${VDLM_CMD[@]}"
fi

sleep 5
11 changes: 8 additions & 3 deletions rootfs/etc/s6-overlay/scripts/vdlm_feeder
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#!/command/with-contenv bash
# shellcheck shell=bash

SCRIPT_NAME="$(basename "$0")"
SCRIPT_NAME="${SCRIPT_NAME%.*}"

# shellcheck disable=SC2034
s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args)

set -o pipefail

# Require that vdlm_server is running
if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15555\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then
sleep 1
if [[ ! ${QUIET_LOGS,,} =~ true ]]; then
echo "[vdlm_feeder] vdlm_server not running, exiting"
"${s6wrap[@]}" echo "vdlm_server not running, exiting"
fi
exit
fi
set -e

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

sleep 5
13 changes: 6 additions & 7 deletions rootfs/etc/s6-overlay/scripts/vdlm_server
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/command/with-contenv bash
#shellcheck shell=bash

set -o pipefail
set -e
set -o pipefail
set -e

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

sleep 5
sleep 5
9 changes: 7 additions & 2 deletions rootfs/etc/s6-overlay/scripts/vdlm_stats
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#!/command/with-contenv bash
#shellcheck shell=bash

SCRIPT_NAME="$(basename "$0")"
SCRIPT_NAME="${SCRIPT_NAME%.*}"

# shellcheck disable=SC2034
s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args)

set -o pipefail

# Require that vdlm_server is running
if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15555\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then
sleep 1
if [[ ! ${QUIET_LOGS,,} =~ true ]]; then
echo "[vdlm_stats] vdlm_server not running, exiting"
"${s6wrap[@]}" echo "vdlm_server not running, exiting"
fi
exit
fi
Expand All @@ -26,7 +31,7 @@ while true; do
fi

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

# rotate files keeping last 2 hours
for i in {24..1}; do
Expand Down
13 changes: 0 additions & 13 deletions rootfs/etc/templates/bad

This file was deleted.

0 comments on commit 931a898

Please sign in to comment.