Skip to content

Commit

Permalink
runlogwatch.sh fix CPU usage and partial files
Browse files Browse the repository at this point in the history
Currently runlogwatch.sh runs in a tight loop when there are no files,
consuming CPU. Also there have been reports of truncated logs being
outputted which would be explained by ironic not writing these files
atomically [1]. This change improves this script by:
- moving the sleep to the top of the loop so it is called on every
  iteration
- change the file glob to a `find` command which includes `-mmin +0.1`
  so the file is only processed when it is at least 6 seconds old

[1] https://opendev.org/openstack/ironic/src/branch/master/ironic/drivers/utils.py#L315-L316

Signed-off-by: Steve Baker <sbaker@redhat.com>
  • Loading branch information
steveb committed Aug 28, 2024
1 parent 6b295ae commit 1122f1b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions scripts/runlogwatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
LOG_DIR="/shared/log/ironic/deploy"

while :; do
if ! ls "${LOG_DIR}"/*.tar.gz 1> /dev/null 2>&1; then
continue
fi
sleep 5

for fn in "${LOG_DIR}"/*.tar.gz; do
while read fn; do
echo "************ Contents of $fn ramdisk log file bundle **************"
tar -xOzvvf "$fn" | sed -e "s/^/$(basename "$fn"): /"
rm -f "$fn"
done
# find all *.tar.gz files which are older than six seconds
done < <(find ${LOG_DIR} -mmin +0.1 -type f -name "*.tar.gz")

sleep 5
done

0 comments on commit 1122f1b

Please sign in to comment.