1

I am trying to understand how anacron works (in Fedora). I have three related questions. I am confused because of the following statement from the anacrontab manual:

The START_HOURS_RANGE variable defines an interval (in hours) when scheduled jobs can be run. In case this time interval is missed, for example, due to a power down, then scheduled jobs are not executed that day.

The first, main question is: What does the phrase "time interval is missed" mean?

I am aware that there are software clock and hardware clock, and that the software clock depends on the hardware clock. As I understand, if the power is down long enough, then after booting the system, the hardware clock has to be adjusted from the software clock, therefore the software clock has to be adjusted independently (manually or automatically).

So, here comes the second question: Does it mean that if anacron should have been run in the time that the system was down, and after booting – in the time anacron was running – it was still not having proper time, then anacron was thinking that it is not yet the time to run (and therefore it will not run)?

I realise that anacron is not a daemon itself, as stated in this stackexchange answer. As the Fedora documentation on anacron states, the anacron jobs are run by the crond daemon. Also, is states that the anacron jobs will be run as soon as the system is up.

So, here comes the third question: If the answer for the second question is "yes", then could the system time be adjusted before crond run anacron, and therefore anacron will run however (because at that time the time will be correct)?


UPDATE

Maybe let us have an example: let us suppose that I have scheduled anacron on Fedora to run some jobs daily – and the system normally is running all the time. I left the default configuration that Fedora provides, that is, anacron will run only within the time range 3:05 and 22:50 (I hope that I understand it correctly what the manual says) – if, of course, the system will be running in this time range. Now, let us suppose that there was a power down from 2:30 to 4:30, so Fedora started to boot at 4:30. Let us suppose that crond run anacron two minutes later (4:32), just as usual, and let us suppose that in that time the system clock was still not set correctly. Anacron sees that the system clock is set to 2:32, so it thinks "it is yet not the time to run my jobs, because I am scheduled to run them at 3:05 earliest".

From this I understand that it is not run that day (and the next time it will be run is the next day starting from 3:05).

And now the other case: let us suppose that the system time was adjusted at 2:31, one minute before crond will run anacron. When it runs anacron at 4:32 (now, the correct time), anacron sees the time and it thinks "OK, so I have to run my jobs. Let us wait the random delay that is defined in my configuration and run the jobs". It waits random delay between 4:32 4:37 and 5:17 5:22 and after that it runs its jobs.

Am I right?

Silv
  • 305
  • 1
  • 2
  • 12
  • anacron does not have a concept of "incorrect time" and always assumes it is correct. Therefore it will always run tasks that were missed when it was not active, when configured to do so. – Mio Rin Oct 16 '18 at 15:12
  • @Mioriin, thanks for clarifying. I suppose that you mean that I used a phrase "it was still not having proper time". Writing it, I meant the operating system still not having the proper time. – Silv Oct 16 '18 at 17:56

1 Answers1

2

Answering your questions in sequence:

  1. The interval would be missed if anacron is not invoked during it. It would not be invoked if it wasn't scheduled or if the machine was not running at the time when it would have been invoked. This has less to do with clocks and more to do with whether cron got around to actually run anacron or not.

  2. When cron (or an administrator) invokes anacron, it will run each scheduled job if required, i.e. if the job was last run more than the number of days specified in the anacrontab file. If anacron is not invoked, it will not run any scheduled jobs. Whether anacron executes on system startup is dependent on local configuration.

  3. If anacron is invoked, for example via a cron job, it will look at the current system time and compare that with its saved state files for each job. If that time difference is larger than what the anacrontab configuration file specifies for a job, anacron will run that job.

All three answers are essentially the same. anacron will run a job from its anacrontab if the conditions are correct (the job has not been run for a certain amount of time). anacron is often started by a cron job. This could be both a job that runs on system startup and every midnight or some other time (probably once daily). Linuxes that uses systemd might invoke anacron differently. If anacron is not executed, it obviously won't do anything.

If the system clock is not set correctly, this may influence whether a job gets run or not, depending on how much the clock is wrong at the time of running anacron and when the job was last run.

Kusalananda
  • 333,661
  • Kusalananda, thank you. In the case of the first question: I think that I start to get it. I suppose that my misunderstanding of the statement in the first question was coming from the situation that I was understanding the verb "to miss" too literally (as in "I missed the train" in the sense "I was trying to make it for the time that it was scheduled at, but could not"). In the case of the second and the third question, I still do not understand. Please see the update of my question, I put an example (it turned out to be too long for putting in the comment). – Silv Oct 16 '18 at 14:24
  • Kusalananda, I corrected the times in my example, if you have started to read it before. – Silv Oct 16 '18 at 14:47
  • Kusalananda, having your answer read a number of times – I think that I now understand what the manual states. So, my first question is answered. – Silv Oct 22 '18 at 13:48