diff options
author | James Davidson <james.davidson@vyatta.com> | 2012-04-05 17:52:08 -0700 |
---|---|---|
committer | James Davidson <james.davidson@vyatta.com> | 2012-04-18 11:04:44 -0700 |
commit | 2415dea5aa5ecc1542b3da7795c0b7c49b98f259 (patch) | |
tree | 75c34b1c20ebbcf0dec9689bbb702f116363cc26 /scripts/system/vyatta_update_logrotate.pl | |
parent | f329c52b1d835aee551e2002e25937ed9447eb7d (diff) | |
download | vyatta-cfg-system-2415dea5aa5ecc1542b3da7795c0b7c49b98f259.tar.gz vyatta-cfg-system-2415dea5aa5ecc1542b3da7795c0b7c49b98f259.zip |
Use rsyslog to trigger log rotation
The previous implementation of log rotation used an hourly cron job to
check log file size and possibly perform a rotation. If the logging
rate is high, this interval may allow for root file system space
exhustion.
Utilizing rsyslog's outchannel mechanism enables log rotation to be
initiated as soon as the log file becomes larger than its configured
size.
Fixes Bug 7807.
Diffstat (limited to 'scripts/system/vyatta_update_logrotate.pl')
-rwxr-xr-x | scripts/system/vyatta_update_logrotate.pl | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/scripts/system/vyatta_update_logrotate.pl b/scripts/system/vyatta_update_logrotate.pl index a3a879ba..05867658 100755 --- a/scripts/system/vyatta_update_logrotate.pl +++ b/scripts/system/vyatta_update_logrotate.pl @@ -1,17 +1,25 @@ #!/usr/bin/perl +# Exit code: +# 0 - success +# 1 - missing parameter +# 2 - invalid files or size parameters +# 3 - unable to write logrotate config + use strict; -my $file = "messages"; +my $cfg_dir = "/opt/vyatta/etc/logrotate"; +my $file = "global"; my $log_file = "/var/log/messages"; +my $log_conf = "${cfg_dir}/$file"; if ($#ARGV == 3) { $file = shift; $log_file = "/var/log/user/$file"; + $log_conf = "${cfg_dir}/file_$file"; } my $files = shift; my $size = shift; my $set = shift; -my $log_conf = "/etc/logrotate.d/$file"; if (!defined($files) || !defined($size) || !defined($set)) { exit 1; @@ -25,7 +33,7 @@ if (!($files =~ m/^\d+$/) || !($size =~ m/^\d+$/)) { # (the detection mechanism in XORP doesn't work anyway) unlink $log_conf; -open my $out, '>>', $log_conf +open my $out, '>', $log_conf or exit 3; if ($set == 1) { print $out <<EOF; @@ -34,13 +42,9 @@ $log_file { notifempty rotate $files size=${size}k - postrotate - invoke-rc.d rsyslog reload >/dev/null - endscript } EOF } close $out; -exec '/usr/sbin/invoke-rc.d', 'rsyslog', 'restart'; -exit 4; +exit 0; |