Pages

Monday, 30 August 2021

Are you confused about cron, cronie, anacron?

1. Timelord

It all started with the god named Chronos who controlled the time. So the computer guys named their software "cron" as it's also used to manage time-related jobs.

The traditional cron daemon checks its configure files every one minute. As a result, the finest time graduality is min in crontab.

2. cron doesn't remember what it did before

One of the problems with cron is it doesn't guarantee to run the scheduled tasks. For example, you set a job to run at 5:00 am every day, but your computer is powered off during 12:00 am and 5:10 am. The crond doesn't remember what it has done or not, instead, it just skips any tasks scheduled before now.

3. Anacron for non-24x7 computers

To solve the issues above, anacron was developed. Anacron recorded what it did in files so it can reference those records to verify what needs to be done or skipped.
 
Anacron is NOT an alternative to cron.

First, anacron's minimal time interval is 1 day. You cannot schedule tasks more frequently than that.
Second, anacron is not a daemon, you need to run it through other means.

Actually, anacron is often run by cron. So here comes cronie project.

4. Cronie is a combination of cron and anacron

Cronie is a project/package which includes both traditional cron and anacron. 

For daily/weekly/monthly jobs, cron dispatch them to anacron to do them.

  1. crond reads /etc/crontab and /etc/cron.d/*
  2. /etc/cron.d/0hourly runs files under /etc/cron.hourly/
  3. /etc/cron.hourly/0anacron is used to run anacron hourly
  4. anacron reads /etc/anacrontab where jobs are defined to run files under:
    1. /etc/cron.daily
    2. /etc/cron.weekly
    3. /etc/cron.monthly
Even though cron itself can handle /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly by itself without the help of Anacron. But Anacron does a better job to deal with those tasks, so cron utilizes anacron to do them.

To be clear,

/etc/cron.hourly is handled by cron directly, while
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly are handled by cron via Anacron.

For normal users, they may not need to be aware of the existence of Anacron at all. It's safe to just take /etc/cron.daily/weekly/monthly as cron jobs.





No comments:

Post a Comment