Skip to content

Commit

Permalink
logging updates (#75)
Browse files Browse the repository at this point in the history
* logging updates

* linter fix

* minor fix for consistency
  • Loading branch information
kx1t authored Oct 11, 2023
1 parent ad59eb9 commit d8f4924
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion rootfs/etc/s6-overlay/scripts/01-timezone
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Set up timezone
if [ -z "${TZ}" ]; then
echo "WARNING: TZ environment variable not set"
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args echo "WARNING: TZ environment variable not set"
else
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
fi
9 changes: 8 additions & 1 deletion rootfs/etc/s6-overlay/scripts/02-sanity-check
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ if [[ "$DUMP978_DEVICE_TYPE" == "rtlsdr" ]]; then
# If we have more than one device, we need a serial number
if [[ "$num_devices" -gt 1 ]]; then
if [[ -z "$DUMP978_RTLSDR_DEVICE" ]]; then
echo -e "${NOCOLOR}ERROR: Multiple RTL-SDR devices present. Please set DUMP978_RTLSDR_DEVICE!${LIGHTRED}"
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args echo -e "${NOCOLOR}ERROR: Multiple RTL-SDR devices present. Please set DUMP978_RTLSDR_DEVICE!${LIGHTRED}"
EXITCODE=1
fi
fi
rm "$biast_tempfile"
fi

# Ensure viewadsb exists:
if [[ ! -f /usr/local/bin/viewadsb ]]; then
echo '#!/bin/bash' > /usr/local/bin/viewadsb
echo '/usr/bin/readsb --interactive --net --net-only --net-connector 127.0.0.1,30978,uat_in $@' >> /usr/local/bin/viewadsb
chmod a+x /usr/local/bin/viewadsb
fi

exit $EXITCODE
5 changes: 2 additions & 3 deletions rootfs/etc/s6-overlay/scripts/autogain
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ if [[ -n "$DUMP978_SDR_GAIN" ]]; then

# Run autogain
#shellcheck disable=SC2016
bash /scripts/autogain.sh 2>&1 | stdbuf -o0 awk '{print "[autogain] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'

s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args bash /scripts/autogain.sh
# Sleep for 15 mins
sleep "$AUTOGAIN_SERVICE_PERIOD"

fi

else
sleep 86400
sleep infinity
fi
17 changes: 5 additions & 12 deletions rootfs/etc/s6-overlay/scripts/dump978
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/command/with-contenv bash
#shellcheck shell=bash

s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args)

# Set readsb binary
DUMP978_BIN="/usr/local/bin/dump978-fa"

Expand All @@ -12,14 +14,6 @@ DUMP978_CMD+=("--json-port" "0.0.0.0:30979")

DUMP978_CMD+=("--format" "CS8")

# Ensure viewadsb exists:
if [[ ! -f /usr/local/bin/viewadsb ]]; then
echo '#!/bin/bash' > /usr/local/bin/viewadsb
# shellcheck disable=SC2145
echo '/usr/bin/readsb --interactive --net --net-only --net-connector 127.0.0.1,30978,uat_in $@' >> /usr/local/bin/viewadsb
chmod a+x /usr/local/bin/viewadsb
fi

# Handle "--sdr"
if [[ -n "${DUMP978_DEVICE_TYPE:-rtlsdr}" ]]; then
case "${DUMP978_DEVICE_TYPE:-rtlsdr}" in
Expand All @@ -34,13 +28,13 @@ if [[ -n "${DUMP978_DEVICE_TYPE:-rtlsdr}" ]]; then
if [[ -n "${DUMP978_STRATUXV3_DEVICE}" ]]; then
DUMP978_CMD+=("--stratuxv3" "${DUMP978_STRATUXV3_DEVICE}")
else
>&2 echo "ERROR: Please set DUMP978_STRATUXV3_DEVICE!"
"${s6wrap[@]}" echo "ERROR: Please set DUMP978_STRATUXV3_DEVICE!"
sleep 60
exit 1
fi
;;
*)
>&2 echo "ERROR: Unsupported DUMP978_DEVICE_TYPE!"
"${s6wrap[@]}" echo "ERROR: Unsupported DUMP978_DEVICE_TYPE!"
sleep 60
exit 1
;;
Expand Down Expand Up @@ -70,7 +64,6 @@ fi
set -eo pipefail

# shellcheck disable=SC2016
"${DUMP978_BIN}" "${DUMP978_CMD[@]}" \
2>&1 | stdbuf -o0 sed --unbuffered '/^$/d' | stdbuf -o0 awk '{print "[dump978] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
exec "${s6wrap[@]}" "${DUMP978_BIN}" "${DUMP978_CMD[@]}"

sleep 5
10 changes: 4 additions & 6 deletions rootfs/etc/s6-overlay/scripts/lighttpd
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ chown -R nobody /var/log/lighttpd

# Launch webapp unless disabled
if [[ -z "$DISABLE_WEBAPP" ]]; then
s6-setuidgid nobody /usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf || exit 0

s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args s6-setuidgid nobody /usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf || exit 0
set -eo pipefail

#shellcheck disable=SC2016
s6-setuidgid nobody /usr/sbin/lighttpd \
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args s6-setuidgid nobody /usr/sbin/lighttpd \
-f /etc/lighttpd/lighttpd.conf \
-D \
2>&1 | stdbuf -o0 awk '{print "[lighttpd] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
-D

# If webapp disabled, sleep forever
else
sleep 86400
sleep infinity
fi
3 changes: 1 addition & 2 deletions rootfs/etc/s6-overlay/scripts/readsb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ set -eo pipefail
sleep 2

# shellcheck disable=SC2016
readsb --net-only --net --quiet --net-connector 127.0.0.1,30978,uat_in --net-ro-port 37981 --net-bo-port 37982 \
2>&1 | stdbuf -o0 sed --unbuffered '/^$/d' | stdbuf -o0 awk '{print "[readsb] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args readsb --net-only --net --quiet --net-connector 127.0.0.1,30978,uat_in --net-ro-port 37981 --net-bo-port 37982
3 changes: 1 addition & 2 deletions rootfs/etc/s6-overlay/scripts/skyaware978
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ if [[ -n "${LON}" ]] && [[ -n "${LAT}" ]]; then
fi

# shellcheck disable=SC2016,SC2086
skyaware978 --json-dir /run/skyaware978 --connect 127.0.0.1:30978 --reconnect-interval 30 --history-count 180 --history-interval 15 ${optstr} \
2>&1 | stdbuf -o0 awk '{print "[skyware] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args skyaware978 --json-dir /run/skyaware978 --connect 127.0.0.1:30978 --reconnect-interval 30 --history-count 180 --history-interval 15 ${optstr}
3 changes: 1 addition & 2 deletions rootfs/etc/s6-overlay/scripts/stats
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ set -eo pipefail
sleep 5

# shellcheck disable=SC2016
python3 -u /scripts/stats.py \
2>&1 | stdbuf -o0 sed --unbuffered '/^$/d' | stdbuf -o0 awk '{print "[stats] " strftime("%Y/%m/%d %H:%M:%S", systime()) " " $0}'
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args python3 -u /scripts/stats.py
5 changes: 2 additions & 3 deletions rootfs/etc/s6-overlay/scripts/telegraf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ set -eo pipefail
if [[ -n "$INFLUXDBURL" ]] || [ -n "$ENABLE_PROMETHEUS" ]; then

#shellcheck disable=SC2016
telegraf \
exec s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args telegraf \
--config /etc/telegraf/telegraf.conf \
--config-directory /etc/telegraf/telegraf.d \
2>&1 | stdbuf -o0 awk '{print "[telegraf] " $0}'

else
sleep 86400
sleep infinity
fi
5 changes: 2 additions & 3 deletions rootfs/etc/s6-overlay/scripts/telegraf_socat
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ if [ -z "$INFLUXDB_SKIP_AIRCRAFT" ] && { [ -n "$INFLUXDBURL" ] || [ -n "$ENABLE_
SOCAT_CMD+=("TCP:localhost:33979")

# shellcheck disable=SC2016
"${SOCAT_BIN}" "${SOCAT_CMD[@]}" \
2>&1 | stdbuf -o0 awk '{print "[telegraf_socat] " $0}'
s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args "${SOCAT_BIN}" "${SOCAT_CMD[@]}"

else
sleep 86400
sleep infinity
fi
2 changes: 1 addition & 1 deletion rootfs/scripts/healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ else
fi

##### Service Death Counts #####
#shellcheck disable=SC2206
# shellcheck disable=SC2207
services=($(find /etc/services.d/* -type d | awk -F'/' '{print $4}'| xargs))

# For each service...
Expand Down

0 comments on commit d8f4924

Please sign in to comment.