Customize hourly fuel logrotate job for (ana)cron

Anacron would execute @hourly '20-fuel' logrotate job for Centos/Rhel
while cron (by default, anacron option configurable manually) would
do the same task for Ubuntu/Debian

Signed-off-by: Bogdan Dobrelya <bogdando@mail.ru>
This commit is contained in:
Bogdan Dobrelya 2013-07-11 13:38:47 +03:00
parent 9a5bc350c1
commit 8776494ad7
9 changed files with 127 additions and 12 deletions

View File

@ -0,0 +1,21 @@
#!/bin/bash
# managed by puppet
#
#!!! do not perform day checks here, cuz it would prevent hourly jobs from execution !!!
#in case file doesn't exist
#if test -r /var/spool/anacron/cron.daily; then
# day=`cat /var/spool/anacron/cron.daily`
#fi
#if [ `date +%Y%m%d` = "$day" ]; then
# exit 0;
#fi
#
# in case anacron is already running,
# there will be log (daemon won't be running twice).
if test -x /usr/bin/on_ac_power; then
/usr/bin/on_ac_power &> /dev/null
if test $? -eq 1; then
exit 0
fi
fi
/usr/sbin/anacron -s

View File

@ -0,0 +1,14 @@
#!/bin/sh
# managed by puppet
#
# anacron's cron script
#
# This script updates anacron time stamps. It is called through run-parts
# either by anacron itself or by cron.
#
# The script is called "0anacron" to assure that it will be executed
# _before_ all other scripts.
# Uncomment these lines below, if anacron should manage hourly schedules (by default, it does not)
#test -x /usr/sbin/anacron || exit 0
#anacron -u cron.hourly

View File

@ -0,0 +1,6 @@
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
01 * * * * root run-parts /etc/cron.hourly

View File

@ -0,0 +1,7 @@
# /etc/cron.d/anacron: crontab entries for the anacron package
# managed by puppet
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
30 7 * * * root start -q anacron || :

View File

@ -1,5 +1,5 @@
# /etc/anacrontab: configuration file for anacron
# managed by puppet
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
@ -11,7 +11,7 @@ RANDOM_DELAY=25
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
@hourly 5 cron.hourly nice ionice -c3 run-parts /etc/cron.hourly
1 5 cron.daily nice ionice -c3 run-parts /etc/cron.daily
7 25 cron.weekly nice ionice -c3 run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice ionice -c3 run-parts /etc/cron.monthly
@hourly 5 cron.hourly nice ionice -c3 run-parts --report /etc/cron.hourly
1 5 cron.daily nice ionice -c3 run-parts --report /etc/cron.daily
7 25 cron.weekly nice ionice -c3 run-parts --report /etc/cron.weekly
@monthly 45 cron.monthly nice ionice -c3 run-parts --report /etc/cron.monthly

View File

@ -0,0 +1,22 @@
# /etc/anacrontab: configuration file for anacron
# managed by puppet
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root
# These, except hourly, replace cron's entries
# If anacron should also manage hourly schedules (by default cron would do), uncomment @hourly job below,
# uncomment corresponding lines at /etc/cron.hourly/0anacron, and update corresponding cron job, like:
## 17 * * * * root cd / && run-parts --report /etc/cron.hourly
# to something like this:
## 17 * * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.hourly )
#period in days delay in minutes job-identifier command
#@hourly 5 cron.hourly nice ionice -c3 run-parts --report /etc/cron.hourly
1 5 cron.daily nice ionice -c3 run-parts --report /etc/cron.daily
7 25 cron.weekly nice ionice -c3 run-parts --report /etc/cron.weekly
@monthly 45 cron.monthly nice ionice -c3 run-parts --report /etc/cron.monthly

View File

@ -0,0 +1,13 @@
#!/bin/sh
# managed by puppet
#
# Due to bug existing, logrotate always returns 0. Use grep for detect errors:
# would return 1 (considered as normal result), if logrotate returns no errors, return 0, if any.
#/usr/sbin/logrotate /etc/logrotate.d/20-fuel.conf >/dev/null 2>&1
/usr/sbin/logrotate /etc/logrotate.d/20-fuel.conf >& /tmp/logrotate && grep -q error /tmp/logrotate
EXITVALUE=$?
if [ $EXITVALUE != 1 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE] (1 was expected)"
fi
exit 0

View File

@ -0,0 +1,13 @@
#!/bin/sh
# managed by puppet
# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
[ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.d/20-fuel.conf

View File

@ -1,12 +1,31 @@
# Make periodic cron jobs run in the idle scheduling class to reduce
# their impact on other system activities.
# Make anacron being manage 20-fuel logrotate job in /etc/cron.hourly
# for RHEL/CENTOS, and same by cron (it does by default) for DEBIAN/UBUNTU
class anacron::config {
file { '/etc/anacrontab':
source => 'puppet:///modules/anacron/anacrontab',
File {
ensure => file,
owner => root,
group => root,
mode => 0644,
}
case $::operatingsystem {
/(?i)(centos|redhat)/: {
# assumes package cronie-anacron were istalled at BM
file { '/etc/anacrontab': source => 'puppet:///modules/anacron/anacrontab', }
file { '/etc/cron.d/0hourly' : source => 'puppet:///modules/anacron/0hourly', }
file { '/etc/cron.hourly/logrotate' : mode => 0755, source => 'puppet:///modules/anacron/logrotate-hourly', }
file { '/etc/cron.hourly/0anacron' : mode => 0755, source => 'puppet:///modules/anacron/0anacron-hourly', }
}
/(?i)(debian|ubuntu)/: {
# assumes package anacron were installed at BM
file { '/etc/anacrontab': source => 'puppet:///modules/anacron/anacrontab-ubuntu', }
file { '/etc/cron.d/anacron' : source => 'puppet:///modules/anacron/anacron-ubuntu', }
file { '/etc/cron.hourly/logrotate' : mode => 0755, source => 'puppet:///modules/anacron/logrotate-hourly-ubuntu', }
file { '/etc/cron.hourly/0anacron' : mode => 0755, source => 'puppet:///modules/anacron/0anacron-hourly-ubuntu', }
}
}
}