From 3c4aeab970b630b3100b7e29868f8582f7542110 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 16 Oct 2024 12:14:17 +1300 Subject: [PATCH] Convert runlogwatch.sh to use inotifywait This aligns with metal3 runlogwatch.sh[1] which is possible now that inotify-tools package is available[2]. [1] https://github.com/metal3-io/ironic-image/pull/548/files [2] https://github.com/openstack-k8s-operators/tcib/commit/0795bb902af2199905413cae8593d382618459e8 Jira: OSPRH-10240 --- templates/common/bin/runlogwatch.sh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/templates/common/bin/runlogwatch.sh b/templates/common/bin/runlogwatch.sh index 7555eaf5..e69999f2 100755 --- a/templates/common/bin/runlogwatch.sh +++ b/templates/common/bin/runlogwatch.sh @@ -3,15 +3,9 @@ # Ramdisk logs path LOG_DIR=${LOG_DIR:-/var/lib/ironic/ramdisk-logs} -while :; do - sleep 5 - - while read -r fn; do - echo - echo "************ Contents of $fn ramdisk log file bundle **************" - tar -xOzvvf "$fn" | sed -e "s/^/$(basename "$fn"): /" - rm -f "$fn" - # find all *.tar.gz files which are older than six seconds - done < <(find "${LOG_DIR}" -mmin +0.1 -type f -name "*.tar.gz") - -done +inotifywait -m "${LOG_DIR}" -e close_write | + while read -r path _action file; do + echo "************ Contents of ${path}${file} ramdisk log file bundle **************" + tar -xOzvvf "${path}${file}" | sed -e "s/^/${file}: /" + rm -f "${path}/${file}" + done