[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Once again about anacron cron cron.daily



Harry Putnam wrote:
> I'm still not getting the whole picture of what is supposed to happen
> on a machine with both anacron and cron installed.

And you might be tired of having me respond about it.  :-)

> I have lines like the one below in /etc/crontab 
> 
> [...] test -x /usr/sbin/anacron || ( cd / && run-parts --report 
>                                                /etc/cron.daily )
> 
> Ok, it tests for the presence of /usr/sbin/anacron, checks that it is
> executable and sees to it that this user has permission to run it.

Yes.  The "this user" part is part that you trimmed off.  It runs as
the root user.  The root user will always have permission.  Let me
show the part you trimmed off.  (Times might be different.)

  25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
             ^^^^ runs as root

So basically if anacron is installed then it does nothing.  But if
anacron is not installed then it basically is the same as this and
runs the expected cron.daily.

  25 6    * * *   root    cd / && run-parts --report /etc/cron.daily

> But where and when does anacron actually get called to run?
> That line appears to expect anacron to be called somewhere else.

Yes.  The anacron itself is actually called from ... cron! :-)

  $ dpkg -L anacron
  /etc/cron.d/anacron
  ...

The cron.d file is file you are looking for.  That is the cron table
used by cron to run anacron.  Ignore the other files for the moment.

  30 7    * * *   root    test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null

Personally the above is too convoluted for my taste.  But basically
this runs anacron by cron.  It checks that /etc/init.d/anacron is
installed.  Why?  Because it is a 'conffile' and the local admin may
have removed it.  If it exists then it calls invoke-rc.d to launch
"/etc/init.d/anacron start".  Why invoke-rc.d?  Because the local
admin may have set up a policy-rc.d configuration that disables it.

It is this last part that I think is too far.  If the local admin were
to disable anacron wouldn't they also have disabled cron?  And if cron
is disabled then anacron which is downstream won't be run by it.  So I
think this is too convoluted.  But I wouldn't be surprised to find
that it was the result of a bug report.

> I've never taken any actions on anacron and don't remember even
> installing it purposely... so am I supposed to put it into a run
> level?

I can't believe I didn't recommend to you at some previous time that
you should probably just remove anacron.  Do you need it?  If not then
remove it.  (I would 'purge' it and remove the config files too.)

But because cron has added anacron in the cron package you will still
see anacron lint left behind even if anacron is not installed!
Because cron will be installed.  And cron has included config for
anacron in /etc/crontab.

> Or, does it get called somewhere else in the cron setup?

Yes!  You have guessed it.

Also there is apm support.  When power is plugged in and unplugged
then anacron is run or stopped.

  /etc/apm/event.d/anacron

  # This script makes anacron jobs start to run when the machine is
  # plugged into AC power, or woken up.  For a laptop, these are the 
  # closest parallels to turning on a desktop.

  # The /etc/init.d/anacron script now normally tries to avoid running
  # anacron unless on AC power, so as to avoid running down the battery.
  # (Things like the slocate updatedb cause a lot of IO.)  Rather than
  # trying to second-guess which events reflect having or not having
  # power, we just try to run anacron every time and let it abort if
  # there's no AC.  You'll see a message on the cron syslog facility 
  # (typically /var/log/cron) if it does run.

So in addition to cron starting anacron it is also run when AC power
is applied to the system.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: