Skip to content

Commit

Permalink
tar1090-update improvements (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf authored Nov 10, 2024
1 parent 507abbf commit 1f1392b
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 97 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ RUN \
rm -rf "${TAR1090_UPDATE_DIR}" && \
# tar1090: add nginx config
cp -Rv /app/rootfs/etc/nginx.tar1090/* /etc/nginx/ && \
# copy nginx config out of tar1090 install directory which might be updated while the container is running
cp -v "${TAR1090_INSTALL_DIR}/nginx-tar1090-webroot.conf" /etc/nginx/ && \
# aircraft-db, file in TAR1090_UPDATE_DIR will be preferred when starting readsb if tar1090-update enabled
curl -o "${TAR1090_INSTALL_DIR}/aircraft.csv.gz" "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz" && \
# clone graphs1090 repo
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ All of the variables below are optional.
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- |
| `READSB_JSON_INTERVAL` | Update data update interval for the webinterface in seconds | `1.0` |
| `UPDATE_TAR1090` | At startup update tar1090 and tar1090db to the latest versions | `true` |
| `UPDATE_TAR1090_DAYS` | Every X days update tar1090 and tar1090db to the latest versions | disabled |
| `INTERVAL` | Interval at which the track history is saved | `8` |
| `HISTORY_SIZE` | How many points in time are stored in the track history | `450` |
| `URL_978` | The URL needs to point at where your skyaware978 webinterface is located, this will also enable UAT-specific graphs in graphs1090 | `http://dump978/skyaware978` |
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/nginx.tar1090/sites-enabled/tar1090
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server {
listen 80 default_server;
root /var/www/html;
server_name _;
include /usr/local/share/tar1090/nginx-tar1090-webroot.conf;
include /etc/nginx/nginx-tar1090-webroot.conf;

location /timelapse {
alias /opt/timelapse1090/html/;
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/tar1090-update
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
10 changes: 5 additions & 5 deletions rootfs/etc/s6-overlay/scripts/collectd
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ elif [[ -f "${PERMFILE}" ]] && ! [[ -d /var/lib/collectd/rrd/localhost ]]; then
fi


# test config?
/usr/sbin/collectd -t -T -f -C /etc/collectd/collectd.conf > /dev/null 2>&1

# wait for necessary input file to exist before starting

loop_count=0
# shellcheck disable=SC2016
while [[ ! -e /usr/share/graphs1090/data-symlink/data/stats.json ]]; do
if (( loop_count++ > 30 )); then echo "[collectd] Waiting for readsb to start..."; sleep 9; fi
if (( loop_count++ > 15 )); then echo "[collectd] Waiting for readsb to start..."; fi
if (( loop_count > 30 )); then echo "[collectd] not waiting for readsb any longer"; break; fi
sleep 1
done

# test config?
/usr/sbin/collectd -t -T -f -C /etc/collectd/collectd.conf > /dev/null 2>&1


# pkill -P $$ will only kill children of the script, not the script itself
trap 'pkill -P $$' SIGTERM SIGINT SIGHUP SIGQUIT
# for this scheme to work, the program is started in the background
Expand Down
47 changes: 47 additions & 0 deletions rootfs/etc/s6-overlay/scripts/tar1090-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091,SC2154

source /scripts/common

if ! chk_enabled "${UPDATE_TAR1090}" || chk_enabled "${TAR1090_DISABLE}"; then
stop_service
fi

OVERRIDE_GIT_SOURCE="/var/tar1090_git_source"

if [[ -d "${OVERRIDE_GIT_SOURCE}/html" ]]; then
"${s6wrap[@]}" echo "USING LOCALLY MODIFIED TAR1090 from ${OVERRIDE_GIT_SOURCE}"
"${s6wrap[@]}" bash /tar1090-install.sh /run/readsb webroot "${TAR1090_INSTALL_DIR}" "${OVERRIDE_GIT_SOURCE}"
TAR1090_VERSION="$(cat "${OVERRIDE_GIT_SOURCE}/version") LOCALLY MODIFIED"
else
"${s6wrap[@]}" bash /tar1090-install.sh /run/readsb webroot "${TAR1090_INSTALL_DIR}"
TAR1090_VERSION=$(cat "${TAR1090_UPDATE_DIR}/git/version")
fi

# aircraft-db
if chk_enabled "$TAR1090_ENABLE_AC_DB" && curl --connect-timeout 10 --silent --show-error "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/version" > "/run/aircraft.csv.gz.version.new"; then
if ! diff -q "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.version" "/run/aircraft.csv.gz.version.new" &>/dev/null; then
"${s6wrap[@]}" echo "Downloading https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz"
if "${s6wrap[@]}" curl --connect-timeout 10 --silent --show-error -o "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.tmp" \
"https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz"; then
"${s6wrap[@]}" mv -f "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.tmp" "${TAR1090_UPDATE_DIR}/aircraft.csv.gz"
"${s6wrap[@]}" mv -f "/run/aircraft.csv.gz.version.new" "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.version"
fi
fi
fi

# Print tar1090 version
TAR1090_DB_VERSION=$(cat "${TAR1090_UPDATE_DIR}/git-db/version")
"${s6wrap[@]}" echo "tar1090 version: ${TAR1090_VERSION} tar1090-db version: ${TAR1090_DB_VERSION}"
export TAR1090_VERSION

# call the necessary scripts to configure the newly created tar1090 html folder
# they were already run on container startup but there is no harm in running them again
"${s6wrap[@]}" bash /etc/s6-overlay/startup.d/04-tar1090-configure
"${s6wrap[@]}" bash /etc/s6-overlay/startup.d/06-range-outline

if (( UPDATE_TAR1090_DAYS == 0 )); then
stop_service
fi

exec sleep $(( UPDATE_TAR1090_DAYS * 86400 ))
3 changes: 2 additions & 1 deletion rootfs/etc/s6-overlay/startup.d/01-sanity-check
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ NOCOLOR='\033[0m'

# Check to make sure the correct command line arguments have been set
EXITCODE=0
if [ -z "${BEASTHOST}" ] && [ -z "${MLATHOST}" ] && [ -z "${READSB_DEVICE_TYPE}" ] && [ -z "${READSB_NET_CONNECTOR}" ]; then
if [ -z "${BEASTHOST}" ] && [ -z "${MLATHOST}" ] && [ -z "${READSB_DEVICE_TYPE}" ] && [ -z "${READSB_NET_CONNECTOR}" ] \
&& ! grep -qs -e 'adsb[^;]*_in' <<< "${ULTRAFEEDER_CONFIG}${ULTRAFEEDER_NET_CONNECTOR}"; then
echo -e "${YELLOW}WARNING: No obvious data input configured: BEASTHOST / MLATHOST / READSB_NET_CONNECTOR / READSB_DEVICE_TYPE environment variables not set${NOCOLOR}"
fi
if [ -z "${LAT}" ] && [ -z "${READSB_LAT}" ]; then
Expand Down
35 changes: 0 additions & 35 deletions rootfs/etc/s6-overlay/startup.d/02-tar1090-update

This file was deleted.

35 changes: 6 additions & 29 deletions rootfs/etc/s6-overlay/startup.d/04-tar1090-configure
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,17 @@ source /scripts/common


if chk_enabled "${TAR1090_DISABLE}"; then
rm -f /etc/nginx/sites-enabled/tar1090
exit 0
fi


# create symlink so /var/cache/fontconfig is in tmpfs
# as per Wiedehopf - https://discord.com/channels/734090820684349521/1102603003376177172/1203826726023729162
# shellcheck disable=SC2174
mkdir -p -m 777 /run/cache/fontconfig
rm -rf /var/cache/fontconfig
ln -sf /run/cache/fontconfig /var/cache/fontconfig

if chk_enabled "${READSB_ENABLE_API}"; then
# shellcheck disable=SC2016
sed -i -e 's|#sed_placeholder_API_proxy|location /re-api/ {\
gzip on;\
proxy_http_version 1.1;\
proxy_max_temp_file_size 0;\
proxy_set_header Connection $http_connection;\
proxy_set_header Host $http_host;\
proxy_pass http://unix:/run/readsb/api.sock:/$is_args$args;\
}|' /etc/nginx/sites-enabled/tar1090
else
cp -Tf /etc/nginx.tar1090/sites-enabled/tar1090 /etc/nginx/sites-enabled/tar1090
if ! chk_enabled "${GRAPHS1090_DISABLE}"; then
# add a link to graphs1090 to the tar1090 web page:
TAR1090_INDEX_HTML="/usr/local/share/tar1090/html-webroot/index.html"
if ! grep -qs -e 'Stats available <a href=' "$TAR1090_INDEX_HTML"; then
sed -i 's|\(\s*\)\(<td id="dump1090_total_history_td"><span class="infoBlockTitleText">History:</span> <span id="dump1090_total_history">n/a</span> positions</td>\)|\1\2\n\1</tr>\n\1<tr class="infoblock_body"><td style="width: 50%"><span class="infoBlockTitleText">Stats available <a href="graphs1090/">here</a></td>|g' "$TAR1090_INDEX_HTML"
fi
fi

# Add in CORS header for tar1090 data/aircraft.json file
# adjust the tar1090 runtime directory to /run/tar1090

sed -i \
-e 's/location ~ aircraft\\.json$ {/location ~ aircraft\.json$ {\n add_header Access-Control-Allow-Origin "\*";/g' \
-e 's#/run/tar1090-webroot/#/run/tar1090/#' \
"${TAR1090_INSTALL_DIR}/nginx-tar1090-webroot.conf"


# Wipe and configure tar1090 config.js.

Expand Down
47 changes: 47 additions & 0 deletions rootfs/etc/s6-overlay/startup.d/07-nginx-configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091

source /scripts/common

if ! chk_enabled "${HTTP_ACCESS_LOG}"; then
# shellcheck disable=SC1003
sed -i 's\access_log .*\access_log off;\' /etc/nginx/nginx.conf
else
# shellcheck disable=SC1003
sed -i 's\access_log .*\access_log /dev/stdout;\' /etc/nginx/nginx.conf
fi

if ! chk_enabled "${HTTP_ERROR_LOG}"; then
# shellcheck disable=SC1003
sed -i 's\error_log .*\error_log /dev/null crit;\' /etc/nginx/nginx.conf
else
# shellcheck disable=SC1003
sed -i 's\error_log .*\error_log /dev/stdout notice;\' /etc/nginx/nginx.conf
fi


# Add in CORS header for tar1090 data/aircraft.json file
# adjust the tar1090 runtime directory to /run/tar1090

sed -i \
-e 's/location ~ aircraft\\.json$ {/location ~ aircraft\.json$ {\n add_header Access-Control-Allow-Origin "\*";/g' \
-e 's#/run/tar1090-webroot/#/run/tar1090/#' \
"/etc/nginx/nginx-tar1090-webroot.conf"

if chk_enabled "${TAR1090_DISABLE}"; then
rm -f /etc/nginx/sites-enabled/tar1090
fi

if chk_enabled "${READSB_ENABLE_API}"; then
# shellcheck disable=SC2016
sed -i -e 's|#sed_placeholder_API_proxy|location /re-api/ {\
gzip on;\
proxy_http_version 1.1;\
proxy_max_temp_file_size 0;\
proxy_set_header Connection $http_connection;\
proxy_set_header Host $http_host;\
proxy_pass http://unix:/run/readsb/api.sock:/$is_args$args;\
}|' /etc/nginx/sites-enabled/tar1090
else
cp -Tf /etc/nginx.tar1090/sites-enabled/tar1090 /etc/nginx/sites-enabled/tar1090
fi
20 changes: 0 additions & 20 deletions rootfs/etc/s6-overlay/startup.d/07-ngnix-logging

This file was deleted.

13 changes: 7 additions & 6 deletions rootfs/etc/s6-overlay/startup.d/08-graphs1090-init
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ if chk_enabled "${GRAPHS1090_DISABLE}"; then
exit 0
fi

# create symlink so /var/cache/fontconfig is in tmpfs
# as per Wiedehopf - https://discord.com/channels/734090820684349521/1102603003376177172/1203826726023729162
# shellcheck disable=SC2174
mkdir -p -m 777 /run/cache/fontconfig
rm -rf /var/cache/fontconfig
ln -sf /run/cache/fontconfig /var/cache/fontconfig

if chk_enabled "${GRAPHS1090_HIDE_SYSTEM}" ; then
sed -i "s|HIDE_SYSTEM=.*|HIDE_SYSTEM=yes|g" /etc/default/graphs1090
cp /usr/share/graphs1090/git/hide_system-collectd.conf /etc/collectd/collectd.conf
Expand Down Expand Up @@ -216,9 +223,3 @@ fi
if [[ -n "$GRAPHS1090_DEFAULT_APPEND" ]]; then
echo "$GRAPHS1090_DEFAULT_APPEND" >> /etc/default/graphs1090
fi

# Finally, add a link to graphs1090 to the tar1090 web page:
TAR1090_INDEX_HTML="/usr/local/share/tar1090/html-webroot/index.html"
if ! grep -qs -e 'Stats available <a href=' "$TAR1090_INDEX_HTML"; then
sed -i 's|\(\s*\)\(<td id="dump1090_total_history_td"><span class="infoBlockTitleText">History:</span> <span id="dump1090_total_history">n/a</span> positions</td>\)|\1\2\n\1</tr>\n\1<tr class="infoblock_body"><td style="width: 50%"><span class="infoBlockTitleText">Stats available <a href="graphs1090/">here</a></td>|g' "$TAR1090_INDEX_HTML"
fi
1 change: 1 addition & 0 deletions rootfs/tar1090-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ if ! diff tar1090.sh "$ipath"/tar1090.sh &>/dev/null; then
systemctl stop "$service" 2>/dev/null || true
fi
done < <(echo "$instances")
rm -f "$ipath"/tar1090.sh
cp tar1090.sh "$ipath"
fi

Expand Down

0 comments on commit 1f1392b

Please sign in to comment.