1
0
Fork 0
mirror of https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git synced 2024-11-23 06:10:10 +00:00
docker-adsb-ultrafeeder/rootfs/etc/services.d/mlathub/run
2023-04-14 08:21:17 -04:00

131 lines
No EOL
4.4 KiB
Text

#!/usr/bin/with-contenv bash
# shellcheck shell=bash disable=SC1091,SC2016
source /scripts/common
if [[ -z "${MLAT_CONFIG}" ]] && [[ -z "$MLATHUB_NET_CONNECTOR" ]]; then
echo "[$(date)][mlathub] No MLAT servers have been defined in MLAT_CONFIG and no external sources have been defined in MLATHUB_NET_CONNECTOR - no need to start MLATHUB"
sleep infinity
fi
if chk_enabled "${MLATHUB_DISABLED}"; then
echo "[$(date)][mlathub] MLATHUB is disabled."
sleep infinity
fi
# Build the readsb command line based on options
MLATHUB_BIN="/usr/local/bin/readsb"
# set some basic options:
MLATHUB_CMD=("--net")
MLATHUB_CMD+=("--quiet")
MLATHUB_CMD+=("--net-only")
MLATHUB_CMD+=("--mlat")
MLATHUB_CMD+=("--forward-mlat")
MLATHUB_CMD+=("--net-connector=localhost,30004,beast_reduce_out")
# define some more ports:
MLATHUB_CMD+=("--net-sbs-port=${MLATHUB_SBS_OUT_PORT:-31003}")
MLATHUB_CMD+=("--net-bi-port=${MLATHUB_BEAST_IN_PORT:-31004}")
MLATHUB_CMD+=("--net-bo-port=${MLATHUB_BEAST_OUT_PORT:-31005}")
MLATHUB_CMD+=("--net-beast-reduce-out-port=${MLATHUB_BEAST_REDUCE_OUT_PORT:-31006}")
# We need to get the mlat results ports from the parameters:
# parse MLAT_CONFIG string into mlat_configs array
readarray -td ";" mlat_configs < <(printf '%s' "${MLAT_CONFIG// /}")
# Now loop through the MLAT_CONFIG items and add a net-connector for each of them:
mlat_result_sources=0
for instance in "${mlat_configs[@]}"
do
# shellcheck disable=SC2015
[[ -z "${instance}" ]] && continue || true
# put individual params into the $params array:
readarray -td "," params < <(printf '%s' "${instance}")
for ((i=2; i<${#params[*]}; i++))
do
if [[ -n "${params[i]}" ]] && [[ "${params[i]}" =~ ^[0-9]+$ ]]; then
# the parameter is a number and it is assumed that this is the beast_results port
MLATHUB_CMD+=("--net-connector=localhost,${params[i]},beast_in")
(( mlat_result_sources++ )) || true
break
fi
done
done
if (( mlat_result_sources == 0 ))
then
echo "[$(date)][mlathub] No MLAT servers have been defined in MLAT_CONFIG - no need to start MLATHUB"
sleep infinity
fi
# removed as it will cause looping:
# handle MLATHUB_ENABLE_ADSB_INGEST (if set, connect to readsb as input)
# if [[ -n "$MLATHUB_ENABLE_ADSB_INGEST" ]]; then
# MLATHUB_CMD+=("--net-connector=localhost,30006,beast_in")
# fi
# Add any additional net_connectors:
if [[ -n "$MLATHUB_NET_CONNECTOR" ]]; then
IFS=';' read -r -a MLATHUB_NET_CONNECTOR_ARRAY <<< "$MLATHUB_NET_CONNECTOR"
for NET_CONNECTOR_ELEMENT in "${MLATHUB_NET_CONNECTOR_ARRAY[@]}"
do
MLATHUB_CMD+=("--net-connector=${NET_CONNECTOR_ELEMENT// /}")
done
fi
if chk_enabled "${READSB_DEBUG}"; then
MLATHUB_CMD+=("--debug=$READSB_DEBUG")
fi
if [ -n "${LAT}" ]; then
MLATHUB_CMD+=(--lat "${LAT}")
elif [ -n "${READSB_LAT}" ]; then
MLATHUB_CMD+=(--lat "${READSB_LAT}")
fi
if [ -n "${LONG}" ]; then
MLATHUB_CMD+=(--lon "${LONG}")
elif [ -n "${READSB_LON}" ]; then
MLATHUB_CMD+=(--lon "${READSB_LON}")
fi
# Handle "--max-range=<dist>"
if [[ -n "$READSB_MAX_RANGE" ]]; then
MLATHUB_CMD+=("--max-range=$READSB_MAX_RANGE")
fi
# Handle "--net-connector-delay=<seconds>"
if [[ -n "$READSB_NET_CONNECTOR_DELAY" ]]; then
MLATHUB_CMD+=("--net-connector-delay=$READSB_NET_CONNECTOR_DELAY")
fi
# Handle "--net-heartbeat=<rate>"
MLATHUB_CMD+=("--net-heartbeat=${READSB_NET_HEARTBEAT:-30}")
if [[ ! -f /run/mlathub_up ]]
then
echo "[$(date)][mlathub] Delaying MLAT hub start until container is established..."
while [[ ! -f /run/mlathub_up ]]
do
sleep 2
done
fi
sleep 5 # sleep a bit so everything is well established
echo "[$(date)][mlathub] Starting MLATHUB..."
# shellcheck disable=SC2086
if [[ -z "${LOGLEVEL}" ]] || [[ "${LOGLEVEL,,}" == "verbose" ]]; then
"${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 | \
mawk -W Interactive '{print "[" strftime("%Y/%m/%d %H:%M:%S", systime()) "][mlathub] " $0}'
elif [[ "${LOGLEVEL,,}" == "error" ]]; then
"${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS 2>&1 >/dev/null | \
mawk -W Interactive '{print "[" strftime("%Y/%m/%d %H:%M:%S", systime()) "][mlathub] " $0}'
elif [[ "${LOGLEVEL,,}" == "none" ]]; then
"${MLATHUB_BIN}" "${MLATHUB_CMD[@]}" $MLATHUB_EXTRA_ARGS >/dev/null 2>/dev/null
fi
echo "[$(date "+%Y-%m-%d %H:%M:%S")][mlathub] The mlathub instance has exited. Restarting in 10 seconds."
sleep 10