2

On Ubuntu server 22.04, how do you control when the automatic daily update check happens?

One of my servers doesn't have internet access during certain (known) periods. When the automatic update happens it hangs forever if there is no internet access. Even with internet access resumes, the update stays hung and I have to manually kill it then do a manual update.

I'd like to keep the automatic update feature, but I need to limit it to certain days/hours.

I found this thread which claims that for 18.04 one should set up a chron job to toggle a couple settings:

How can I ban Software Updater from checking for updates at certain times of day or certain days of week?

But, the settings it specifies don't exist:

# gsettings get org.gnome.software download-updates 
No such schema “org.gnome.software”

gsettings get org.gnome.software allow-updates

No such schema “org.gnome.software”

2 Answers2

2

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.

user535733
  • 68,493
1

The short answer is:

# systemctl edit --full apt-daily.timer

That will copy the existing file to /etc/systemd/... and open it in $EDITOR. Make changes to OnCalendar= and RandomizedDelaySec= lines, save file, exit editor. Using systemctl edit will trigger loading of the new/edited file after editor exits.

# systemctl status apt-daily.timer

The above should show new file in use (/etc/systemd/...) and expected trigger time.

Repeat above with apt-daily-upgrade.timer:

# systemctl edit --full apt-daily-upgrade.timer

[...]