Hello everybody, looking at this old but nasty bug that must be fixed for stretch:
* Trying to understand what goes wrong I wrote a small script that
creates a few scenarios and executes logrotate then. Run it in
an arbitrary directory like /tmp/ as regular user, with a single
parameter in the range 0 to 4. Expect a lot of failures.
* In my understanding logrotate never compresses older logfiles even
if they are not compressed yet, this will lead to the observed
clashes. So I was about to write a patch that similar for Bolesław's
proposal detects if the target file already exists, but would
compress it then. However:
* github[1] contains a link[2] to a patch gentoo created. At least
for all scenario my test script above creates, it solves the problems.
I'd suggest you all test it as well and report back.
Cheers,
Christoph
[1] https://github.com/logrotate/logrotate/pull/23
[2]
https://gitweb.gentoo.org/repo/gentoo.git/plain/app-admin/logrotate/files/logrotate-3.10.0-atomic-create.patch?id=3aae9fbc
#!/bin/sh
set -e
mkdir -p logs
rm logs/* 2>/dev/null || true
create () {
touch logs/logfile
while [ "$1" ] ; do
echo "$1" >logs/logfile$1
shift
done
}
compress () {
while [ "$1" ] ; do
gzip logs/logfile$1
shift
done
}
case "$1" in
0)
# vanilla: some older logfiles
create '.1' '.2' '.3'
compress '.1' '.2' '.3'
;;
1)
# first generation exists both plain and compressed
create '.1' '.2' '.3'
compress '.1' '.2' '.3'
create '.1'
;;
2)
# first generation is not compressed - ERROR
create '.1' '.2' '.3' '.4'
compress '.2' '.3' '.4'
;;
3)
# gen.1 not compressed, gen.2 missing
create '.1' '.3' '.4'
compress '.3' '.4'
;;
4)
# gen.1 not compressed, gen.[23] missing
create '.1' '.4'
compress '.4'
;;
'')
echo "Usage: $0 <scenario>"
exit 1
;;
*)
echo "BUG: Undefined scenario '$1'"
exit 2
;;
esac
CONF="$PWD/logrotate.conf"
cat <<__EOS__ >"$CONF"
$PWD/logs/logfile {
daily
missingok
rotate 3
compress
copytruncate
create 640 $(getent passwd $(id -u) | cut -d: -f1) $(getent group $(id -g)
| cut -d: -f1)
}
__EOS__
STATE="$PWD/state"
rm "$STATE" >/dev/null || true
echo 'Files in logs/ [PRE]:'
ls -1 logs/
/usr/sbin/logrotate --force --state "$STATE" --verbose "$CONF" || true
echo 'Files in logs/ [POST]:'
ls -1 logs/
echo 'State file:'
cat "$STATE"
signature.asc
Description: Digital signature

