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/debian-bugs-dist@lists.debian.org/msg560900.html

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

ECII
  • 3,957
  • 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. –  Jan 09 '12 at 21:28

3 Answers3

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. :)

mzuther
  • 583
  • 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 : ) – Astral Axiom Feb 04 '21 at 15:00
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=
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
ECII
  • 3,957