fix: Ensure main log file is tailed from the start (#4146)

Co-authored-by: Casper <casperklein@users.noreply.github.com>
This commit is contained in:
Brennan Kinney 2024-08-03 12:04:21 +12:00 committed by GitHub
parent 2f8ad142ec
commit 526fd64d11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -194,10 +194,16 @@ fi
# marker to check if container was restarted
date >/CONTAINER_START
# Container logs will receive updates from this log file:
MAIN_LOGFILE=/var/log/mail/mail.log
# NOTE: rsyslogd would usually create this later during `_start_daemons`, however it would already exist if the container was restarted.
touch "${MAIN_LOGFILE}"
# Ensure `tail` follows the correct position of the log file for this container start (new logs begin once `_start_daemons` is called)
TAIL_START=$(( $(wc -l < "${MAIN_LOGFILE}") + 1 ))
[[ ${LOG_LEVEL} =~ (debug|trace) ]] && print-environment
_start_daemons
# Container start-up scripts completed. `tail` will now pipe the log updates to stdout:
_log 'info' "${HOSTNAME} is up and running"
touch /var/log/mail/mail.log
exec tail -Fn 0 /var/log/mail/mail.log
exec tail -Fn "+${TAIL_START}" "${MAIN_LOGFILE}"