15

I was reading about the differences between cron and anacron and I realized that anacron, unlike cron is not a daemon. So I'm wondering how does it work actually if it's not a daemon.

Stephen Kitt
  • 434,908
tgwtdt
  • 435

2 Answers2

21

It uses a variety of methods to run:

  • if the system is running systemd, it uses a systemd timer (in the Debian package, you’ll see it in /lib/systemd/system/anacron.timer);
  • if the system isn’t running systemd, it uses a system cron job (in /etc/cron.d/anacron);
  • in all cases it runs daily, weekly and monthly cron jobs (in /etc/cron.{daily,weekly,monthly}/0anacron);
  • it also runs at boot (from /etc/init.d/anacron or its systemd unit).
Stephen Kitt
  • 434,908
6

anacron is not a daemon, and therefore it needs to be run periodically by other means. Most often, this means executing it with a cron job once a day, and possibly on bootup as well.

This may look like the following in root's crontab, for example:

@reboot /usr/local/sbin/anacron -ds
@daily  /usr/local/sbin/anacron -ds

Linux systems that uses systemd may do this differently, obviously, but still need to facilitate at least one run of anacron per 24 hour period.

Running anacron more than once every 24 hours is pointless as the shortest period one can schedule jobs through anacron is once a day.

Kusalananda
  • 333,661
  • Thanks. (1) I was wondering what "not a daemon" means? (2) regarding your last sentence: "The systemd timer runs anacron hourly to reduce the delay between resuming a suspended system and the next anacron run" https://unix.stackexchange.com/questions/478803/is-it-true-that-cron-daily-runs-anacron-everyhour/478842#comment875696_478842 – Tim Nov 01 '18 at 11:13