Bug 431865 - anacron and crond both run cron.daily
anacron and crond both run cron.daily
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: anacron (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: Marcela Mašláňová
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-02-07 09:57 EST by Jonathan Kamens
Modified: 2008-03-27 06:15 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-03-27 06:15:40 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jonathan Kamens 2008-02-07 09:57:55 EST
I rebooted my machine at around 1:45am this morning.  After it rebooted, both 
anacron and crond decided to run cron.daily, which had rather negative effects 
on my system, since my nightly backup job, which takes a number of hours, 
overlapped between the two runs.

Here's yesterday's update to the cron.daily timestamp:

Feb  6 03:03:01 jik2 CROND[25408]: (root) CMD (run-parts /etc/cron.daily)
Feb  6 03:03:01 jik2 run-parts(/etc/cron.daily)[25415]: starting 000-delay.cron
Feb  6 03:54:13 jik2 run-parts(/etc/cron.daily)[26612]: finished 000-delay.cron
Feb  6 03:54:13 jik2 run-parts(/etc/cron.daily)[26614]: starting 0anacron
Feb  6 03:54:13 jik2 run-parts(/etc/cron.daily)[26622]: finished 0anacron
Feb  6 03:54:13 jik2 run-parts(/etc/cron.daily)[26624]: starting backup
Feb  6 03:54:13 jik2 anacron[26620]: Updated timestamp for job `cron.daily' to 
2008-02-06
Feb  6 04:38:04 jik2 run-parts(/etc/cron.daily)[27762]: finished backup

And here's what happened this morning:

Feb  7 01:45:43 jik2 anacron[2861]: Anacron 2.3 started on 2008-02-07
Feb  7 01:45:43 jik2 anacron[2861]: Will run job `cron.daily' in 65 min.
Feb  7 01:45:43 jik2 anacron[2861]: Will run job `cron.weekly' in 70 min.
Feb  7 01:45:43 jik2 anacron[2861]: Jobs will be executed sequentially
Feb  7 02:50:43 jik2 anacron[2861]: Job `cron.daily' started
Feb  7 02:50:43 jik2 run-parts(/etc/cron.daily)[10208]: starting 000-delay.cron
Feb  7 03:03:01 jik2 CROND[10524]: (root) CMD (run-parts /etc/cron.daily)

Note that when anacron started during reboot and decided that it needed to run 
cron.daily, it was less than 24 hours after the cron.daily timestamp was last 
updated, so I don't think it should have done that.

Perhaps I've got the root cause wrong, but one thing is certain -- rebooting 
your machine shouldn't cause anacron and crond to both decide to run cron.daily.
Comment 1 Marcela Mašláňová 2008-02-20 06:35:08 EST
Could you attach whole log from the "what happened this morning" (also the time
before)?

I was trying to solve this before. It should be working this was:
If you don't reboot, only cron.daily will be run at 4:02. If you shut down your
computer, then anacron run cron.daily, with 65 + delay ('uniq' for computer)
minutes delay. It could be possible that you restarted computer in the middle of
cron.daily process before the time stamp of process was created.
Comment 2 Jonathan Kamens 2008-02-20 15:27:16 EST
It is obvious from the log excerpts shown above that I did not restart my 
computer in the middle of cron.daily.  As the log excerpts shown, on my 
computer, cron.daily is run by crond at 3:03am, and as I said in the ticket, I 
rebooted at 1:45am.

The problem is that anacron's logic for determining whether a day has elapsed 
since the last time the job was run is flawed.  All it does is calculate the 
day number of the current day, subtract it from the day number the last time 
the job was run, and see if the difference is greater than or equal the desired 
frequency of the job.  This is obviously the logic from looking at consider_job 
in lock.c in the anacron sources.

In other words, between midnight and when crond runs the cron.daily, if the 
machine reboots then anacron will run the job and then crond will run it as 
well.  This is wrong and dangerous when there are jobs that will break if they 
are run twice at the same time.

The simplest solution is to subtract the two actual timestamps (current - last 
run) and determine if the resulting number of seconds / 60 / 60 / 24 + 60 
exceeds the period of the job.  That is, determine if the exact minute during 
which cron should have started the job and updated its timestamps has passed.
Comment 3 Marcela Mašláňová 2008-03-27 06:15:40 EDT
Now, I read the log file twice and find out there's no problem ;-)

> Feb  7 01:45:43 jik2 anacron[2861]: Anacron 2.3 started on 2008-02-07
> Feb  7 01:45:43 jik2 anacron[2861]: Will run job `cron.daily' in 65 min.
> Feb  7 01:45:43 jik2 anacron[2861]: Will run job `cron.weekly' in 70 min.
> Feb  7 01:45:43 jik2 anacron[2861]: Jobs will be executed sequentially
> Feb  7 02:50:43 jik2 anacron[2861]: Job `cron.daily' started
> Feb  7 02:50:43 jik2 run-parts(/etc/cron.daily)[10208]: starting 000-delay.cron
Here's starting the first job in /etc/cron.daily, but as you can see there
wasn't updated timestamp. So the cron jobs weren't done and they were run again. 

If you don't switch off your computer than the cron.daily will run at 4:02. If
you reboot before 4:02 or switch off the computer, than the cron.daily will run
after 65minutes.

You can send me a patch with better solution, if the example in comment#2 is
working well. I'd like to review it.

Note You need to log in before you can comment on or make changes to this bug.