Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Make logrotate aware of disk space
Browse files Browse the repository at this point in the history
Delete logs files above a threshold in size in chronological order
while disk space usage is above a given threshold.
  • Loading branch information
rtrinque committed May 9, 2022
1 parent 26a4f0c commit 10ebb2f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/logrotate/templates/logrotate.conf.erb
Expand Up @@ -43,6 +43,16 @@
# Remove empty .1 log files. There seems to be an issue where logrotate
# will refuse to rotate the logs if an empty .1 log file exists.
find <%= @matches %>* -wholename '/var/log/*' -name '*.1' -size 0 -delete
# Remove files bigger than $SIZE in chronological order while use of
# disk space on the logging partition is greater than $MAX_USE
SIZE='300M'
MAX_USE=85
for file in $(find <%= @matches %>* -type f -size +$SIZE -exec ls -tr {} +); do
USE=$(df /var/log --output=pcent | sed -n '2p' | tr -d %)
if [ $USE -gt $MAX_USE ]; then
rm $file
fi
done;
endscript
lastaction
# Clean up files older than maximum rotation. No-op unless "rotate" value is reduced,
Expand Down

0 comments on commit 10ebb2f

Please sign in to comment.