dd0eacc460
- use flock to ensure that only one instance of fuel-logrotate is running - combine centos and ubuntu versions of fuel-logrotate to a single file - remove unused versions of fuel-logrotate file - enable delayed compression in system-wide logrotate.conf to avoid race condition between fuel-logrotate and regular logrotate - enable delaycompress also on master node - default minsize (30M) and maxsize (100M) in system-wide logrotate.conf - use file_line for logrotate.conf updates - use bash to execute fuel-logrotate - fix path to cron's logrotate script in logrotate-debug This commit changes default behavior of logrotate by enabling compress and delaycompress. The result is that compression is enabled for all log files managed by logrotate and rotated logs are compressed only on the next rotation. It allows us to resolve rotation cycle that might happen when both regular logrotate and fuel-logrotate were executed at the same time, causing both to rotate the same file. Closes-Bug: 1461400 Doc-Impact: ops guide Change-Id: I94c497a8916fa6fac87ea2ddc51f6de56ab73f98 Co-Authored-By: Alex Schultz <aschultz@mirantis.com>
46 lines
982 B
Bash
46 lines
982 B
Bash
#!/bin/bash
|
|
lock() {
|
|
exec 903>/var/lock/fuel-logrotate
|
|
flock -n 903 && return 0 || return 1
|
|
}
|
|
|
|
unlock() {
|
|
flock -u 903
|
|
}
|
|
|
|
fail() {
|
|
if [ -z "$1" ]
|
|
then
|
|
MESSAGE="WARNING logrotate failed, no reason provided"
|
|
else
|
|
MESSAGE=$1
|
|
fi
|
|
/usr/bin/logger -t logrotate "${MESSAGE}"
|
|
unlock
|
|
exit 1
|
|
}
|
|
|
|
lock || fail "WARNING logrotate flock failed, exiting"
|
|
|
|
nice ionice -c3 /usr/sbin/logrotate /etc/logrotate.d/fuel.nodaily >& /tmp/logrotate
|
|
EXITVALUE=$?
|
|
|
|
if [ -f /etc/redhat-release ] || [ -f /etc/centos-release ];
|
|
then
|
|
# Due to bug in logrotate on centos/rhel, it always returns 0. Use grep for
|
|
# detect errors; exit code 1 is considered a success as no errors were
|
|
# found.
|
|
grep -q error /tmp/logrotate
|
|
EXITVALUE=$?
|
|
EXPECTEDVALUE=1
|
|
else
|
|
EXPECTEDVALUE=0
|
|
fi
|
|
|
|
if [ "${EXITVALUE}" != "${EXPECTEDVALUE}" ]; then
|
|
fail "ALERT exited abnormally with [${EXITVALUE}] (${EXPECTEDVALUE} was expected)"
|
|
fi
|
|
|
|
unlock
|
|
exit 0
|