3

There is a known behavior of anacron not to run when the laptop is running on batteries. Is there any way to stop this behavior and run anacron whatever the power state?

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=152402

http://www.mail-archive.com/[email protected]/msg560900.html

https://bugs.launchpad.net/ubuntu/+source/anacron/+bug/36816

1
  • Are you sure it's up to anacron ? cron.daily/apt, cron.daily/mlocate and cron.daily/apt-xapian-index do call /usr/bin/on_ac_power explicitly to check whether the script is being run on a battery. You could probably just comment these conditions within those scripts as a solution.
    – user40613
    Commented Jan 9, 2012 at 21:28

3 Answers 3

4

Please never change any files in /usr! Instead, you may change a line in the file /etc/default/anacron to

ANACRON_RUN_ON_BATTERY_POWER=yes

Thanks @Teresa e Junior. :)

1
  • Only works when not running systemd. Otherwise look at /usr/share/doc/anacron/README.Debian for instructions on creating /etc/systemd/system/anacron.service.d/on-ac.conf. The README tell what contents the file should be created with. This worked for me running daily snapshots with rsnapshot. I Have only tried this on Ubuntu 20.04, so not sure if it will work for other distros using systemd and not Debian based. This answer lead me to solving the issue for myself though ...thanks so much : ) Commented Feb 4, 2021 at 15:00
1

I found how to do this and summarized it in my blogpost

http://opensourceresearchtips.blogspot.com/2012/01/linux-anacron-tips.html

To change this behavior of anacron do the following:

 sudo gedit /usr/lib/pm-utils/power.d/anacron

and change to

case $1 in
    false)
 start -q anacron || :
 ;;
    true)
 start -q anacron || :
 ;;
esac
2
  • 5
    Just edit /etc/default/anacron, and set ANACRON_RUN_ON_BATTERY_POWER to yes. You should never edit files in /usr. Commented Oct 19, 2014 at 11:50
  • 1
    you may want to change this comment to an answer
    – ECII
    Commented Mar 25, 2015 at 7:57
1

For Debian based systems using systemd look at /usr/share/doc/anacron/README.Debian for instructions on creating /etc/systemd/system/anacron.service.d/on-ac.conf. The README tells what contents the file should be created with. This worked for me running daily snapshots with rsnapshot. I Have only tried this on Ubuntu 20.04. It seems likely that other distros may have a similar README in that directory. /etc/default/anacron has instructions to look in /usr/share/doc/anacron/README.Debian in Ubuntu 20.04. Thanks so much @mzuther : )

Just in case the README is not on someone's system the file contents should be:

[Unit]
ConditionACPower=

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .