add TPOT_PERSISTENCE_CYCLES setting

- makes logrotate cycles configurable, instead of static 30 days
- adjust .env / env.example for setting cycles
- adjust tpotinit dockerfile to include envsubst
- add logrotate.template
- add checks / validations
This commit is contained in:
t3chn0m4g3
2025-05-13 15:32:00 +02:00
parent 3372a23eb2
commit 9455877fa3
6 changed files with 130 additions and 3 deletions

View File

@ -10,6 +10,9 @@ myPIGZ=$(which pigz)
# Set persistence
myPERSISTENCE=$1
myPERSISTENCE_CYCLES=$2
myPERSISTENCE_CYCLES="${myPERSISTENCE_CYCLES:=30}"
export myPERSISTENCE_CYCLES
# Let's create a function to check if folder is empty
fuEMPTY () {
@ -18,6 +21,15 @@ fuEMPTY () {
echo $(ls $myFOLDER | wc -l)
}
# Let's create a function to setup logrotate config
fuLOGROTATECONF () {
local myLOGROTATECONF="/opt/tpot/etc/logrotate/logrotate.conf"
local myLOGROTATETEMP="/opt/tpot/etc/logrotate/logrotate.template"
envsubst < $myLOGROTATETEMP > $myLOGROTATECONF
chown root:root $myLOGROTATECONF
chmod 0600 $myLOGROTATECONF
}
# Let's create a function to rotate and compress logs
fuLOGROTATE () {
local mySTATUS="/data/tpot/etc/logrotate/status"
@ -43,6 +55,9 @@ fuLOGROTATE () {
local myTANNERF="/data/tanner/files/"
local myTANNERFTGZ="/data/tanner/files.tgz"
# Setup logrotate config
fuLOGROTATECONF
# Ensure correct permissions and ownerships for logrotate to run without issues
chmod 770 /data/ -R
chown tpot:tpot /data -R
@ -408,7 +423,7 @@ fi
# Check persistence, if enabled compress and rotate logs
if [ "$myPERSISTENCE" = "on" ];
then
echo "Persistence enabled, now rotating and compressing logs."
echo "Persistence enabled for $myPERSISTENCE_CYCLES cycles, now rotating and compressing logs."
fuLOGROTATE
fi