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

Add support for AIX osfamily and refactoring #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
43 changes: 0 additions & 43 deletions manifests/base.pp

This file was deleted.

40 changes: 40 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class logrotate::config {

include ::logrotate

File {
owner => 'root',
group => '0'
}

file { $::logrotate::config_file:
ensure => file,
mode => '0444',
content => template('logrotate/etc/logrotate.conf.erb')
}

file { $::logrotate::config_dir:
ensure => directory,
mode => '0755'
}

file { $::logrotate::daily_cron_script:
ensure => file,
mode => '0555',
content => template('logrotate/etc/cron.daily/logrotate.erb')
}

# For O.S like AIX that does not have /etc/cron.{daily,hourly,...}
# feature, just create a standard cron task
if $::logrotate::has_cron_d_feature == false {
cron { 'logrotate-daily-task':
command => $::logrotate::daily_cron_script,
minute => ['25'],
hour => ['06'],
monthday => absent,
weekday => absent,
user => 'root',
ensure => 'present'
}
}
}
14 changes: 14 additions & 0 deletions manifests/defaults.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class logrotate::defaults {
case $::osfamily {
'Debian': {
include ::logrotate::defaults::debian
}
'RedHat': {
include ::logrotate::defaults::redhat
}
'SuSE': {
include ::logrotate::defaults::suse
}
default: { }
}
}
55 changes: 39 additions & 16 deletions manifests/hourly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# ensure => absent,
# }
class logrotate::hourly($ensure='present') {

include ::logrotate

case $ensure {
'absent': {
$dir_ensure = $ensure
Expand All @@ -25,21 +28,41 @@
}
}

file {
'/etc/logrotate.d/hourly':
ensure => $dir_ensure,
owner => 'root',
group => 'root',
mode => '0755';
'/etc/cron.hourly/logrotate':
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0555',
source => 'puppet:///modules/logrotate/etc/cron.hourly/logrotate',
require => [
File['/etc/logrotate.d/hourly'],
Package['logrotate'],
];
File {
owner => 'root',
group => '0'
}

$hourly_config_dir = "${::logrotate::config_dir}/hourly"

file { $hourly_config_dir:
ensure => $dir_ensure,
mode => '0755'
}

file { $::logrotate::hourly_cron_script:
ensure => $ensure,
mode => '0555',
content => template('logrotate/etc/cron.hourly/logrotate.erb'),
require => [
File[$hourly_config_dir],
Package[$::logrotate::package_name]
]
}

# For O.S like AIX that does not have /etc/cron.{daily,hourly,...}
# feature, just create a standard cron task
if $::logrotate::has_cron_d_feature == false {
if ! defined(Cron['logrotate-hourly-task']) {
cron { 'logrotate-hourly-task':
command => $::logrotate::hourly_cron_script,
minute => ['17'],
hour => absent,
monthday => absent,
weekday => absent,
user => 'root',
ensure => $ensure
}
}
}
}
15 changes: 15 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class logrotate(
$package_name = $::logrotate::params::package_name,
$package_ensure = $::logrotate::params::package_ensure,
$config_file = $::logrotate::params::logrotate_config_file,
$config_dir = $::logrotate::params::logrotate_config_dir,
$daily_cron_script = $::logrotate::params::logrotate_daily_cron_script,
$hourly_cron_script = $::logrotate::params::logrotate_hourly_cron_script,
$bin_path = $::logrotate::params::logrotate_bin_path,
$has_cron_d_feature = $::logrotate::params::has_cron_d_feature
) inherits ::logrotate::params {

class { '::logrotate::install': } ->
class { '::logrotate::config': } ->
class { '::logrotate::defaults': }
}
8 changes: 8 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class logrotate::install {

include ::logrotate

package { $::logrotate::package_name:
ensure => $::logrotate::package_ensure
}
}
23 changes: 23 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class logrotate::params {
$package_name = 'logrotate'
$package_ensure = 'latest'
$logrotate_config_file = '/etc/logrotate.conf'
$logrotate_config_dir = '/etc/logrotate.d'
$logrotate_bin_path = '/usr/sbin/logrotate'

case $::osfamily {
'AIX': {
# Note(riton):
# If someone finds a better place to drop those scripts, be my
# guest.
$logrotate_daily_cron_script = '/usr/bin/logrotate.daily'
$logrotate_hourly_cron_script = '/usr/bin/logrotate.hourly'
$has_cron_d_feature = false
}
default: {
$logrotate_daily_cron_script = '/etc/cron.daily/logrotate'
$logrotate_hourly_cron_script = '/etc/cron.hourly/logrotate'
$has_cron_d_feature = true
}
}
}
18 changes: 10 additions & 8 deletions manifests/rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,23 @@
#############################################################################
#

include logrotate::base
include ::logrotate

$hourly_config_dir = "${::logrotate::config_dir}/hourly"

case $rotate_every {
'hour', 'hourly': {
include logrotate::hourly
$rule_path = "/etc/logrotate.d/hourly/${name}"
include ::logrotate::hourly
$rule_path = "${hourly_config_dir}/${name}"

file { "/etc/logrotate.d/${name}":
file { "${::logrotate::config_dir}/${name}":
ensure => absent,
}
}
default: {
$rule_path = "/etc/logrotate.d/${name}"
$rule_path = "${::logrotate::config_dir}/${name}"

file { "/etc/logrotate.d/hourly/${name}":
file { "${hourly_config_dir}/${name}":
ensure => absent,
}
}
Expand All @@ -424,9 +426,9 @@
file { $rule_path:
ensure => $ensure,
owner => 'root',
group => 'root',
group => '0',
mode => '0444',
content => template('logrotate/etc/logrotate.d/rule.erb'),
require => Class['logrotate::base'],
require => Class['logrotate'],
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE
# OVERWRITTEN.

OUTPUT=$(/usr/sbin/logrotate /etc/logrotate.d/hourly 2>&1)
OUTPUT=$(<%= scope.lookupvar('::logrotate::bin_path') -%> <%= scope.lookupvar('::logrotate::config_file') -%> 2>&1)
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE
# OVERWRITTEN.

OUTPUT=$(/usr/sbin/logrotate /etc/logrotate.conf 2>&1)
OUTPUT=$(<%= scope.lookupvar('::logrotate::bin_path') -%> <%= @hourly_config_dir -%> 2>&1)
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ rotate 4
create

# packages drop log rotation information into this directory
include /etc/logrotate.d
include <%= @config_dir %>
Copy link
Author

Choose a reason for hiding this comment

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

Should be scope.lookupvar('::logrotate::config_dir').