diff --git a/README.md b/README.md index 13ab20a..d04e9f1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ # OpenStack Logrotate Module This module installs and configures Logrotate + +Rotate logfiles using the logrotate::file defined type: + + +include logrotate +logrotate::file { 'manage_projects.log': + log => '/var/log/manage_projects.log', + options => [ + 'compress', + 'missingok', + 'rotate 30', + 'daily', + 'notifempty', + 'copytruncate', + ], +} + diff --git a/manifests/file.pp b/manifests/file.pp index f7c0873..685cc2d 100644 --- a/manifests/file.pp +++ b/manifests/file.pp @@ -1,19 +1,24 @@ # == Define: logrotate::file # -define logrotate::file( $log, +define logrotate::file ( + $log, $options, $ensure=present, $prerotate='undef', $postrotate='undef', $firstaction='undef', - $lastaction='undef') { + $lastaction='undef', +) { # $options should be an array containing 1 or more logrotate # directives (e.g. missingok, compress). + validate_string($options[0]) include logrotate + # This allows us to handle fully pathed files + $escaped_path = regsubst($name, '/', '_', 'G') - file { "/etc/logrotate.d/${name}": + file { "/etc/logrotate.d/${escaped_path}": ensure => $ensure, owner => 'root', group => 'root', @@ -21,4 +26,5 @@ define logrotate::file( $log, content => template('logrotate/config.erb'), require => File['/etc/logrotate.d'], } + }