From a09b5fe410968a3b661bc8fc666e390bd4b40d50 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 26 Jul 2017 18:40:47 +0000 Subject: [PATCH 01/11] Properly prevent cron from logging to /var/log/syslog --- files/image_config/logrotate.d/rsyslog | 3 +++ .../image_config/rsyslog/rsyslog.d/99-default.conf | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/files/image_config/logrotate.d/rsyslog b/files/image_config/logrotate.d/rsyslog index 5101b0e41fd2..f64f68583e64 100644 --- a/files/image_config/logrotate.d/rsyslog +++ b/files/image_config/logrotate.d/rsyslog @@ -9,6 +9,7 @@ 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. @@ -17,6 +18,7 @@ kill -HUP $(cat /var/run/rsyslogd.pid) endscript } + /var/log/swss/*.rec { rotate 7 @@ -31,6 +33,7 @@ pgrep -x orchagent | xargs /bin/kill -HUP 2>/dev/null || true endscript } + /var/log/mail.info /var/log/mail.warn /var/log/mail.err diff --git a/files/image_config/rsyslog/rsyslog.d/99-default.conf b/files/image_config/rsyslog/rsyslog.d/99-default.conf index 51049e7473a8..e10fac13e793 100644 --- a/files/image_config/rsyslog/rsyslog.d/99-default.conf +++ b/files/image_config/rsyslog/rsyslog.d/99-default.conf @@ -1,17 +1,20 @@ # # First some standard log files. Log by facility. # + +# Log all facilities to /var/log/syslog except cron, +# auth and authpriv - log them to their own files +*.*;cron,auth,authpriv.none -/var/log/syslog auth,authpriv.* /var/log/auth.log -*.*;auth,authpriv.none -/var/log/syslog cron.* /var/log/cron.log -# Do not redirect daemon, kernel or lpr logs to -# their own files. Let them log to /var/log/syslog +# Do not redirect the following facilities' logs to +# their own files. Let them log to /var/log/syslog only #daemon.* -/var/log/daemon.log #kern.* -/var/log/kern.log #kern.* -/var/persist/log/kern.log #lpr.* -/var/log/lpr.log -mail.* -/var/log/mail.log -user.* -/var/log/user.log +#mail.* -/var/log/mail.log +#user.* -/var/log/user.log # # Logging for the mail system. Split it up so that From f8c2d4182cdda9bc3cae0b890a61e405cb3cd55f Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 26 Jul 2017 19:30:53 +0000 Subject: [PATCH 02/11] Condense logs further to eliminate duplicate logs and further prevent filling disk space --- .../rsyslog/rsyslog.d/99-default.conf | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/files/image_config/rsyslog/rsyslog.d/99-default.conf b/files/image_config/rsyslog/rsyslog.d/99-default.conf index e10fac13e793..428981bcf44e 100644 --- a/files/image_config/rsyslog/rsyslog.d/99-default.conf +++ b/files/image_config/rsyslog/rsyslog.d/99-default.conf @@ -7,58 +7,12 @@ *.*;cron,auth,authpriv.none -/var/log/syslog auth,authpriv.* /var/log/auth.log cron.* /var/log/cron.log -# Do not redirect the following facilities' logs to -# their own files. Let them log to /var/log/syslog only -#daemon.* -/var/log/daemon.log -#kern.* -/var/log/kern.log -#kern.* -/var/persist/log/kern.log -#lpr.* -/var/log/lpr.log -#mail.* -/var/log/mail.log -#user.* -/var/log/user.log -# -# Logging for the mail system. Split it up so that -# it is easy to write scripts to parse these files. -# -mail.info -/var/log/mail.info -mail.warn -/var/log/mail.warn -mail.err /var/log/mail.err - -# -# Logging for INN news system. -# -news.crit /var/log/news/news.crit -news.err /var/log/news/news.err -news.notice -/var/log/news/news.notice - -# -# Some "catch-all" log files. -# -*.=debug;\ - auth,authpriv.none;\ - news.none;mail.none -/var/log/debug -# -# Removed as duplicates: -#*.=info;*.=notice;*.=warn;\ -# auth,authpriv.none;\ -# cron,daemon.none;\ -# mail,news.none -/var/log/messages -# -*.=crit;*.=alert;*.=emerg -/var/persist/log/alarms # # Emergencies are sent to everybody logged in. # *.emerg :omusrmsg:* -# -# I like to have messages displayed on the console, but only on a virtual -# console I usually leave idle. -# -#daemon,mail.*;\ -# news.=crit;news.=err;news.=notice;\ -# *.=debug;*.=info;\ -# *.=notice;*.=warn /dev/tty8 - # The named pipe /dev/xconsole is for the `xconsole' utility. To use it, # you must invoke `xconsole' with the `-file' option: # From 3cc5d158df0278665a5d56062cdfb03aa0dd7314 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 26 Jul 2017 19:32:14 +0000 Subject: [PATCH 03/11] Comment --- files/image_config/rsyslog/rsyslog.d/99-default.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/image_config/rsyslog/rsyslog.d/99-default.conf b/files/image_config/rsyslog/rsyslog.d/99-default.conf index 428981bcf44e..06a40ca64852 100644 --- a/files/image_config/rsyslog/rsyslog.d/99-default.conf +++ b/files/image_config/rsyslog/rsyslog.d/99-default.conf @@ -2,8 +2,8 @@ # First some standard log files. Log by facility. # -# Log all facilities to /var/log/syslog except cron, -# auth and authpriv - log them to their own files +# Log all facilities to /var/log/syslog except cron, auth +# and authpriv. They are noisy - log them to their own files *.*;cron,auth,authpriv.none -/var/log/syslog auth,authpriv.* /var/log/auth.log cron.* /var/log/cron.log From ce58980d5c54626c5fcad859b9ce62ff949b97f7 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 26 Jul 2017 21:41:55 +0000 Subject: [PATCH 04/11] Allow other users to read log files mamged by rsyslog --- files/image_config/rsyslog/rsyslog.conf.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/image_config/rsyslog/rsyslog.conf.j2 b/files/image_config/rsyslog/rsyslog.conf.j2 index 54e2eec3f999..91f5b717fa46 100644 --- a/files/image_config/rsyslog/rsyslog.conf.j2 +++ b/files/image_config/rsyslog/rsyslog.conf.j2 @@ -50,7 +50,7 @@ $ActionFileDefaultTemplate SONiCFileFormat # $FileOwner root $FileGroup adm -$FileCreateMode 0640 +$FileCreateMode 0644 $DirCreateMode 0755 $Umask 0022 From fe53df3830a54c24bacb26885630be796b30adb3 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 26 Jul 2017 22:05:32 +0000 Subject: [PATCH 05/11] Force log rotation at size intervals; remove temporal rotations altoghether since logrotate is run every minute --- files/image_config/logrotate.d/rsyslog | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/files/image_config/logrotate.d/rsyslog b/files/image_config/logrotate.d/rsyslog index f64f68583e64..5aca073f33c9 100644 --- a/files/image_config/logrotate.d/rsyslog +++ b/files/image_config/logrotate.d/rsyslog @@ -3,8 +3,7 @@ /var/log/teamd.log { rotate 7 - daily - maxsize 100M + size 100M missingok notifempty compress @@ -22,8 +21,7 @@ /var/log/swss/*.rec { rotate 7 - daily - maxsize 20M + size 20M missingok notifempty compress @@ -34,6 +32,8 @@ endscript } +# These log files should no longer be created, but we should attempt to rotate +# them anyway, just in case they happen to get created. /var/log/mail.info /var/log/mail.warn /var/log/mail.err @@ -47,9 +47,8 @@ /var/log/debug /var/log/messages { - rotate 4 - daily - maxsize 50M + rotate 1 + size 1k missingok notifempty compress From 63c734ae2029261290242238b89443cd089e3abf Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 26 Jul 2017 23:58:16 +0000 Subject: [PATCH 06/11] Add 'Managed by SONiC Config Engine' banner to rsyslog.conf.j2 --- files/image_config/rsyslog/rsyslog.conf.j2 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/files/image_config/rsyslog/rsyslog.conf.j2 b/files/image_config/rsyslog/rsyslog.conf.j2 index 91f5b717fa46..75bb7040c38d 100644 --- a/files/image_config/rsyslog/rsyslog.conf.j2 +++ b/files/image_config/rsyslog/rsyslog.conf.j2 @@ -1,12 +1,13 @@ -############################################################################### -# Managed by Ansible -# file: ansible/roles/acs/templates/rsyslog.conf.j2 -############################################################################### +{% block banner %} # -# /etc/rsyslog.conf Configuration file for rsyslog. +# =========== Managed by SONiC Config Engine - DO NOT EDIT MANUALLY! =========== +# Generated from /usr/share/sonic/templates/rsyslog.conf.j2 using sonic-cfggen +# +# file: /etc/rsyslog.conf Configuration file for rsyslog. # # For more information see # /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html +{% endblock banner %} ################# From ebdda8e3bcb7c7fef51cc4febde3cb351d3e29cd Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Thu, 27 Jul 2017 18:35:52 +0000 Subject: [PATCH 07/11] Dynamically calculate logrotate file size thresholds based on /var/log/ partition size - Also rename /etc/logrotate.d/rsyslog to /etc/logrotate.d/sonic, as SwSS logs are not managed by rsyslog - Add modified default /etc/logrotate.conf to ensure btmp and wtmp files are rotated based on size --- .../build_templates/sonic_debian_extension.j2 | 9 +++- .../logrotate/logrotate-config.service | 10 +++++ .../logrotate/logrotate-config.sh | 34 ++++++++++++++ files/image_config/logrotate/logrotate.conf | 32 ++++++++++++++ .../rsyslog => logrotate/sonic.j2} | 44 ++++++++++++++++--- 5 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 files/image_config/logrotate/logrotate-config.service create mode 100755 files/image_config/logrotate/logrotate-config.sh create mode 100644 files/image_config/logrotate/logrotate.conf rename files/image_config/{logrotate.d/rsyslog => logrotate/sonic.j2} (53%) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index a84b7070a560..8d8178ea29f5 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -105,8 +105,13 @@ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.d/* $FILESYSTEM_ROOT/etc/rsyslog.d/ -# Copy logrotate.d configuration files -sudo cp -f $IMAGE_CONFIGS/logrotate.d/rsyslog $FILESYSTEM_ROOT/etc/logrotate.d/ +# Copy logrotate configuration files and templates +sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.service $FILESYSTEM_ROOT/etc/systemd/system/ +sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable logrotate-config.service +sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.sh $FILESYSTEM_ROOT/usr/bin/ +sudo cp $IMAGE_CONFIGS/logrotate/logrotate.conf $FILESYSTEM_ROOT/etc/ +sudo mkdir -p $FILESYSTEM_ROOT/usr/share/sonic/templates/logrotate.d/ +sudo cp $IMAGE_CONFIGS/logrotate/sonic.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/logrotate.d/ # Copy systemd-journald configuration files sudo cp -f $IMAGE_CONFIGS/systemd/journald.conf $FILESYSTEM_ROOT/etc/systemd/ diff --git a/files/image_config/logrotate/logrotate-config.service b/files/image_config/logrotate/logrotate-config.service new file mode 100644 index 000000000000..893afc8857de --- /dev/null +++ b/files/image_config/logrotate/logrotate-config.service @@ -0,0 +1,10 @@ +[Unit] +Description=Update logrotate configuration +After=basic.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/logrotate-config.sh + +[Install] +WantedBy=multi-user.target diff --git a/files/image_config/logrotate/logrotate-config.sh b/files/image_config/logrotate/logrotate-config.sh new file mode 100755 index 000000000000..eabadec5e861 --- /dev/null +++ b/files/image_config/logrotate/logrotate-config.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Reserve space for btmp and wtmp, auth.log and cron.log, as well as logs that +# should be disabled, just in case they get created and rotated +RESERVED_SPACE_KB=1024 + +# Number of rotated archive files to keep per log file +NUM_ARCHIVES_PER_LOG_FILE=7 + +# Number of files to rotate in each block within sonic.j2 template +NUM_LOG_FILES_SYSLOG=1 +NUM_LOG_FILES_QUAGGA_TEAMD=3 +NUM_LOG_FILES_SWSS=2 + +# Percentage of usable /var/log/ space to allocate to each block in template +PERCENT_ALLOCATED_SYSLOG=75 +PERCENT_ALLOCATED_QUAGGA_TEAMD=15 +PERCENT_ALLOCATED_SWSS=10 + +VAR_LOG_SIZE_KB=$(df /var/log | sed -n 2p | awk '{print $2}') +USABLE_SPACE_KB=$((VAR_LOG_SIZE_KB - RESERVED_SPACE_KB)) + +SIZE_LIMIT_SYSLOG_FILES_KB=$((USABLE_SPACE_KB / (NUM_LOG_FILES_SYSLOG * (NUM_ARCHIVES_PER_LOG_FILE + 1)) / 100 * PERCENT_ALLOCATED_SYSLOG)) +SIZE_LIMIT_QUAGGA_TEAMD_FILES_KB=$((USABLE_SPACE_KB / (NUM_LOG_FILES_QUAGGA_TEAMD * (NUM_ARCHIVES_PER_LOG_FILE + 1)) / 100 * PERCENT_ALLOCATED_QUAGGA_TEAMD)) +SIZE_LIMIT_SWSS_FILES_KB=$((USABLE_SPACE_KB / (NUM_LOG_FILES_SWSS * (NUM_ARCHIVES_PER_LOG_FILE + 1)) / 100 * PERCENT_ALLOCATED_SWSS)) + +ADDITIONAL_DATA_JSON="{" +ADDITIONAL_DATA_JSON+="\"num_archive_files\":$NUM_ARCHIVES_PER_LOG_FILE," +ADDITIONAL_DATA_JSON+="\"size_limit_syslog_kb\":$SIZE_LIMIT_SYSLOG_FILES_KB," +ADDITIONAL_DATA_JSON+="\"size_limit_quagga_teamd_kb\":$SIZE_LIMIT_QUAGGA_TEAMD_FILES_KB," +ADDITIONAL_DATA_JSON+="\"size_limit_swss_kb\":$SIZE_LIMIT_SWSS_FILES_KB" +ADDITIONAL_DATA_JSON+="}" + +sonic-cfggen -a "$ADDITIONAL_DATA_JSON" -t /usr/share/sonic/templates/logrotate.d/sonic.j2 > /etc/logrotate.d/sonic diff --git a/files/image_config/logrotate/logrotate.conf b/files/image_config/logrotate/logrotate.conf new file mode 100644 index 000000000000..6f107e209837 --- /dev/null +++ b/files/image_config/logrotate/logrotate.conf @@ -0,0 +1,32 @@ +# see "man logrotate" for details +# Rotate log files daily by default +daily + +# Keep 4 days worth of backlogs by default +rotate 4 + +# create new (empty) log files after rotating old ones +create + +# uncomment this if you want your log files compressed +#compress + +# packages drop log rotation information into this directory +include /etc/logrotate.d + +# no packages own wtmp, or btmp -- we'll rotate them here +/var/log/wtmp { + missingok + size 100k + create 0664 root utmp + rotate 1 +} + +/var/log/btmp { + missingok + size 100k + create 0660 root utmp + rotate 1 +} + +# system-specific logs may be configured here diff --git a/files/image_config/logrotate.d/rsyslog b/files/image_config/logrotate/sonic.j2 similarity index 53% rename from files/image_config/logrotate.d/rsyslog rename to files/image_config/logrotate/sonic.j2 index 5aca073f33c9..8653687c00b9 100644 --- a/files/image_config/logrotate.d/rsyslog +++ b/files/image_config/logrotate/sonic.j2 @@ -1,9 +1,37 @@ +{% block banner %} +# +# =========== Managed by SONiC Config Engine - DO NOT EDIT MANUALLY! =========== +# Generated from: +# /usr/share/sonic/templates/logrotate.d/sonic.conf.j2 using sonic-cfggen +# +# file: /etc/logrotate.d/sonic.conf +# Logrotate configuration file for SONiC +# +{% endblock banner %} + /var/log/syslog +{ + rotate {{ num_archive_files }} + size {{ size_limit_syslog_kb }}k + 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/quagga/*.log /var/log/teamd.log { - rotate 7 - size 100M + rotate {{ num_archive_files }} + size {{ size_limit_quagga_teamd_kb }}k missingok notifempty compress @@ -18,10 +46,11 @@ endscript } +# SwSS logs (written by orchagent, not rsyslog) /var/log/swss/*.rec { - rotate 7 - size 20M + rotate {{ num_archive_files }} + size {{ size_limit_swss_kb }}k missingok notifempty compress @@ -32,8 +61,9 @@ endscript } -# These log files should no longer be created, but we should attempt to rotate -# them anyway, just in case they happen to get created. +# Of these rsyslog-written log files, only auth.log and cron.log should still +# be created. However, we should attempt to rotate all of them anyway, just +# in case others happen to get created. /var/log/mail.info /var/log/mail.warn /var/log/mail.err @@ -48,7 +78,7 @@ /var/log/messages { rotate 1 - size 1k + size 10k missingok notifempty compress From 4bac664fb88808469c97d01114e58bc46360c493 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Thu, 27 Jul 2017 18:51:32 +0000 Subject: [PATCH 08/11] Change logrotate cron job to use /etc/logrotate.conf, which includes all files in /etc/logrotate.d/ --- files/image_config/cron.d/logrotate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/image_config/cron.d/logrotate b/files/image_config/cron.d/logrotate index 9e1335cbd43e..fd09d1792a2e 100644 --- a/files/image_config/cron.d/logrotate +++ b/files/image_config/cron.d/logrotate @@ -1,2 +1,2 @@ # Attempt to rotate system logs once per minute -* * * * * root /usr/sbin/logrotate /etc/logrotate.d/rsyslog +* * * * * root /usr/sbin/logrotate /etc/logrotate.conf From aef25cff9b74b89f220b5a8737d2d2523c7513eb Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 28 Jul 2017 00:17:16 +0000 Subject: [PATCH 09/11] Rename sonic.j2 back to rsyslog(.j2), as /etc/logrotate.d/rsyslog in order to overwrite the default file --- files/build_templates/sonic_debian_extension.j2 | 2 +- files/image_config/cron.d/logrotate | 2 +- files/image_config/logrotate/logrotate-config.sh | 4 ++-- files/image_config/logrotate/{sonic.j2 => rsyslog.j2} | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename files/image_config/logrotate/{sonic.j2 => rsyslog.j2} (95%) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 8d8178ea29f5..d383c238aaff 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -111,7 +111,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable logrotate-config.service sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/logrotate/logrotate.conf $FILESYSTEM_ROOT/etc/ sudo mkdir -p $FILESYSTEM_ROOT/usr/share/sonic/templates/logrotate.d/ -sudo cp $IMAGE_CONFIGS/logrotate/sonic.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/logrotate.d/ +sudo cp $IMAGE_CONFIGS/logrotate/rsyslog.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/logrotate.d/ # Copy systemd-journald configuration files sudo cp -f $IMAGE_CONFIGS/systemd/journald.conf $FILESYSTEM_ROOT/etc/systemd/ diff --git a/files/image_config/cron.d/logrotate b/files/image_config/cron.d/logrotate index fd09d1792a2e..212b6c08e1a2 100644 --- a/files/image_config/cron.d/logrotate +++ b/files/image_config/cron.d/logrotate @@ -1,2 +1,2 @@ # Attempt to rotate system logs once per minute -* * * * * root /usr/sbin/logrotate /etc/logrotate.conf +* * * * * root /usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1 diff --git a/files/image_config/logrotate/logrotate-config.sh b/files/image_config/logrotate/logrotate-config.sh index eabadec5e861..ab9fe0fa4719 100755 --- a/files/image_config/logrotate/logrotate-config.sh +++ b/files/image_config/logrotate/logrotate-config.sh @@ -7,7 +7,7 @@ RESERVED_SPACE_KB=1024 # Number of rotated archive files to keep per log file NUM_ARCHIVES_PER_LOG_FILE=7 -# Number of files to rotate in each block within sonic.j2 template +# Number of files to rotate in each block within rsyslog.j2 template NUM_LOG_FILES_SYSLOG=1 NUM_LOG_FILES_QUAGGA_TEAMD=3 NUM_LOG_FILES_SWSS=2 @@ -31,4 +31,4 @@ ADDITIONAL_DATA_JSON+="\"size_limit_quagga_teamd_kb\":$SIZE_LIMIT_QUAGGA_TEAMD_F ADDITIONAL_DATA_JSON+="\"size_limit_swss_kb\":$SIZE_LIMIT_SWSS_FILES_KB" ADDITIONAL_DATA_JSON+="}" -sonic-cfggen -a "$ADDITIONAL_DATA_JSON" -t /usr/share/sonic/templates/logrotate.d/sonic.j2 > /etc/logrotate.d/sonic +sonic-cfggen -a "$ADDITIONAL_DATA_JSON" -t /usr/share/sonic/templates/logrotate.d/rsyslog.j2 > /etc/logrotate.d/rsyslog diff --git a/files/image_config/logrotate/sonic.j2 b/files/image_config/logrotate/rsyslog.j2 similarity index 95% rename from files/image_config/logrotate/sonic.j2 rename to files/image_config/logrotate/rsyslog.j2 index 8653687c00b9..2c7a2ecf7db9 100644 --- a/files/image_config/logrotate/sonic.j2 +++ b/files/image_config/logrotate/rsyslog.j2 @@ -2,9 +2,9 @@ # # =========== Managed by SONiC Config Engine - DO NOT EDIT MANUALLY! =========== # Generated from: -# /usr/share/sonic/templates/logrotate.d/sonic.conf.j2 using sonic-cfggen +# /usr/share/sonic/templates/logrotate.d/rsyslog.j2 using sonic-cfggen # -# file: /etc/logrotate.d/sonic.conf +# file: /etc/logrotate.d/rsyslog # Logrotate configuration file for SONiC # {% endblock banner %} From e46090e1808a6ac3401fe254551f1be4dc3e8870 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 28 Jul 2017 17:16:59 +0000 Subject: [PATCH 10/11] Add comment re: percentages must sum to 100 --- files/image_config/logrotate/logrotate-config.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/files/image_config/logrotate/logrotate-config.sh b/files/image_config/logrotate/logrotate-config.sh index ab9fe0fa4719..246b88cec729 100755 --- a/files/image_config/logrotate/logrotate-config.sh +++ b/files/image_config/logrotate/logrotate-config.sh @@ -13,6 +13,7 @@ NUM_LOG_FILES_QUAGGA_TEAMD=3 NUM_LOG_FILES_SWSS=2 # Percentage of usable /var/log/ space to allocate to each block in template +# NOTE: These must sum to 100! PERCENT_ALLOCATED_SYSLOG=75 PERCENT_ALLOCATED_QUAGGA_TEAMD=15 PERCENT_ALLOCATED_SWSS=10 From b121c16292615566653b55e0021de787700fdf1b Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 31 Jul 2017 18:15:49 +0000 Subject: [PATCH 11/11] Reorder operations to reduce truncation and make more understandable --- files/image_config/logrotate/logrotate-config.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/image_config/logrotate/logrotate-config.sh b/files/image_config/logrotate/logrotate-config.sh index 246b88cec729..71f902856fbd 100755 --- a/files/image_config/logrotate/logrotate-config.sh +++ b/files/image_config/logrotate/logrotate-config.sh @@ -21,9 +21,9 @@ PERCENT_ALLOCATED_SWSS=10 VAR_LOG_SIZE_KB=$(df /var/log | sed -n 2p | awk '{print $2}') USABLE_SPACE_KB=$((VAR_LOG_SIZE_KB - RESERVED_SPACE_KB)) -SIZE_LIMIT_SYSLOG_FILES_KB=$((USABLE_SPACE_KB / (NUM_LOG_FILES_SYSLOG * (NUM_ARCHIVES_PER_LOG_FILE + 1)) / 100 * PERCENT_ALLOCATED_SYSLOG)) -SIZE_LIMIT_QUAGGA_TEAMD_FILES_KB=$((USABLE_SPACE_KB / (NUM_LOG_FILES_QUAGGA_TEAMD * (NUM_ARCHIVES_PER_LOG_FILE + 1)) / 100 * PERCENT_ALLOCATED_QUAGGA_TEAMD)) -SIZE_LIMIT_SWSS_FILES_KB=$((USABLE_SPACE_KB / (NUM_LOG_FILES_SWSS * (NUM_ARCHIVES_PER_LOG_FILE + 1)) / 100 * PERCENT_ALLOCATED_SWSS)) +SIZE_LIMIT_SYSLOG_FILES_KB=$(((USABLE_SPACE_KB * PERCENT_ALLOCATED_SYSLOG / 100) / (NUM_LOG_FILES_SYSLOG * (NUM_ARCHIVES_PER_LOG_FILE + 1)))) +SIZE_LIMIT_QUAGGA_TEAMD_FILES_KB=$(((USABLE_SPACE_KB * PERCENT_ALLOCATED_QUAGGA_TEAMD / 100) / (NUM_LOG_FILES_QUAGGA_TEAMD * (NUM_ARCHIVES_PER_LOG_FILE + 1)))) +SIZE_LIMIT_SWSS_FILES_KB=$(((USABLE_SPACE_KB * PERCENT_ALLOCATED_SWSS / 100) / (NUM_LOG_FILES_SWSS * (NUM_ARCHIVES_PER_LOG_FILE + 1)))) ADDITIONAL_DATA_JSON="{" ADDITIONAL_DATA_JSON+="\"num_archive_files\":$NUM_ARCHIVES_PER_LOG_FILE,"