From 7071740ef047b3ec1daf20ce0d4d79c896fed640 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Fri, 17 Dec 2021 23:56:48 +0000 Subject: [PATCH] Addressing code review comments --- files/build_templates/sonic_debian_extension.j2 | 4 ++++ .../image_config/logrotate/logrotate-config.service | 12 ++++++++++++ files/image_config/logrotate/logrotate-config.sh | 4 ++++ .../logrotate/logrotate.d/{rsyslog => rsyslog.j2} | 11 ++++++++--- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 files/image_config/logrotate/logrotate-config.service create mode 100755 files/image_config/logrotate/logrotate-config.sh rename files/image_config/logrotate/logrotate.d/{rsyslog => rsyslog.j2} (93%) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 6cd852e6e8ea..fcd972a30ac3 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -377,6 +377,10 @@ echo "system-health.service" | sudo tee -a $GENERATED_SERVICE_FILE # Copy logrotate.d configuration files sudo cp -f $IMAGE_CONFIGS/logrotate/logrotate.d/* $FILESYSTEM_ROOT/etc/logrotate.d/ +sudo mv $IMAGE_CONFIGS/logrotate/logrotate.d/rsyslog.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ +sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM +sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.sh $FILESYSTEM_ROOT/usr/bin/ +echo "copp-config.service" | sudo tee -a $GENERATED_SERVICE_FILE # 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..b965e4b32425 --- /dev/null +++ b/files/image_config/logrotate/logrotate-config.service @@ -0,0 +1,12 @@ +[Unit] +Description=Update logrotate configuration +Requires=updategraph.service +After=updategraph.service + +[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..76caec6f035d --- /dev/null +++ b/files/image_config/logrotate/logrotate-config.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.j2 -a "{\"var_log_kb\":$(df -k /var/log | sed -n 2p | awk '{ print $2 }') }" > /etc/logrotate.d/rsyslog + diff --git a/files/image_config/logrotate/logrotate.d/rsyslog b/files/image_config/logrotate/logrotate.d/rsyslog.j2 similarity index 93% rename from files/image_config/logrotate/logrotate.d/rsyslog rename to files/image_config/logrotate/logrotate.d/rsyslog.j2 index b43f3f74c19d..2329d0ab1470 100644 --- a/files/image_config/logrotate/logrotate.d/rsyslog +++ b/files/image_config/logrotate/logrotate.d/rsyslog.j2 @@ -33,9 +33,13 @@ /var/log/frr/zebra.log /var/log/swss/sairedis*.rec /var/log/swss/swss*.rec -/var/log/swss/responsepublisher.rec +/var/log/swss/responsepublisher.ec { +{% if var_log_kb <= 204800 %} + size 1M +{% else %} size 16M +{% endif %} rotate 5000 missingok notifempty @@ -47,13 +51,14 @@ 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=16384 + 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 }') + VARL_LOG_SIZE_KB={{var_log_kb}} + #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))