Skip to content

Commit

Permalink
Manage cron subdirectories, if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Aug 26, 2024
1 parent c4e601d commit b13d094
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions manifests/cron.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@
}
}

if $logrotate::manage_cron_subdirectories {
case $facts['os']['family'] {
'FreeBSD': {}
default: {
$cron_dir = "/etc/cron.${name}"
ensure_resources('file', { $cron_dir => {
ensure => directory,
owner => $logrotate::root_user,
group => $logrotate::root_group,
} })

File <<| name == $script_path |>> {
require => File[$cron_dir]
}
}
}
}

file { $script_path:
ensure => $ensure,
owner => $logrotate::root_user,
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
String $root_group = $logrotate::params::root_group,
Array[String[1]] $logrotate_args = [],
Boolean $cron_always_output = false,
Boolean $manage_cron_subdirectories = true,
) inherits logrotate::params {
contain logrotate::install
contain logrotate::config
Expand Down
22 changes: 22 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,28 @@
it { is_expected.to contain_file('/etc/cron.hourly/logrotate').with_ensure('absent') }
end
end

context 'with logrotate rule' do
let(:params) {{
manage_cron_hourly: true,
rules: {
nginx: {
path: ['/var/log/nginx/*.log'],
rotate_every: 'hour',
}
}
}}

case os_facts['os']['name']
when 'FreeBSD'
it { is_expected.to contain_file('/usr/local/etc/logrotate.d/hourly').with_ensure('directory') }
else
it { is_expected.to contain_file('/etc/logrotate.d/hourly').with_ensure('directory') }
it { is_expected.to contain_file('/etc/logrotate.d/hourly/nginx').with_ensure('present').with_content(%r{/var/log/nginx/\*.log\s\{\n\s+hourly\n\}}) }
it { is_expected.to contain_file('/etc/cron.hourly').with_ensure('directory') }
it { is_expected.to contain_logrotate__rule('nginx') }
end
end
end
end
end
Expand Down

0 comments on commit b13d094

Please sign in to comment.