Skip to content

Commit

Permalink
allow persistent directory for tar1090-update (#174)
Browse files Browse the repository at this point in the history
when recreating the container via docker compose, changes in the docker
image are lost. this means tar1090-update needs to download data again.
especially when changes to container are made via automation, this can
happen relatively often and it's desirable that the data are not
required to be downloaded more than once

change the directory for the tar1090 and tar1090-db git dirs and the
aircraft.csv.gz file to
TAR1090_UPDATE_DIR=/var/globe_history/tar1090-update

this directory is already mounted on most installs and redownloads are
avoided

the Dockerfile places aircraft.csv.gz in TAR1090_INSTALL_DIR so it can
be used in the unlikely event of /var/globe_history being mounted while
UPDATE_TAR1090 is false
  • Loading branch information
wiedehopf authored Apr 13, 2024
1 parent 5106c77 commit b17b020
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ENV BEASTPORT=30005 \
HTTP_ACCESS_LOG="false" \
HTTP_ERROR_LOG="true" \
TAR1090_INSTALL_DIR=/usr/local/share/tar1090 \
TAR1090_UPDATE_DIR=/var/globe_history/tar1090-update \
MLATPORT=30105 \
INTERVAL=8 \
HISTORY_SIZE=450 \
Expand Down Expand Up @@ -71,13 +72,15 @@ RUN set -x && \
# change some /run/tar1090-webroot to /run/readsb to make work with existing docker scripting
sed -i -e 's#/run/tar1090-webroot/#/run/readsb/#' /usr/local/share/tar1090/nginx-tar1090-webroot.conf && \
# tar1090-db: document version
pushd "${TAR1090_INSTALL_DIR}/git-db" || exit 1 && \
pushd "${TAR1090_UPDATE_DIR}/git-db" || exit 1 && \
bash -ec 'echo "tar1090-db $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \
popd && \
# tar1090: document version
pushd "${TAR1090_INSTALL_DIR}/git" || exit 1 && \
pushd "${TAR1090_UPDATE_DIR}/git" || exit 1 && \
bash -ec 'echo "tar1090 $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \
popd && \
# tar1090: remove tar1090-update files as they're not needed unless tar1090-update is active
rm -rf "${TAR1090_UPDATE_DIR}" && \
# tar1090: add nginx config
cp -Rv /etc/nginx.tar1090/* /etc/nginx/ && \
# timelapse1090
Expand All @@ -86,9 +89,8 @@ RUN set -x && \
bash -ec 'echo "timelapse1090 $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \
popd && \
mkdir -p /var/timelapse1090 && \
# aircraft-db
# 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" && \
git ls-remote https://github.com/wiedehopf/tar1090-db | grep refs/heads/csv > "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.version" && \
# clone graphs1090 repo
git clone \
-b master \
Expand Down
7 changes: 5 additions & 2 deletions rootfs/etc/s6-overlay/scripts/readsb
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ if [[ -n "$READSB_NET_VRS_PORT" ]]; then
fi

# make sure the db file exists, and if it does, use it
if [[ -e $TAR1090_INSTALL_DIR/aircraft.csv.gz ]]; then
if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then
if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then
if [[ -e $TAR1090_UPDATE_DIR/aircraft.csv.gz ]]; then
READSB_CMD+=("--db-file=$TAR1090_UPDATE_DIR/aircraft.csv.gz")
elif [[ -e $TAR1090_INSTALL_DIR/aircraft.csv.gz ]]; then
# fallback to container supplied not updated csv.gz
READSB_CMD+=("--db-file=$TAR1090_INSTALL_DIR/aircraft.csv.gz")
fi
fi
Expand Down
10 changes: 5 additions & 5 deletions rootfs/etc/s6-overlay/startup.d/02-tar1090-update
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ fi
# aircraft-db
if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then
git ls-remote https://github.com/wiedehopf/tar1090-db | grep refs/heads/csv > "/run/aircraft.csv.gz.version.new"
if ! diff -q "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.version" "/run/aircraft.csv.gz.version.new" &>/dev/null; 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 --silent --show-error -o "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.tmp" "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz"; then
mv -f "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.tmp" "${TAR1090_INSTALL_DIR}/aircraft.csv.gz"
mv -f "/run/aircraft.csv.gz.version.new" "${TAR1090_INSTALL_DIR}/aircraft.csv.gz.version"
if curl --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
pushd "${TAR1090_INSTALL_DIR}/git" >/dev/null || exit 1
pushd "${TAR1090_UPDATE_DIR}/git" >/dev/null || exit 1
if [[ -z "$TAR1090_VERSION" ]]; then
TAR1090_VERSION=$(git rev-parse --short HEAD)
fi
Expand Down
30 changes: 17 additions & 13 deletions rootfs/tar1090-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ lighttpd=no
nginx=no
function useSystemd () { command -v systemd &>/dev/null; }

gpath="$TAR1090_UPDATE_DIR"
if [[ -z "$gpath" ]]; then gpath="$ipath"; fi

mkdir -p "$ipath"
mkdir -p "$gpath"

if useSystemd && ! id -u tar1090 &>/dev/null
then
Expand Down Expand Up @@ -85,8 +89,8 @@ fi

dir=$(pwd)

if (( $( { du -s "$ipath/git-db" 2>/dev/null || echo 0; } | cut -f1) > 150000 )); then
rm -rf "$ipath/git-db"
if (( $( { du -s "$gpath/git-db" 2>/dev/null || echo 0; } | cut -f1) > 150000 )); then
rm -rf "$gpath/git-db"
fi

function getGIT() {
Expand All @@ -106,11 +110,11 @@ function revision() {
git rev-parse --short HEAD 2>/dev/null || echo "$RANDOM-$RANDOM"
}

if ! { [[ "$1" == "test" ]] && cd "$ipath/git-db"; }; then
getGIT "$db_repo" "master" "$ipath/git-db" || true
if ! { [[ "$1" == "test" ]] && cd "$gpath/git-db"; }; then
getGIT "$db_repo" "master" "$gpath/git-db" || true
fi

if ! cd "$ipath/git-db"
if ! cd "$gpath/git-db"
then
echo "Unable to download files, exiting! (Maybe try again?)"
exit 1
Expand All @@ -121,17 +125,17 @@ DB_VERSION=$(revision)
cd "$dir"

if [[ "$1" == "test" ]] || [[ -n "$git_source" ]]; then
mkdir -p "$ipath/git"
rm -rf "$ipath/git"/* || true
mkdir -p "$gpath/git"
rm -rf "$gpath/git"/* || true
if [[ -n "$git_source" ]]; then
cp -r "$git_source"/* "$ipath/git"
cp -r "$git_source"/* "$gpath/git"
else
cp -r ./* "$ipath/git"
cp -r ./* "$gpath/git"
fi
cd "$ipath/git"
cd "$gpath/git"
TAR_VERSION="$(date +%s)_${RANDOM}${RANDOM}"
else
if ! getGIT "$repo" "master" "$ipath/git" || ! cd "$ipath/git"
if ! getGIT "$repo" "master" "$gpath/git" || ! cd "$gpath/git"
then
echo "Unable to download files, exiting! (Maybe try again?)"
exit 1
Expand Down Expand Up @@ -274,7 +278,7 @@ do
sed -i.orig -e "s?SOURCE_DIR?$srcdir?g" -e "s?SERVICE?${service}?g" tar1090.service

cp -r -T html "$TMP"
cp -r -T "$ipath/git-db/db" "$TMP/db-$DB_VERSION"
cp -r -T "$gpath/git-db/db" "$TMP/db-$DB_VERSION"
sed -i -e "s/let databaseFolder = .*;/let databaseFolder = \"db-$DB_VERSION\";/" "$TMP/index.html"
echo "{ \"tar1090Version\": \"$TAR_VERSION\", \"databaseVersion\": \"$DB_VERSION\" }" > "$TMP/version.json"

Expand Down Expand Up @@ -306,7 +310,7 @@ do

sed -i -e "s/tar1090 on github/tar1090 on github ($(date +%y%m%d))/" index.html

"$ipath/git/cachebust.sh" "$ipath/git/cachebust.list" "$TMP"
"$gpath/git/cachebust.sh" "$gpath/git/cachebust.list" "$TMP"

rm -rf "$html_path"
mv "$TMP" "$html_path"
Expand Down

0 comments on commit b17b020

Please sign in to comment.