From 5bdcf9d0ee119e16d0cd9299c78bebdd7bcda5f6 Mon Sep 17 00:00:00 2001 From: kx1t Date: Wed, 24 Jul 2024 12:29:23 -0400 Subject: [PATCH] move cleanup_globe_history from ultrafeeder container to tar1090 container --- README.md | 1 + .../dependencies.d/startup | 0 .../s6-rc.d/cleanup_globe_history/run | 2 + .../s6-rc.d/cleanup_globe_history/type | 1 + .../user/contents.d/cleanup_globe_history | 0 .../s6-overlay/scripts/cleanup_globe_history | 47 +++++++++++++++++++ 6 files changed, 51 insertions(+) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/dependencies.d/startup create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/type create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/cleanup_globe_history create mode 100755 rootfs/etc/s6-overlay/scripts/cleanup_globe_history diff --git a/README.md b/README.md index 2721fe1..785f1fa 100644 --- a/README.md +++ b/README.md @@ -458,6 +458,7 @@ Where the default value is "Unset", `readsb`'s default will be used. | `READSB_STATS_EVERY` | Number of seconds between showing and resetting stats. | `--stats-every=` | Unset | | `READSB_STATS_RANGE` | Set this to any value to collect range statistics for polar plot. | `--stats-range` | Unset | | `READSB_RANGE_OUTLINE_HOURS` | Change which past timeframe the range outline is based on | `--range-outline-hours` | `24` | +| `MAX_GLOBE_HISTORY` | Maximum number of days that `globe_history` data (used to produce heatmaps and ptracks) is retained. Note - this parameter doesn't affect the data used to produce `graphs1090` statistics | | Unset | ### AutoGain for RTLSDR Devices diff --git a/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/dependencies.d/startup b/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/dependencies.d/startup new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/run b/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/run new file mode 100755 index 0000000..ea60751 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/cleanup_globe_history diff --git a/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/type b/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/cleanup_globe_history/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/cleanup_globe_history b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/cleanup_globe_history new file mode 100755 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/scripts/cleanup_globe_history b/rootfs/etc/s6-overlay/scripts/cleanup_globe_history new file mode 100755 index 0000000..3a5b4cf --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/cleanup_globe_history @@ -0,0 +1,47 @@ +#!/command/with-contenv bash +# shellcheck shell=bash disable=SC2015,SC2016,SC1091,SC2001,SC2154 + +#--------------------------------------------------------------------------------------------- +# Script to remove Globe_History files older than xxx days - this to ensure that the disk +# doesn't fill up with (unwanted) history files) + +# Copyright (C) 2023-2024, Ramon F. Kolb (kx1t) and contributors +# Core script copyright and provided by Matthias Wirth (wiedehopf), used with permission +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . +#--------------------------------------------------------------------------------------------- + +source /scripts/common + +if [[ -z "$MAX_GLOBE_HISTORY" ]]; then + "${s6wrap[@]}" echo "MAX_GLOBE_HISTORY not set - we will not expire any globe_history files" + exec sleep infinity +fi + +cutoffepoch="$(date -d"-${MAX_GLOBE_HISTORY} days" +%s)" + +"${s6wrap[@]}" echo "Purging globe_history older than $MAX_GLOBE_HISTORY days (before $(date -d"-${MAX_GLOBE_HISTORY} days" +%d-%b-%Y))" +for dir in $(find /var/globe_history -maxdepth 3 -mindepth 3 -type d | grep -o -E -e '[0-9]{4}/[0-9]{2}/[0-9]{2}$'); do + if (( $(date -d "$dir" +%s) < cutoffepoch )); then + "${s6wrap[@]}" echo Removing "/var/globe_history/$dir" + rm -rf "/var/globe_history/$dir" + fi +done + +# delete empty year / month directories +# make sure the directories haven't been touched for 3 days so freshly created directories aren't removed +# this will also delay deletion of empty parent directories by 3 days after their contents have been removed but that's fine +find /var/globe_history/ -mindepth 1 -maxdepth 2 -type d -empty -mtime +3 -delete + +"${s6wrap[@]}" echo "Done - next purge will be in 24 hours" +exec sleep 24h