commit 9a04df09ebcda4cee1ab4a599b85fe0c97ccdb41 Author: David Shrewsbury Date: Mon May 7 16:19:07 2012 -0400 Added new logrotate puppet module. Allows us to easily manage log rotation. Example: logrotate::file { 'xyz': log => '/var/log/xyz.log', options => ['compress', 'weekly'], } Change-Id: I84fa3a20e0510a1273aa9b8555da0dde4613f50a diff --git a/manifests/file.pp b/manifests/file.pp new file mode 100644 index 0000000..6fcabda --- /dev/null +++ b/manifests/file.pp @@ -0,0 +1,20 @@ +define logrotate::file($log, + $options, + $prerotate='undef', + $postrotate='undef', + $firstaction='undef', + $lastaction='undef') { + + # $options should be an array containing 1 or more logrotate + # directives (e.g. missingok, compress). + + include logrotate + + file { "/etc/logrotate.d/${name}": + owner => root, + group => root, + mode => 644, + content => template("logrotate/config.erb"), + require => File["/etc/logrotate.d"], + } +} diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..ec29bc8 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,16 @@ +# Adapted from http://projects.puppetlabs.com/projects/1/wiki/Logrotate_Patterns + +class logrotate { + + package { "logrotate": + ensure => latest, + } + + file { "/etc/logrotate.d": + ensure => directory, + owner => root, + group => root, + mode => 755, + require => Package["logrotate"], + } +} diff --git a/templates/config.erb b/templates/config.erb new file mode 100644 index 0000000..58c8cf0 --- /dev/null +++ b/templates/config.erb @@ -0,0 +1,24 @@ +<%= log %> { +<% options.each do |opt| -%> <%= opt %> +<% end -%> +<% if prerotate != 'undef' -%> + prerotate + <%= prerotate %> + endscript +<% end -%> +<% if postrotate != 'undef' -%> + postrotate + <%= postrotate %> + endscript +<% end -%> +<% if firstaction != 'undef' -%> + firstaction + <%= firstaction %> + endscript +<% end -%> +<% if lastaction != 'undef' -%> + lastaction + <%= lastaction %> + endscript +<% end -%> +}