apt daily timers are run by systemd:
me@me:~$ systemctl list-timers | grep apt
Wed 2022-11-30 00:42:17 CST 14h left Tue 2022-11-29 07:57:32 CST 2h 22min ago apt-daily.timer apt-daily.service
Wed 2022-11-30 06:41:41 CST 20h left Tue 2022-11-29 07:57:32 CST 2h 22min ago apt-daily-upgrade.timer apt-daily-upgrade.service
Note that there are two jobs:
- apt-daily =
apt update
- apt-daily-upgrade = unattended upgrades =
apt upgrade
for security upgrades only (configurable at /etc/apt/apt.conf.d/50unattended-upgrades)
Next, let's locate where the apt-daily timer is located:
me@me:~$ systemctl status apt-daily.timer | grep loaded
Loaded: loaded (/lib/systemd/system/apt-daily.timer; enabled; preset: enabled)
Since the file is located in /lib/systemd, it will be overwritten when the apt package gets updated. So we cannot make changes directly to that file.
Instead, let's write an override file in /etc.
First, we copy the file into /etc:
sudo cp /lib/systemd/system/apt-daily.timer /etc/systemd/system/
Next, we edit the file. Here's the original:
[Unit]
Description=Daily apt download activities
[Timer]
OnCalendar=*-*-* 6,18:00
RandomizedDelaySec=12h
Persistent=true
[Install]
WantedBy=timers.target
Look at the timer section. That's the part you want to edit to match times when your system is online.
For example, something like this might be more reasonable for a machine that get shut down daily. The apt-daily job will run sometime between 5 and 60
minutes after startup.
OnStartupSec=300
RandomizedDelaySec=3300
Overriding the timer of the second job (apt-daily-upgrade) is left as an exercise for the student.