diff --git a/Dockerfile b/Dockerfile index 385f6ab..8991fa1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index bd52a26..c15825d 100644 --- a/README.md +++ b/README.md @@ -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` | diff --git a/rootfs/etc/nginx.tar1090/sites-enabled/tar1090 b/rootfs/etc/nginx.tar1090/sites-enabled/tar1090 index 2683136..76b04c5 100644 --- a/rootfs/etc/nginx.tar1090/sites-enabled/tar1090 +++ b/rootfs/etc/nginx.tar1090/sites-enabled/tar1090 @@ -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/; diff --git a/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/dependencies.d/startup b/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/dependencies.d/startup new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/run b/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/run new file mode 100755 index 0000000..e74e3ef --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/tar1090-update diff --git a/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/type b/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/tar1090-update/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/scripts/collectd b/rootfs/etc/s6-overlay/scripts/collectd index d3b1efb..c690e89 100755 --- a/rootfs/etc/s6-overlay/scripts/collectd +++ b/rootfs/etc/s6-overlay/scripts/collectd @@ -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 diff --git a/rootfs/etc/s6-overlay/scripts/tar1090-update b/rootfs/etc/s6-overlay/scripts/tar1090-update new file mode 100755 index 0000000..7574fb7 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/tar1090-update @@ -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 )) diff --git a/rootfs/etc/s6-overlay/startup.d/01-sanity-check b/rootfs/etc/s6-overlay/startup.d/01-sanity-check index f38bc55..642ce69 100755 --- a/rootfs/etc/s6-overlay/startup.d/01-sanity-check +++ b/rootfs/etc/s6-overlay/startup.d/01-sanity-check @@ -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 diff --git a/rootfs/etc/s6-overlay/startup.d/02-tar1090-update b/rootfs/etc/s6-overlay/startup.d/02-tar1090-update deleted file mode 100755 index 47f40fc..0000000 --- a/rootfs/etc/s6-overlay/startup.d/02-tar1090-update +++ /dev/null @@ -1,35 +0,0 @@ -#!/command/with-contenv bash -# shellcheck shell=bash disable=SC1091 - -source /scripts/common - -if ! chk_enabled "${UPDATE_TAR1090}" || chk_enabled "${TAR1090_DISABLE}"; then - exit 0 -fi - -OVERRIDE_GIT_SOURCE="/var/tar1090_git_source" - -if [[ -d "${OVERRIDE_GIT_SOURCE}/html" ]]; then - echo "USING LOCALLY MODIFIED TAR1090 from ${OVERRIDE_GIT_SOURCE}" - bash /tar1090-install.sh /run/readsb webroot "${TAR1090_INSTALL_DIR}" "${OVERRIDE_GIT_SOURCE}" - TAR1090_VERSION="$(cat "${OVERRIDE_GIT_SOURCE}/version") LOCALLY MODIFIED" -else - 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 2 --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 - echo "Downloading https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz" - if curl --connect-timeout 2 --silent --show-error -o "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.tmp" "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz"; then - mv -f "${TAR1090_UPDATE_DIR}/aircraft.csv.gz.tmp" "${TAR1090_UPDATE_DIR}/aircraft.csv.gz" - 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") -echo "tar1090 version: ${TAR1090_VERSION} tar1090-db version: ${TAR1090_DB_VERSION}" -export TAR1090_VERSION diff --git a/rootfs/etc/s6-overlay/startup.d/04-tar1090-configure b/rootfs/etc/s6-overlay/startup.d/04-tar1090-configure index 901bbf3..8c25900 100755 --- a/rootfs/etc/s6-overlay/startup.d/04-tar1090-configure +++ b/rootfs/etc/s6-overlay/startup.d/04-tar1090-configure @@ -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 History: n/a positions\)|\1\2\n\1\n\1Stats available here|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. diff --git a/rootfs/etc/s6-overlay/startup.d/07-nginx-configure b/rootfs/etc/s6-overlay/startup.d/07-nginx-configure new file mode 100755 index 0000000..0d15e9f --- /dev/null +++ b/rootfs/etc/s6-overlay/startup.d/07-nginx-configure @@ -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 diff --git a/rootfs/etc/s6-overlay/startup.d/07-ngnix-logging b/rootfs/etc/s6-overlay/startup.d/07-ngnix-logging deleted file mode 100755 index 6e5e4f9..0000000 --- a/rootfs/etc/s6-overlay/startup.d/07-ngnix-logging +++ /dev/null @@ -1,20 +0,0 @@ -#!/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 diff --git a/rootfs/etc/s6-overlay/startup.d/08-graphs1090-init b/rootfs/etc/s6-overlay/startup.d/08-graphs1090-init index 1eddd92..6f6f5a8 100755 --- a/rootfs/etc/s6-overlay/startup.d/08-graphs1090-init +++ b/rootfs/etc/s6-overlay/startup.d/08-graphs1090-init @@ -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 @@ -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 History: n/a positions\)|\1\2\n\1\n\1Stats available here|g' "$TAR1090_INDEX_HTML" -fi diff --git a/rootfs/tar1090-install.sh b/rootfs/tar1090-install.sh index 75f2599..fd6e990 100755 --- a/rootfs/tar1090-install.sh +++ b/rootfs/tar1090-install.sh @@ -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