2017-08-10 18:24:57 -05:00
|
|
|
# These logs should no longer get created. However, in case they do get created,
|
|
|
|
# we should keep them to a small size and rotate them also.
|
|
|
|
/var/log/mail.info
|
|
|
|
/var/log/mail.warn
|
|
|
|
/var/log/mail.err
|
|
|
|
/var/log/mail.log
|
|
|
|
/var/log/daemon.log
|
|
|
|
/var/log/kern.log
|
|
|
|
/var/log/user.log
|
|
|
|
/var/log/lpr.log
|
|
|
|
/var/log/debug
|
|
|
|
/var/log/messages
|
|
|
|
{
|
|
|
|
size 10k
|
|
|
|
rotate 1
|
|
|
|
missingok
|
|
|
|
notifempty
|
|
|
|
compress
|
|
|
|
delaycompress
|
|
|
|
sharedscripts
|
|
|
|
postrotate
|
2019-05-25 20:00:18 -05:00
|
|
|
/bin/kill -HUP $(cat /var/run/rsyslogd.pid)
|
2017-08-10 18:24:57 -05:00
|
|
|
endscript
|
|
|
|
}
|
|
|
|
|
|
|
|
/var/log/auth.log
|
|
|
|
/var/log/cron.log
|
|
|
|
/var/log/syslog
|
|
|
|
/var/log/teamd.log
|
2018-03-27 15:39:04 -05:00
|
|
|
/var/log/telemetry.log
|
2020-12-10 10:44:34 -06:00
|
|
|
/var/log/frr/bgpd.log
|
|
|
|
/var/log/frr/zebra.log
|
2021-01-22 11:42:19 -06:00
|
|
|
/var/log/swss/sairedis*.rec
|
|
|
|
/var/log/swss/swss*.rec
|
2021-11-24 12:31:06 -06:00
|
|
|
/var/log/swss/responsepublisher.rec
|
2017-08-10 18:24:57 -05:00
|
|
|
{
|
2022-01-14 12:24:07 -06:00
|
|
|
{% if var_log_kb <= 204800 %}
|
2017-08-10 18:24:57 -05:00
|
|
|
size 1M
|
2023-07-14 16:47:03 -05:00
|
|
|
{% elif var_log_kb <= 409600 %}
|
|
|
|
size 2M
|
2022-01-14 12:24:07 -06:00
|
|
|
{% else %}
|
|
|
|
size 16M
|
|
|
|
{% endif %}
|
2017-08-10 18:24:57 -05:00
|
|
|
rotate 5000
|
|
|
|
missingok
|
|
|
|
notifempty
|
|
|
|
compress
|
|
|
|
delaycompress
|
|
|
|
nosharedscripts
|
2019-05-25 20:00:18 -05:00
|
|
|
firstaction
|
2017-08-10 18:24:57 -05:00
|
|
|
# Adjust NUM_LOGS_TO_ROTATE to reflect number of log files that trigger this block specified above
|
|
|
|
NUM_LOGS_TO_ROTATE=8
|
|
|
|
|
|
|
|
# Adjust LOG_FILE_ROTATE_SIZE_KB to reflect the "size" parameter specified above, in kB
|
2022-11-08 05:38:14 -06:00
|
|
|
{% if var_log_kb <= 204800 %}
|
2017-08-10 18:24:57 -05:00
|
|
|
LOG_FILE_ROTATE_SIZE_KB=1024
|
2023-07-14 16:47:03 -05:00
|
|
|
{% elif var_log_kb <= 409600 %}
|
|
|
|
LOG_FILE_ROTATE_SIZE_KB=2048
|
2022-11-08 05:38:14 -06:00
|
|
|
{% else %}
|
|
|
|
LOG_FILE_ROTATE_SIZE_KB=16384
|
|
|
|
{% endif %}
|
2017-08-10 18:24:57 -05:00
|
|
|
|
|
|
|
# Reserve space for btmp, wtmp, dpkg.log, monit.log, etc., as well as logs that
|
|
|
|
# should be disabled, just in case they get created and rotated
|
|
|
|
RESERVED_SPACE_KB=4096
|
|
|
|
|
2022-02-17 02:16:44 -06:00
|
|
|
VAR_LOG_SIZE_KB={{var_log_kb}}
|
2017-08-10 18:24:57 -05:00
|
|
|
|
2018-04-30 13:18:56 -05:00
|
|
|
# Limit usable space to 90% of the partition minus the reserved space for other logs
|
|
|
|
USABLE_SPACE_KB=$(( (VAR_LOG_SIZE_KB * 90 / 100) - RESERVED_SPACE_KB))
|
2017-08-10 18:24:57 -05:00
|
|
|
|
|
|
|
# Set our threshold so as to maintain enough space to write all logs from empty to full
|
|
|
|
# Most likely, some logs will have non-zero size when this is called, so this errs on the side
|
|
|
|
# of caution, giving us a bit of a cushion if a log grows quickly and passes its rotation size
|
|
|
|
THRESHOLD_KB=$((USABLE_SPACE_KB - (NUM_LOGS_TO_ROTATE * LOG_FILE_ROTATE_SIZE_KB * 2)))
|
|
|
|
|
2019-05-25 20:00:18 -05:00
|
|
|
# First, delete any *.1.gz files that might be left around from a prior incomplete
|
|
|
|
# logrotate execution, otherwise logrotate will fail to do its job
|
|
|
|
find /var/log/ -name '*.1.gz' -type f -exec rm -f {} +
|
|
|
|
|
2017-08-10 18:24:57 -05:00
|
|
|
while true; do
|
|
|
|
USED_KB=$(du -s /var/log | awk '{ print $1; }')
|
|
|
|
|
|
|
|
if [ $USED_KB -lt $THRESHOLD_KB ]; then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
OLDEST_ARCHIVE_FILE=$(find /var/log -type f -printf '%T+ %p\n' | grep -E '.+\.[0-9]+(\.gz)?$' | sort | head -n 1 | awk '{ print $2; }')
|
|
|
|
|
|
|
|
if [ -z "$OLDEST_ARCHIVE_FILE" ]; then
|
|
|
|
logger -p syslog.err -t "logrotate" "No archive file to delete -- potential for filling up /var/log partition!"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
logger -p syslog.info -t "logrotate" "Deleting archive file $OLDEST_ARCHIVE_FILE to free up space"
|
|
|
|
rm -rf "$OLDEST_ARCHIVE_FILE"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
endscript
|
|
|
|
postrotate
|
|
|
|
if [ $(echo $1 | grep -c "/var/log/swss/") -gt 0 ]; then
|
2021-01-22 11:42:19 -06:00
|
|
|
# for multi asic platforms, there are multiple orchagents
|
|
|
|
# send the SIGHUP only to the orchagent the which needs log file rotation
|
|
|
|
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
|
|
|
|
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
|
|
|
|
if [ -f "$ASIC_CONF" ]; then
|
|
|
|
. $ASIC_CONF
|
|
|
|
fi
|
|
|
|
if [ $NUM_ASIC -gt 1 ]; then
|
|
|
|
log_file=$1
|
|
|
|
log_file_name=${log_file#/var/log/swss/}
|
|
|
|
logger -p syslog.info -t "logrotate" "Sending SIGHUP to OA log_file_name: $log_file_name"
|
|
|
|
pgrep -xa orchagent | grep $log_file_name | awk '{ print $1; }' | xargs /bin/kill -HUP 2>/dev/null || true
|
|
|
|
else
|
|
|
|
logger -p syslog.info -t "logrotate" "Sending SIGHUP to OA log_file_name: $1"
|
|
|
|
pgrep -x orchagent | xargs /bin/kill -HUP 2>/dev/null || true
|
|
|
|
fi
|
2017-08-10 18:24:57 -05:00
|
|
|
else
|
2019-05-25 20:00:18 -05:00
|
|
|
/bin/kill -HUP $(cat /var/run/rsyslogd.pid)
|
2017-08-10 18:24:57 -05:00
|
|
|
fi
|
|
|
|
endscript
|
|
|
|
}
|