Scheduling system maintenance cron jobs in CentOS/RHEL 6.xSeptember 5th, 2011
CentOS 6.x has changed how the default system maintenance cronjobs are scheduled. These are the cron jobs responsible for things like rotating logs and indexing files on the filesystem. That is routine jobs that are best scheduled to run at off peak times when the server is not busy doing more important things like serving money making websites. So how do you go about changing the timing of cron jobs on CentOS or RHEL 6.x?
First, a look at how the jobs are scheduled. We just follow the trail:
- Previously, in CentOS/RHEL 5.x system maintenance cronjobs were scheduled using the /etc/crontab file. This is no longer the case in CentOS 6.x. /etc/crontab is empty by default.
- Anacron is installed by default and is responsible for maintenance cron jobs. Anacron was originally created for running cron jobs on systems that aren’t switched on 24/7 i.e. desktop or workstation PCs. So why Redhat chose to include it by default in an enterprise operating system designed for servers that are always on is anyone’s guess.
- Anacron is run by crond via the 0anacron file in /etc/cron.hourly. Anacron does NOT run as it’s own daemon.
- Anacron is configured using /etc/anacrontab and executes the commands in the cron.daily/weekly/monthly directories:
SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # the maximal random delay added to the base delay of the jobs RANDOM_DELAY=45 # the jobs will be started during the following hours only START_HOURS_RANGE=20-22 #period in days delay in minutes job-identifier command 1 5 cron.daily nice run-parts /etc/cron.daily 7 25 cron.weekly nice run-parts /etc/cron.weekly @monthly 45 cron.monthly nice run-parts /etc/cron.monthly
So if you want to schedule system maintenance cron jobs to run at off-peak times you will have to tweak the START_HOURS_RANGE in /etc/anacrontab.
Or if you want more fine grained control you could just ditch anacron altogether and use /etc/cron.d/dailyjobs
yum remove cronie-anacron yum install cronie-noanacron sysstat
Don’t forget to start crond!
service crond start chkconfig crond on