forked from sonoble/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrsyslog
More file actions
97 lines (87 loc) · 3.46 KB
/
Copy pathrsyslog
File metadata and controls
97 lines (87 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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
# calling kill directly instead of 'service rsyslog rotate >/dev/null' due
# to bug in init-system-helpers. bug has apparently been fixed in v1.47.
# however, debian jessie is still using v1.22.
# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672218
kill -hup $(cat /var/run/rsyslogd.pid)
endscript
}
/var/log/auth.log
/var/log/cron.log
/var/log/syslog
/var/log/teamd.log
/var/log/telemetry.log
/var/log/quagga/bgpd.log
/var/log/quagga/zebra.log
/var/log/swss/sairedis.rec
/var/log/swss/swss.rec
{
size 1M
rotate 5000
missingok
notifempty
compress
delaycompress
nosharedscripts
prerotate
# 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
LOG_FILE_ROTATE_SIZE_KB=1024
# 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
VAR_LOG_SIZE_KB=$(df -k /var/log | sed -n 2p | awk '{ print $2 }')
# 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))
# 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)))
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
pgrep -x orchagent | xargs /bin/kill -HUP 2>/dev/null || true
else
# Calling kill directly instead of 'service rsyslog rotate >/dev/null' due
# to bug in init-system-helpers. Bug has apparently been fixed in v1.47.
# However, Debian Jessie is still using v1.22.
# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672218
kill -HUP $(cat /var/run/rsyslogd.pid)
fi
endscript
}