I have been struggling with in various forms, year after year. See here and here. Either I am configuring something wrong (unlikely), or I am using my computer in a bizarre way (I don't see it).
My computer is a laptop:
- Before, I turned it off at night - as a result the
unattended-upgrade
could often not connect to the internet when it wanted to. Result: my computer was left un-upgraded and insecure for months on end. - These days I mostly stay logged in, but the hotspot connection is unavailable at night. So now, the
unattended-upgrade
runs but finds nothing to update, apparently becauseapt update
has not been able to run successfully. Result: my computer is left un-upgraded and insecure for months on end.
How can I ensure the systemd
timer for apt update
does not go weeks and months between runs?
Typical output of /var/log/unattended-upgrades/unattended-upgrades.log
2022-02-09 06:30:27,331 INFO Starting unattended upgrades script
2022-02-09 06:30:27,334 INFO Allowed origins are: o=Ubuntu,a=focal, o=Ubuntu,a=focal-security, o=UbuntuESMApps,a=focal-apps-security, o=UbuntuESM,a=focal-infra-security, o=UbuntuESM,a=focal-security
2022-02-09 06:30:27,335 INFO Initial blacklist:
2022-02-09 06:30:27,336 INFO Initial whitelist (not strict):
2022-02-09 06:30:40,279 INFO No packages found that can be upgraded unattended and no pending auto-removals
sudo systemctl status apt-daily
:
* apt-daily.service - Daily apt download activities
Loaded: loaded (/lib/systemd/system/apt-daily.service; static; vendor preset: enabled)
Active: inactive (dead)
TriggeredBy: * apt-daily.timer
Condition: start condition failed at Wed 2022-02-09 20:42:17 EET; 4h 17min ago
└─ ConditionACPower=true was not met
Docs: man:apt(8)
Feb 09 20:42:17 tbox systemd[1]: Condition check resulted in Daily apt download activities being skippe>
lines 1-9/9 (END)
sudo systemctl list-timers apt-daily
:
NEXT LEFT LAST PASSED UNIT ACTIVATES>
Thu 2022-02-10 16:15:14 EET 15h left Wed 2022-02-09 20:42:17 EET 4h 22min ago apt-daily.timer apt-daily>
1 timers listed.
Pass --all to see loaded but inactive timers, too.
lines 1-5/5 (END)
NB: there was a reboot a few hours ago. Not plugged in but was connected to network.
FINAL CONCLUSION. Going with version of the accepted solution below, shifting the apt-daily.timer
to a time when the internet connection is more likely to be available. Thanks for those who helped. The end.
Checking a stock Ubuntu Server 20.04 install, it looks like
unattended-upgrade
runs are triggered byapt-daily-upgrade.timer
. This triggers daily at 6am with a random delay up to an hour.A potentially simple solution is to override the
OnCalendar
setting so the timer triggers at a time more likely to be online. For exampleThis will trigger the timer at noon instead.
unattended-upgrade
should only run once per day by default. That is because of the setting forAPT::Periodic::Unattended-Upgrade
. Cherry picking a comment from/usr/lib/apt/apt.systemd.daily
The stock configuration value for this is
1
day.You can configure the timer to more frequently than once per day by adding apt configuration. The commented link of https://unix.stackexchange.com/a/541426/147262 has several suggestions. Here is a simple example of adding apt configuration
If you override the
apt-daily-upgrade.timer
then you might want to make the same override forapt-daily.timer
. This also has a corresponding apt configuration valueAPT::Periodic::Update-Package-Lists
.EDIT I've changed the suggestion from running hourly to running once per day at a time more likely to be online. I realized that the default setting of running once per day was not affected by whether or not
unattended-upgrade
actually had any packages to update. Therefore,unattended-upgrade
could still continue to only run when not online.comments
The upgrades run overnight by default to avoid interfering with user activity. You will no longer have that convenience.
You should change this setting using an override file, not by modifying the package installed service file
apt-daily.timer
triggers apt commands to update package information and to download available updates. If these commands continue to run when the network is not available thenunattended-upgrade
may not update anything because it may not know updates are available.