Checking a stock Ubuntu Server 20.04 install, it looks like unattended-upgrade
runs are triggered by apt-daily-upgrade.timer
. This triggers daily at 6am with a random delay up to an hour.
root@ubuntu:~# systemctl cat apt-daily-upgrade.timer
# /lib/systemd/system/apt-daily-upgrade.timer
[Unit]
Description=Daily apt upgrade and clean activities
After=apt-daily.timer
[Timer]
OnCalendar=*-*-* 6:00
RandomizedDelaySec=60m
Persistent=true
[Install]
WantedBy=timers.target
A potentially simple solution is to override the OnCalendar
setting so the timer triggers at a time more likely to be online. For example
mkdir /etc/systemd/system/apt-daily-upgrade.timer.d
cat <<EOF >/etc/systemd/system/apt-daily-upgrade.timer.d/override.conf
[Timer]
OnCalendar=
OnCalendar=*-*-* 12:00
EOF
systemctl daemon-reload
This will trigger the timer at noon instead. unattended-upgrade
should only run once per day by default. That is because of the setting for APT::Periodic::Unattended-Upgrade
. Cherry picking a comment from /usr/lib/apt/apt.systemd.daily
# APT::Periodic::Unattended-Upgrade "0";
# - Run the "unattended-upgrade" security upgrade script
# every n-days (0=disabled)
The stock configuration value for this is 1
day.
root@ubuntu:~# apt-config dump APT::Periodic::Unattended-Upgrade
APT::Periodic::Unattended-Upgrade "1";
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
cat <<EOF > /etc/apt/apt.conf.d/90myuu
> APT::Periodic::Unattended-Upgrade "always";
> EOF
If you override the apt-daily-upgrade.timer
then you might want to make the same override for apt-daily.timer
. This also has a corresponding apt configuration value APT::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
Are there any potential downsides to overclocking the daily timer like that?
The upgrades run overnight by default to avoid interfering with user activity. You will no longer have that convenience.
ConditionACPower=true was not met. You can change that setting
You should change this setting using an override file, not by modifying the package installed service file
mkdir /etc/systemd/system/apt-daily-upgrade.service.d
cat <<EOF > /etc/systemd/system/apt-daily-upgrade.service.d/override.conf
[Unit]
ConditionACPower=false
EOF
systemctl daemon-reload
What would be the reason for, or downsides to, overriding apt-daily.timer too?
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 then unattended-upgrade
may not update anything because it may not know updates are available.