puppet: Merged puppet-report-cleanup from parameterize branch.

This commit is contained in:
Timo Makinen 2014-10-13 11:19:52 +03:00
parent 766f7d06a5
commit 3cf4363186
2 changed files with 35 additions and 15 deletions

View file

@ -249,12 +249,10 @@ class puppet::server {
# Database password. # Database password.
# #
# $puppet_report_maxage: # $puppet_report_maxage:
# Maximum age (in hours) to keep reports. Defaults to 720 hours (30 days). # Maximum age (in days) to keep reports. Defaults to 30 days.
# #
class puppet::server::common inherits puppet::client { class puppet::server::common inherits puppet::client {
include tmpwatch
if $::operatingsystem in ["CentOS","RedHat"] and $::operatingsystemrelease =~ /^[1-5]\..*/ { if $::operatingsystem in ["CentOS","RedHat"] and $::operatingsystemrelease =~ /^[1-5]\..*/ {
$seltype = "var_lib_t" $seltype = "var_lib_t"
} else { } else {
@ -477,20 +475,37 @@ class puppet::server::common inherits puppet::client {
require => Package["puppetmaster"], require => Package["puppetmaster"],
} }
if !$puppet_report_maxage {
$puppet_report_maxage = "30"
}
if $::operatingsystem != "OpenBSD" { if $::operatingsystem != "OpenBSD" {
if !$puppet_report_maxage {
$puppet_report_maxage = "720"
}
file { "/etc/cron.daily/puppet-report-cleanup": file { "/etc/cron.daily/puppet-report-cleanup":
ensure => present, ensure => absent,
content => template("puppet/puppet-report-cleanup.erb"),
mode => "0755",
owner => "root",
group => "root",
require => [ File["/srv/puppet/reports"], Package["tmpwatch"] ],
} }
} }
file { "/usr/local/sbin/puppet-report-cleanup":
ensure => present,
mode => "0755",
owner => "root",
group => $::operatingsystem ? {
"openbsd" => "wheel",
default => "root",
},
content => template("puppet/puppet-report-cleanup.erb"),
require => File["/srv/puppet/reports"],
}
cron { "puppet-report-cleanup":
ensure => present,
command => "/usr/local/sbin/puppet-report-cleanup",
user => $user,
hour => "1",
minute => "5",
require => File["/usr/local/sbin/puppet-report-cleanup"],
}
if $puppet_storeconfigs != "none" { if $puppet_storeconfigs != "none" {
file { "/usr/local/sbin/puppet-clean-storeconfigs": file { "/usr/local/sbin/puppet-clean-storeconfigs":
ensure => present, ensure => present,

View file

@ -1,6 +1,11 @@
#!/bin/sh #!/bin/sh
MAXAGE=<%= @puppet_report_maxage %> if [ "`whoami`" = "root" ]; then
echo "$0: must not be run as root"
exit 1
fi
/usr/sbin/tmpwatch -m ${MAXAGE} /srv/puppet/reports find /srv/puppet/reports/ -xdev -mindepth 2 -type f -mtime +<%= @puppet_report_maxage %> \
find /srv/puppet/reports/ -mindepth 2 -mmin +1440 -type f -name \*.yaml -exec gzip {} \; -name '*.yaml.gz' -execdir rm -f -- {} \;
find /srv/puppet/reports/ -xdev -mindepth 2 -type f -mtime +1 \
-name '*.yaml' -execdir gzip -- {} \;