-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from sdr-enthusiasts/s6-migrate
initial
- Loading branch information
Showing
32 changed files
with
196 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
oneshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec /etc/s6-overlay/scripts/01-vdlm2dec |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec /etc/s6-overlay/scripts/vdlm2dec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec /etc/s6-overlay/scripts/vdlm_feeder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec /etc/s6-overlay/scripts/vdlm_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec /etc/s6-overlay/scripts/vdlm_stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
longrun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/command/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
# FEED_ID needs to be set | ||
|
||
if [[ -z "${FEED_ID}" ]]; then | ||
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" | ||
exit 1 | ||
fi | ||
|
||
IFS=';' | ||
read -ra SPLIT_FREQS <<< "${FREQUENCIES}" | ||
|
||
# loop through SPLIT_FREQS | ||
|
||
# We can only have 6 total frequencies | ||
|
||
if [[ "${#SPLIT_FREQS[@]}" -gt 8 ]]; then | ||
echo "FREQUENCIES is too long, exiting" | ||
exit 1 | ||
fi | ||
|
||
# FREQUENCIES needs to be in the range of 118.0 - 137.0. | ||
|
||
FREQ_STRING="" | ||
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" | ||
exit 1 | ||
fi | ||
FREQ_STRING+=" $i" | ||
done | ||
|
||
# Make sure mode is valid | ||
|
||
if [[ "${MODE}" != @(J|j|P|p|A|a) ]]; then | ||
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" | ||
exit 1 | ||
fi | ||
|
||
# DEVICE_ID or SERIAL needs to be set | ||
|
||
if [[ -z "${SERIAL}" ]]; then | ||
echo "SERIAL is not set, exiting" | ||
exit 1 | ||
fi | ||
|
||
RTL_TEST_OUTPUT=$(timeout 1s rtl_test -d 0 2>&1 | grep -P '^\s+\d+:\s+\S+?,\s+\S+?,\s+SN:\s+\S+?\s*$' || true) | ||
|
||
IFS=$'\n' | ||
for RTL_TEST_OUTPUT_LINE in $RTL_TEST_OUTPUT; do | ||
# Unset variables in case any regexes fail | ||
unset RTL_DEVICE_ID RTL_DEVICE_MAKE RTL_DEVICE_MODEL RTL_DEVICE_SERIAL | ||
|
||
# Pull variables from output via regex | ||
RTL_DEVICE_NUMBER=$(echo "$RTL_TEST_OUTPUT_LINE" | grep -oP '^\s+\K\d+(?=:\s+\S+?,\s+\S+?,\s+SN:\s+\S+?\s*$)') | ||
RTL_DEVICE_SERIAL=$(echo "$RTL_TEST_OUTPUT_LINE" | grep -oP '^\s+\d+:\s+\S+?,\s+\S+?,\s+SN:\s+\K\S+?(?=\s*$)') | ||
|
||
# See if we've found the device we're looking for | ||
if [[ -n "$SERIAL" && "$SERIAL" == "$RTL_DEVICE_SERIAL" ]]; then | ||
OUTPUT_DEVICE_ID="$RTL_DEVICE_NUMBER" | ||
fi | ||
done | ||
|
||
if [[ -z "${OUTPUT_DEVICE_ID}" ]]; then | ||
echo "Could not find device ID for serial '$SERIAL'" | ||
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 | ||
|
||
#sed -i "s/DEVICE_ID=\"\"/DEVICE_ID=\"$OUTPUT_DEVICE_ID\"/g" /etc/s6-overlay/scripts/vdlm2dec | ||
sed -i "s/FREQ_STRING=\"\"/FREQ_STRING=\"$FREQ_STRING\"/g" /etc/s6-overlay/scripts/vdlm2dec | ||
|
||
# Everything is good to go. Exit with 0 | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/command/with-contenv bash | ||
# shellcheck shell=bash | ||
|
||
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" | ||
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}' | ||
|
||
sleep 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/command/with-contenv bash | ||
#shellcheck shell=bash | ||
|
||
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}' | ||
|
||
sleep 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/command/with-contenv bash | ||
#shellcheck shell=bash | ||
|
||
|
||
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" | ||
fi | ||
exit | ||
fi | ||
|
||
# Start our stats loop | ||
while true; do | ||
|
||
# capture 5 mins of flows | ||
timeout --foreground 300s socat -u TCP:127.0.0.1:15555 CREATE:/run/acars/vdlm2.past5min.json | ||
|
||
# if the port isn't reachable, this file isn't created, either container is shutting down or vdlm_server isn't reachable | ||
# in both cases let's exit, if this should still be running it will be restarted | ||
if ! [[ -f /run/acars/vdlm2.past5min.json ]]; then | ||
exit | ||
fi | ||
|
||
# shellcheck disable=SC2016 | ||
echo "$(wc -l < /run/acars/vdlm.past5min.json) VDLM messages received in last 5 mins" | stdbuf -oL awk '{print "[vdlm_stats] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}' | ||
|
||
# rotate files keeping last 2 hours | ||
for i in {24..1}; do | ||
mv "/run/acars/vdlm2.$((i-1)).json" "/run/acars/vdlm2.$i.json" > /dev/null 2>&1 || true | ||
done | ||
mv "/run/acars/vdlm2.past5min.json" "/run/acars/vdlm2.0.json" > /dev/null 2>&1 || true | ||
|
||
done | ||
|
||
sleep 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters