Funknetz needs a protocol 2.0 reflector without production credentials; the compose stack and smoke test prove the station can log in and select a talk group. Co-authored-by: Cursor <cursoragent@cursor.com>
114 lines
2.6 KiB
Bash
Executable File
114 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
SVXLINK_CONF="${SVXLINK_CONF:-/etc/svxlink/svxlink.conf}"
|
|
REMOTETRX_CONF="${REMOTETRX_CONF:-/etc/svxlink/remotetrx.conf}"
|
|
SVXREFLECTOR_CONF="${SVXREFLECTOR_CONF:-/etc/svxlink/svxreflector.conf}"
|
|
|
|
START_SVXLINK="${START_SVXLINK:-0}"
|
|
START_REMOTETRX="${START_REMOTETRX:-0}"
|
|
START_SVXREFLECTOR="${START_SVXREFLECTOR:-1}"
|
|
|
|
SVXLINK_ARGS="${SVXLINK_ARGS:-}"
|
|
REMOTETRX_ARGS="${REMOTETRX_ARGS:-}"
|
|
SVXREFLECTOR_ARGS="${SVXREFLECTOR_ARGS:-}"
|
|
|
|
pids=""
|
|
|
|
log() {
|
|
echo "[$(date -Iseconds)] $*"
|
|
}
|
|
|
|
die() {
|
|
log "ERROR: $*"
|
|
exit 1
|
|
}
|
|
|
|
need_file_if_enabled() {
|
|
enabled="$1"
|
|
file="$2"
|
|
name="$3"
|
|
if [ "$enabled" = "1" ] && [ ! -f "$file" ]; then
|
|
die "Config for $name not found: $file (expected volume mount)"
|
|
fi
|
|
}
|
|
|
|
start_bg() {
|
|
name="$1"
|
|
shift
|
|
log "Starting: $name -> $*"
|
|
"$@" &
|
|
pid="$!"
|
|
pids="$pids $pid"
|
|
log "$name started (pid=$pid)"
|
|
}
|
|
|
|
stop_all() {
|
|
log "Stop requested; stopping: $pids"
|
|
for pid in $pids; do
|
|
kill -TERM "$pid" 2>/dev/null || true
|
|
done
|
|
|
|
i=0
|
|
while [ $i -lt 10 ]; do
|
|
alive=0
|
|
for pid in $pids; do
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
alive=1
|
|
fi
|
|
done
|
|
[ "$alive" -eq 0 ] && break
|
|
i=$((i + 1))
|
|
sleep 1
|
|
done
|
|
|
|
for pid in $pids; do
|
|
kill -KILL "$pid" 2>/dev/null || true
|
|
done
|
|
log "Stop complete."
|
|
}
|
|
|
|
trap 'stop_all; exit 0' INT TERM
|
|
|
|
if [ "$START_SVXLINK" = "1" ] && ! command -v svxlink >/dev/null 2>&1; then
|
|
die "svxlink binary not found"
|
|
fi
|
|
if [ "$START_REMOTETRX" = "1" ] && ! command -v remotetrx >/dev/null 2>&1; then
|
|
die "remotetrx binary not found"
|
|
fi
|
|
if [ "$START_SVXREFLECTOR" = "1" ] && ! command -v svxreflector >/dev/null 2>&1; then
|
|
die "svxreflector binary not found"
|
|
fi
|
|
|
|
need_file_if_enabled "$START_SVXLINK" "$SVXLINK_CONF" "svxlink"
|
|
need_file_if_enabled "$START_REMOTETRX" "$REMOTETRX_CONF" "remotetrx"
|
|
need_file_if_enabled "$START_SVXREFLECTOR" "$SVXREFLECTOR_CONF" "svxreflector"
|
|
|
|
if [ "$START_SVXREFLECTOR" = "1" ]; then
|
|
start_bg "svxreflector" svxreflector --config "$SVXREFLECTOR_CONF" $SVXREFLECTOR_ARGS
|
|
fi
|
|
|
|
if [ "$START_REMOTETRX" = "1" ]; then
|
|
start_bg "remotetrx" remotetrx --config "$REMOTETRX_CONF" $REMOTETRX_ARGS
|
|
fi
|
|
|
|
if [ "$START_SVXLINK" = "1" ]; then
|
|
start_bg "svxlink" svxlink --config "$SVXLINK_CONF" $SVXLINK_ARGS
|
|
fi
|
|
|
|
if ! echo "$pids" | grep -q '[0-9]'; then
|
|
die "No service enabled. Set START_SVXREFLECTOR=1 (lab default) and/or START_SVXLINK / START_REMOTETRX"
|
|
fi
|
|
|
|
log "Requested services are running. Waiting…"
|
|
|
|
exit_code=0
|
|
for pid in $pids; do
|
|
if ! wait "$pid"; then
|
|
exit_code=1
|
|
fi
|
|
done
|
|
|
|
log "Exit (exit_code=$exit_code)"
|
|
exit "$exit_code"
|