From a519547f77522414721d4772718d53346d8a91cd Mon Sep 17 00:00:00 2001 From: LALLAU Bertrand Date: Fri, 30 Aug 2024 14:09:34 +0200 Subject: [PATCH] Fix CPU burning on ironic-log-watch when no ramdisk file is present Use inotifywait on 'close_write' event instead of an infinite loop. Inotifywait 'close_write' event usage allow to be sure that tar file archive integrity is safe. Signed-off-by: LALLAU Bertrand --- scripts/runlogwatch.sh | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/scripts/runlogwatch.sh b/scripts/runlogwatch.sh index 472b63f18..269b77e79 100755 --- a/scripts/runlogwatch.sh +++ b/scripts/runlogwatch.sh @@ -3,16 +3,9 @@ # Ramdisk logs path LOG_DIR="/shared/log/ironic/deploy" -while :; do - if ! ls "${LOG_DIR}"/*.tar.gz 1> /dev/null 2>&1; then - continue - fi - - for fn in "${LOG_DIR}"/*.tar.gz; do - echo "************ Contents of $fn ramdisk log file bundle **************" - tar -xOzvvf "$fn" | sed -e "s/^/$(basename "$fn"): /" - rm -f "$fn" +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 - - sleep 5 -done