Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Changing logrotate size in 202106 #21

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,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/
Expand Down
12 changes: 12 additions & 0 deletions files/image_config/logrotate/logrotate-config.service
Original file line number Diff line number Diff line change
@@ -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

4 changes: 4 additions & 0 deletions files/image_config/logrotate/logrotate-config.sh
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
/var/log/swss/sairedis*.rec
/var/log/swss/swss*.rec
{
{% if var_log_kb <= 204800 %}
size 1M
{% else %}
size 16M
{% endif %}
rotate 5000
missingok
notifempty
Expand All @@ -51,7 +55,8 @@
# 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))
Expand Down