From 931a8984539353810aec5ad08d196a7c80118865 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:24:17 -0700 Subject: [PATCH] updates to use s6 wrap and remove serial detection --- rootfs/etc/s6-overlay/scripts/01-vdlm2dec | 34 ++++++------------- rootfs/etc/s6-overlay/scripts/02-gdbcheck | 9 +++-- .../run => s6-overlay/scripts/vdlm2dec} | 28 +++++++-------- rootfs/etc/s6-overlay/scripts/vdlm_feeder | 11 ++++-- rootfs/etc/s6-overlay/scripts/vdlm_server | 13 ++++--- rootfs/etc/s6-overlay/scripts/vdlm_stats | 9 +++-- rootfs/etc/templates/bad | 13 ------- 7 files changed, 51 insertions(+), 66 deletions(-) rename rootfs/etc/{templates/run => s6-overlay/scripts/vdlm2dec} (75%) delete mode 100755 rootfs/etc/templates/bad diff --git a/rootfs/etc/s6-overlay/scripts/01-vdlm2dec b/rootfs/etc/s6-overlay/scripts/01-vdlm2dec index e386a0f..db4e76c 100755 --- a/rootfs/etc/s6-overlay/scripts/01-vdlm2dec +++ b/rootfs/etc/s6-overlay/scripts/01-vdlm2dec @@ -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 @@ -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 @@ -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" @@ -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 diff --git a/rootfs/etc/s6-overlay/scripts/02-gdbcheck b/rootfs/etc/s6-overlay/scripts/02-gdbcheck index 3874889..3faabe0 100755 --- a/rootfs/etc/s6-overlay/scripts/02-gdbcheck +++ b/rootfs/etc/s6-overlay/scripts/02-gdbcheck @@ -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 diff --git a/rootfs/etc/templates/run b/rootfs/etc/s6-overlay/scripts/vdlm2dec similarity index 75% rename from rootfs/etc/templates/run rename to rootfs/etc/s6-overlay/scripts/vdlm2dec index 1c93b0b..9983872 100755 --- a/rootfs/etc/templates/run +++ b/rootfs/etc/s6-overlay/scripts/vdlm2dec @@ -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 @@ -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 @@ -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 @@ -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/' | \ @@ -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 diff --git a/rootfs/etc/s6-overlay/scripts/vdlm_feeder b/rootfs/etc/s6-overlay/scripts/vdlm_feeder index aea9743..d8050c0 100755 --- a/rootfs/etc/s6-overlay/scripts/vdlm_feeder +++ b/rootfs/etc/s6-overlay/scripts/vdlm_feeder @@ -1,13 +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_feeder] vdlm_server not running, exiting" + "${s6wrap[@]}" echo "vdlm_server not running, exiting" fi exit fi @@ -15,7 +21,6 @@ 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 diff --git a/rootfs/etc/s6-overlay/scripts/vdlm_server b/rootfs/etc/s6-overlay/scripts/vdlm_server index 1d2677e..308f2e3 100755 --- a/rootfs/etc/s6-overlay/scripts/vdlm_server +++ b/rootfs/etc/s6-overlay/scripts/vdlm_server @@ -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 diff --git a/rootfs/etc/s6-overlay/scripts/vdlm_stats b/rootfs/etc/s6-overlay/scripts/vdlm_stats index c3ae54d..e479b90 100755 --- a/rootfs/etc/s6-overlay/scripts/vdlm_stats +++ b/rootfs/etc/s6-overlay/scripts/vdlm_stats @@ -1,6 +1,11 @@ #!/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 @@ -8,7 +13,7 @@ set -o pipefail 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 @@ -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 diff --git a/rootfs/etc/templates/bad b/rootfs/etc/templates/bad deleted file mode 100755 index dff3898..0000000 --- a/rootfs/etc/templates/bad +++ /dev/null @@ -1,13 +0,0 @@ -#!/command/with-contenv bash -#shellcheck shell=bash - -# shellcheck disable=SC2001,SC2034 -VDLM_BIN="/usr/local/bin/dumpvdl2" -# shellcheck disable=SC2001,SC2034 -DEVICE_ID="" -# shellcheck disable=SC2001,SC2034 -FREQ_STRING="" -# shellcheck disable=SC2001,SC2034 -VDLM_CMD=() -echo "NO DECODER IS STARTING" -sleep 86400