Skip to content

Commit

Permalink
Zonetable additions and updates (#77)
Browse files Browse the repository at this point in the history
* auto dns/port selection based on zone

* add zone map

* Update README.md

* make use of zonetable persistent across all functions

* make logging more consistent

* cleanup

* cleanup

* made ImAlive more robust

* add EU zones

* improve zonetable to auto-extract zone names; add EU zones

* Update README.md

* add FALLBACK_IMALIVE_SERVICE

* Update zonetable

* implement zonetable auto updates

* Update imalive

* Update zonetable-update

* Update zonetable-update

* Update zonetable

* change to test zonetable downloads

* Create imalive-original

* Update Dockerfile

* Update imalive

* Update zonetable-update

* Update zonetable

* Update zonetable-update

* Update zonetable

* Update imalive

* Update imalive

* Update imalive

* Update imalive

* Update zonetable

* Update zonetable-update

* Update zonetable-update

* Update zonetable

* Update imalive

* Update zonetable

* Update zonetable-update

* Update zonetable

* Update 50-radarvirtuel

* Update 55-mlat-client

* Update imalive

* Update mlat-client

* Update radarvirtuel

* Update zonetable-update

* Update healthcheck.sh

* remove file

* add zonetable coverage for mlat_server

* temp change to test zonetable updates for mlat

* updates

* update zonetable

* kill processes more efficiently

* zonetable change test

* more zonetable change testing

* updates

* MLAT_SERVER auto config
  • Loading branch information
kx1t authored Aug 8, 2024
1 parent e2783e7 commit cbc9274
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 39 deletions.
40 changes: 22 additions & 18 deletions rootfs/etc/s6-overlay/scripts/50-radarvirtuel
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,42 @@
source /scripts/common
"${s6wrap[@]}" echo "Initializing RadarVirtuel..."

if [[ "${RV_SERVER%%:*}" == "mg2.adsbnetwork.com" ]]; then
RV_SERVER="mg22.adsbnetwork.com:${RV_SERVER##*:}"
"${s6wrap[@]}" cat <<EOF
+------------------------------------------------------------------------+
| ATTENTION! RV_SERVER mg2.adsbnetwork.com will be retired. |
| Please remove the RV_SERVER parameter from docker-compose.yml |
| We will use mg22.adsbnetwork.com for this session. |
+------------------------------------------------------------------------+
EOF
fi
RV_SERVER="${RV_SERVER:-mg22.adsbnetwork.com:50050}"
# check if we are in one of the defined zones, and update the server address accordingly:
source /home/zonetable
if [[ -n "$zone_id" ]]; then
RV_SERVER="${zone_dns}:${zone_port}"
"${s6wrap[@]}" cat <<EOF
Server and port have been updated automatically based on the LAT/LON of the receiver:
Zone: $zone_id
Name: $zone_name
DNS: $zone_dns
Port: $zone_port
Zone ID : $zone_id
Zone Name : $zone_name
ADSB Server: $zone_dns:$zone_port
MLAT Server: $zone_mlat
------------------
EOF
fi

if [[ "${RV_SERVER%%:*}" == "mg2.adsbnetwork.com" ]]; then
RV_SERVER="mg22.adsbnetwork.com:${RV_SERVER##*:}"
else
"${s6wrap[@]}" cat <<EOF
+------------------------------------------------------------------------+
| ATTENTION! RV_SERVER mg2.adsbnetwork.com will be retired. |
| Please remove the RV_SERVER parameter in docker-compose.yml |
| We will use mg22.adsbnetwork.com for this session. |
+------------------------------------------------------------------------+
ADSB Server: $RV_SERVER
MLAT Server: ${MLAT_HOST:-${SOURCE_HOST%%:*}:30005}
EOF
fi

if chk_enabled "${VERBOSE}"; then
"${s6wrap[@]}" cat <<EOF
Feeder key: ${FEEDER_KEY}
Source host: ${SOURCE_HOST}
RadarVirtuel Server: ${RV_SERVER}
Verbose: ${VERBOSE}
Feeder Key : ${FEEDER_KEY}
ADSB Source: ${SOURCE_HOST}
MLAT Source: ${MLAT_HOST:-${SOURCE_HOST%%:*}:30005}
Verbose : ${VERBOSE}
EOF
fi

Expand All @@ -63,7 +67,7 @@ else
ln -sf "/home/py/ANfeeder-raspy-$(dpkg --print-architecture)" /home/py/ANfeeder
fi
if chk_enabled "${VERBOSE}"; then
"${s6wrap[@]}" echo "Architecture: $(dpkg --print-architecture) (supported)"
"${s6wrap[@]}" echo "Sys Arch : $(dpkg --print-architecture) (supported)"
fi

# Let's do some checks to make sure the parameters look good, at least format-wise:
Expand Down
11 changes: 7 additions & 4 deletions rootfs/etc/s6-overlay/scripts/55-mlat-client
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ source /opt/healthchecks-framework/healthchecks.sh

MLAT_INPUT_TYPE="${MLAT_INPUT_TYPE:-auto}"
MLAT_RESULTS="${MLAT_RESULTS:-beast,listen,30105}"
MLAT_HOST="${MLAT_HOST:-${SOURCE_HOST%%:*}:30005}"

# Check: see if the parameters are correctly configured
if [[ -z "${MLAT_HOST}" ]]
then
if [[ -z "${LAT}" ]] || [[ -z "${LON}" ]] || [[ -z "${ALT}" ]]; then
"${s6wrap[@]}" cat <<EOF
-------------------------------------------------------------------
ATTENTION RADARVIRTUEL USERS!
Expand All @@ -45,8 +45,6 @@ This is a NEW FEATURE and we encourage you to use it!
Here's how: add the following parameter to the environment section of
radarvirtuel:

- MLAT_SERVER=mlat.adsbnetwork.com:50000 # Don't change this unless someone tells you to
- MLAT_HOST=\${HOSTNAME}:30005 # This is the same hostname as for SOURCE_HOST, but now using port 30005
- LAT=42.123456789 # This is your station latitude
- LON=-71.123456789 # This is your station longtude
- ALT=40ft # This is your antenna altitude above the ellipoid (MSL) - use "ft" for feet or "m" for meters
Expand Down Expand Up @@ -86,6 +84,11 @@ then
exit 0
fi

# update the MLAT_SERVER from the ZoneTable script:
source /home/zonetable
MLAT_SERVER="${zone_mlat:-${MLAT_SERVER}}"
MLAT_SERVER="${MLAT_SERVER:-mlat.adsbnetwork.com:50000}"

# Check: see if remote MLAT server can be reached
MLAT_OK=""
for (( i=1; i<="${MAX_TRIES}"; i++ ))
Expand Down
6 changes: 4 additions & 2 deletions rootfs/etc/s6-overlay/scripts/imalive
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ rm -f /run/zonetable.lock
KEEPALIVE_ALIVE="${KEEPALIVE_ALIVE:-600}" # keepalive timer in seconds if previous run was fine
KEEPALIVE_DEAD="${KEEPALIVE_DEAD:-60}" # keepalive timer in seconds if previous run failed
# dont make this shorter than 60 secs to allow services to be properly restarted after a failure
CONNECTION_TIMEOUT="{CONNECTION_TIMEOUT:-10}" # timeout when checking ability to connect using netcat

#CONNECTION_TIMEOUT="${CONNECTION_TIMEOUT:-10}" # timeout when checking ability to connect using netcat
ALIVE=true
mkdir -p /run/imalive
touch /run/imalive/errors
Expand Down Expand Up @@ -138,7 +139,8 @@ do
fi

if [[ "$ALIVE" != "true" ]]; then
killall /home/py/ANfeeder >/dev/null 2>&1 || true
pkill -f /home/py/ANfeeder >/dev/null 2>&1 || true
pkill -f /usr/local/bin/mlat-client >/dev/null 2>&1 || true
echo "$(date +%s) - $ALIVE" >> /run/imalive/errors
else
echo "" > /run/imalive/errors
Expand Down
13 changes: 10 additions & 3 deletions rootfs/etc/s6-overlay/scripts/mlat-client
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ MLAT_FLAG="/run/mlat-down"
MLAT_INPUT_TYPE="${MLAT_INPUT_TYPE:-auto}"
MLAT_RESULTS="${MLAT_RESULTS:-beast,listen,30105}"

# If MLAT_HOST is not defined, use port 30005 (beast_out) on the SOURCE_HOST
MLAT_HOST="${MLAT_HOST:-${SOURCE_HOST%%:*}:30005}"

START_DELAY=10s

# update the MLAT_SERVER from the ZoneTable script:
source /home/zonetable
MLAT_SERVER="${zone_mlat:-${MLAT_SERVER}}"
MLAT_SERVER="${MLAT_SERVER:-mlat.adsbnetwork.com:50000}"

# Do some basic checks:
# Sleep forever if the initialization process found that MLAT cannot be started
[[ -f ${MLAT_FLAG} ]] && [[ "$(<${MLAT_FLAG})" != "temp" ]] && sleep infinity || true
if [[ -f ${MLAT_FLAG} ]] && [[ "$(<${MLAT_FLAG})" != "temp" ]]; then stop_service; fi
# Sleep for 5 minutes if the issue is that the config is correct but the server is down
if [[ -f ${MLAT_FLAG} ]] && [[ "$(<${MLAT_FLAG})" == "temp" ]]
then
Expand All @@ -47,7 +55,6 @@ else
fi

MLAT_PARAM=(--input-type "${MLAT_INPUT_TYPE}")
# MLAT_PARAM+=(--no-udp)
MLAT_PARAM+=(--input-connect "${MLAT_HOST}")
MLAT_PARAM+=(--server "${MLAT_SERVER}")
MLAT_PARAM+=(--lat "${LAT}")
Expand All @@ -56,7 +63,7 @@ MLAT_PARAM+=(--alt "${ALT}")
MLAT_PARAM+=(--results "${MLAT_RESULTS}")
MLAT_PARAM+=(--user "${FEEDER_KEY}")
MLAT_PARAM+=(--uuid "${FEEDER_KEY##*:}")
[[ -n "${PRIVATE_MLAT}" ]] && MLAT_PARAM+=(--privacy) || true
MLAT_PARAM+=("${PRIVATE_MLAT:+--privacy}")

sleep ${START_DELAY}

Expand Down
4 changes: 2 additions & 2 deletions rootfs/etc/s6-overlay/scripts/radarvirtuel
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ source /scripts/common
START_DELAY=5s

RV_SERVER="${RV_SERVER:-mg22.adsbnetwork.com:50050}"
[[ "${RV_SERVER%%:*}" == "mg2.adsbnetwork.com" ]] && RV_SERVER="mg22.adsbnetwork.com:${RV_SERVER##*:}" || true
"${s6wrap[@]}" echo "started as an s6 service"
if [[ "${RV_SERVER%%:*}" == "mg2.adsbnetwork.com" ]]; then RV_SERVER="mg22.adsbnetwork.com:${RV_SERVER##*:}"; fi
"${s6wrap[@]}" echo "Started as an s6 service"

# check if we are in one of the defined zones, and update the server address accordingly:
source /home/zonetable
Expand Down
20 changes: 11 additions & 9 deletions rootfs/etc/s6-overlay/scripts/zonetable-update
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ source /scripts/common
ZONETABLE_CHECK_INT="${ZONETABLE_CHECK_INT:-7200}" # check every 2 hours
ZONETABLE_URL="${ZONETABLE_URL:-https://raw.githubusercontent.com/sdr-enthusiasts/docker-radarvirtuel/main/rootfs/home/zonetable}"

"${s6wrap[@]}" echo "[INFO] checking if zonetable needs to get updated"
"${s6wrap[@]}" echo "[INFO] Checking if zonetable needs to get updated"

if curl -sSL "${ZONETABLE_URL}" -o /tmp/zonetable >/dev/null 2>&1; then
if curl -sSL --fail "${ZONETABLE_URL}" -o /tmp/zonetable >/dev/null 2>&1; then
if [[ -n "$(comm --nocheck-order -3 /home/zonetable /tmp/zonetable 2>/dev/null)" ]]; then
"${s6wrap[@]}" echo "[INFO] zonetable has changed, installing new version"
"${s6wrap[@]}" echo "[INFO] Zonetable has changed, installing new version and restarting ANFeeder and mlat-client"
while [[ -f /run/zonetable.lock ]]; do sleep 1; done
touch /run/zonetable.lock
mv -f /tmp/zonetable /home/zonetable
chmod +x /home/zonetable
mv -f /tmp/zonetable /home/zonetable
chmod +x /home/zonetable
rm -f /run/zonetable.lock
pkill -f /home/py/ANfeeder >/dev/null 2>&1 || true
pkill -f /usr/local/bin/mlat-client >/dev/null 2>&1 || true
else
"${s6wrap[@]}" echo "[INFO] zonetable has not changed since last check"
"${s6wrap[@]}" echo "[INFO] Zonetable has not changed since last check"
rm -f /tmp/zonetable
fi
else
"${s6wrap[@]}" echo "[WARNING] couldn't reach the remote server with the latest zonetable - we will keep on using the current table"
"${s6wrap[@]}" echo "[WARNING] Couldn't reach the remote server with the latest zonetable - we will keep on using the current table"
fi

"${s6wrap[@]}" echo "[INFO] next zonetable update check will be at $(date -d "+$ZONETABLE_CHECK_INT seconds" | xargs)"
sleep $ZONETABLE_CHECK_INT
"${s6wrap[@]}" echo "[INFO] Next zonetable update check will be at $(date -d "+$ZONETABLE_CHECK_INT seconds" | xargs)"
exec sleep "$ZONETABLE_CHECK_INT"
Loading

0 comments on commit cbc9274

Please sign in to comment.