From 8776494ad7826c5b2090443c3c08e97b1b098227 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Thu, 11 Jul 2013 13:38:47 +0300 Subject: [PATCH] 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 --- .../puppet/anacron/files/0anacron-hourly | 21 ++++++++++++ .../anacron/files/0anacron-hourly-ubuntu | 14 ++++++++ deployment/puppet/anacron/files/0hourly | 6 ++++ .../puppet/anacron/files/anacron-ubuntu | 7 ++++ deployment/puppet/anacron/files/anacrontab | 10 +++--- .../puppet/anacron/files/anacrontab-ubuntu | 22 +++++++++++++ .../puppet/anacron/files/logrotate-hourly | 13 ++++++++ .../anacron/files/logrotate-hourly-ubuntu | 13 ++++++++ deployment/puppet/anacron/manifests/config.pp | 33 +++++++++++++++---- 9 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 deployment/puppet/anacron/files/0anacron-hourly create mode 100644 deployment/puppet/anacron/files/0anacron-hourly-ubuntu create mode 100644 deployment/puppet/anacron/files/0hourly create mode 100644 deployment/puppet/anacron/files/anacron-ubuntu create mode 100644 deployment/puppet/anacron/files/anacrontab-ubuntu create mode 100644 deployment/puppet/anacron/files/logrotate-hourly create mode 100644 deployment/puppet/anacron/files/logrotate-hourly-ubuntu diff --git a/deployment/puppet/anacron/files/0anacron-hourly b/deployment/puppet/anacron/files/0anacron-hourly new file mode 100644 index 0000000000..638016dfe2 --- /dev/null +++ b/deployment/puppet/anacron/files/0anacron-hourly @@ -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 diff --git a/deployment/puppet/anacron/files/0anacron-hourly-ubuntu b/deployment/puppet/anacron/files/0anacron-hourly-ubuntu new file mode 100644 index 0000000000..34fa487ef6 --- /dev/null +++ b/deployment/puppet/anacron/files/0anacron-hourly-ubuntu @@ -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 diff --git a/deployment/puppet/anacron/files/0hourly b/deployment/puppet/anacron/files/0hourly new file mode 100644 index 0000000000..8e5af0adf0 --- /dev/null +++ b/deployment/puppet/anacron/files/0hourly @@ -0,0 +1,6 @@ +SHELL=/bin/bash +PATH=/sbin:/bin:/usr/sbin:/usr/bin +MAILTO=root +HOME=/ +01 * * * * root run-parts /etc/cron.hourly + diff --git a/deployment/puppet/anacron/files/anacron-ubuntu b/deployment/puppet/anacron/files/anacron-ubuntu new file mode 100644 index 0000000000..395eab6668 --- /dev/null +++ b/deployment/puppet/anacron/files/anacron-ubuntu @@ -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 || : diff --git a/deployment/puppet/anacron/files/anacrontab b/deployment/puppet/anacron/files/anacrontab index c1980730e8..51a93138e4 100644 --- a/deployment/puppet/anacron/files/anacrontab +++ b/deployment/puppet/anacron/files/anacrontab @@ -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 diff --git a/deployment/puppet/anacron/files/anacrontab-ubuntu b/deployment/puppet/anacron/files/anacrontab-ubuntu new file mode 100644 index 0000000000..5c20f1458e --- /dev/null +++ b/deployment/puppet/anacron/files/anacrontab-ubuntu @@ -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 diff --git a/deployment/puppet/anacron/files/logrotate-hourly b/deployment/puppet/anacron/files/logrotate-hourly new file mode 100644 index 0000000000..7c17ed0cb3 --- /dev/null +++ b/deployment/puppet/anacron/files/logrotate-hourly @@ -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 diff --git a/deployment/puppet/anacron/files/logrotate-hourly-ubuntu b/deployment/puppet/anacron/files/logrotate-hourly-ubuntu new file mode 100644 index 0000000000..bc9b5cde29 --- /dev/null +++ b/deployment/puppet/anacron/files/logrotate-hourly-ubuntu @@ -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 diff --git a/deployment/puppet/anacron/manifests/config.pp b/deployment/puppet/anacron/manifests/config.pp index 1733fe00a4..64f36d81e1 100644 --- a/deployment/puppet/anacron/manifests/config.pp +++ b/deployment/puppet/anacron/manifests/config.pp @@ -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', - ensure => file, - owner => root, - group => root, - mode => 0644, - } + +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', } + } + } }