Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cron to always mail its output. #124

Merged
merged 5 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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] $logrotate_args = []
Array[String] $logrotate_args = [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please enforce a minimal string length like this:

Array[String[1]]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that is better. However, it belongs to pull request 80. I will fix it there.
https://github.com/Heidistein/puppet-logrotate/tree/pr80fix

Copy link
Author

@Heidistein Heidistein Jul 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in PR #127
I added only a trailing comma here, this was unrelated to this change.

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}' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI the :: aren't needed in front of logrotate

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