From 5f4c7fa7685d7a95b85c305e1a55a4eaa02eedc1 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Mon, 7 May 2012 16:19:07 -0400 Subject: [PATCH] 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 --- modules/logrotate/manifests/file.pp | 20 ++++++++++++++++++++ modules/logrotate/manifests/init.pp | 16 ++++++++++++++++ modules/logrotate/templates/config.erb | 24 ++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 modules/logrotate/manifests/file.pp create mode 100644 modules/logrotate/manifests/init.pp create mode 100644 modules/logrotate/templates/config.erb diff --git a/modules/logrotate/manifests/file.pp b/modules/logrotate/manifests/file.pp new file mode 100644 index 0000000000..6fcabda37d --- /dev/null +++ b/modules/logrotate/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/modules/logrotate/manifests/init.pp b/modules/logrotate/manifests/init.pp new file mode 100644 index 0000000000..ec29bc85da --- /dev/null +++ b/modules/logrotate/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/modules/logrotate/templates/config.erb b/modules/logrotate/templates/config.erb new file mode 100644 index 0000000000..58c8cf0031 --- /dev/null +++ b/modules/logrotate/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 -%> +}