Skip to content

Commit

Permalink
Merge pull request #124 from Heidistein/master
Browse files Browse the repository at this point in the history
Allow cron to always mail its output.
  • Loading branch information
bastelfreak authored Aug 7, 2018
2 parents 0dafd86 + 1d664af commit 04f1b28
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ class { '::logrotate':
```
## Examples

#### Cron output

Default the cron output is discarded if there is no error output. To enable this output, when you (for example) enable the verbose startup argument, enable the $cron_always_output boolean on the logrotate class.

```puppet
logrotate::conf { '/etc/logrotate.conf':
rotate => 10,
Expand Down
2 changes: 2 additions & 0 deletions manifests/cron.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
$_logrotate_args = $logrotate::logrotate_args
}

$cron_always_output = $logrotate::cron_always_output

$logrotate_args = join($_logrotate_args, ' ')

# FreeBSD does not have /etc/cron.daily, so we need to have Puppet maintain
Expand Down
3 changes: 2 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
Stdlib::Filemode $rules_configdir_mode = $logrotate::params::rules_configdir_mode,
String $root_user = $logrotate::params::root_user,
String $root_group = $logrotate::params::root_group,
Array[String[1]] $logrotate_args = []
Array[String[1]] $logrotate_args = [],
Boolean $cron_always_output = false,
) inherits logrotate::params {

contain ::logrotate::install
Expand Down
12 changes: 12 additions & 0 deletions spec/defines/cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
with_content(%r{(\/usr\/local\/sbin\/logrotate -s \/var\/lib\/logrotate\/logrotate.status -m \/usr\/sbin\/mailer \/usr\/local\/etc\/logrotate.conf 2>&1)})
}
end

context 'With additional arguments' do
let(:pre_condition) { 'class {"::logrotate": cron_always_output => true}' }
let(:title) { 'test' }
let(:params) { { ensure: 'present' } }

it {
is_expected.to contain_file('/usr/local/bin/logrotate.test.sh').
with_ensure('present').
with_content(%r{(else\n echo "\${OUTPUT}"\nfi)})
}
end
end
end
end
4 changes: 4 additions & 0 deletions templates/etc/cron/logrotate.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
echo "${OUTPUT}"
<% if @cron_always_output -%>
else
echo "${OUTPUT}"
<% end -%>
fi
exit $EXITVALUE

0 comments on commit 04f1b28

Please sign in to comment.