From 81cc0ce3d338bf5a7ae43996c350995b00ded953 Mon Sep 17 00:00:00 2001 From: Arjen Heidinga Date: Wed, 25 Jul 2018 17:05:24 +0200 Subject: [PATCH 1/3] Allow cron to always mail its output. I was used to the fact that redhat always mails its output. I enabled the managed_cron bool, and added the --verbose startup argument (for debugging) and all mail went away... --- README.md | 4 ++++ manifests/cron.pp | 2 ++ manifests/init.pp | 3 ++- spec/defines/cron_spec.rb | 12 ++++++++++++ templates/etc/cron/logrotate.erb | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 180ccfc0..8e34052f 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/manifests/cron.pp b/manifests/cron.pp index ec74f7fd..435b4fe3 100644 --- a/manifests/cron.pp +++ b/manifests/cron.pp @@ -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 diff --git a/manifests/init.pp b/manifests/init.pp index 4713629d..8738d2c8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 = [], + Boolean $cron_always_output = false, ) inherits logrotate::params { contain ::logrotate::install diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 3c1e9b44..91da8243 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -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 diff --git a/templates/etc/cron/logrotate.erb b/templates/etc/cron/logrotate.erb index 177bb9e7..0e3d2932 100644 --- a/templates/etc/cron/logrotate.erb +++ b/templates/etc/cron/logrotate.erb @@ -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 From 19637b71e0e12273d44daed11883bfd3e1631684 Mon Sep 17 00:00:00 2001 From: Arjen Heidinga Date: Wed, 25 Jul 2018 17:05:24 +0200 Subject: [PATCH 2/3] Allow cron to always mail its output. I was used to the fact that redhat always mails its output. I enabled the managed_cron bool, and added the --verbose startup argument (for debugging) and all mail went away... --- README.md | 4 ++++ manifests/cron.pp | 2 ++ manifests/init.pp | 3 ++- spec/defines/cron_spec.rb | 12 ++++++++++++ templates/etc/cron/logrotate.erb | 4 ++++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 180ccfc0..8e34052f 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/manifests/cron.pp b/manifests/cron.pp index ec74f7fd..435b4fe3 100644 --- a/manifests/cron.pp +++ b/manifests/cron.pp @@ -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 diff --git a/manifests/init.pp b/manifests/init.pp index 4713629d..8738d2c8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 = [], + Boolean $cron_always_output = false, ) inherits logrotate::params { contain ::logrotate::install diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 3c1e9b44..91da8243 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -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 diff --git a/templates/etc/cron/logrotate.erb b/templates/etc/cron/logrotate.erb index 177bb9e7..0e3d2932 100644 --- a/templates/etc/cron/logrotate.erb +++ b/templates/etc/cron/logrotate.erb @@ -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 From d7486593d97d1e7f9fb663992f62e834a08d887c Mon Sep 17 00:00:00 2001 From: Arjen Heidinga Date: Fri, 27 Jul 2018 12:25:36 +0200 Subject: [PATCH 3/3] fix: Neglected to escape a character in test. --- spec/defines/cron_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 91da8243..dc2515cd 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -87,7 +87,7 @@ it { is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). with_ensure('present'). - with_content(%r{(else\n echo "${OUTPUT}"\nfi)}) + with_content(%r{(else\n echo "\${OUTPUT}"\nfi)}) } end end