Is it on and when does it run
Both values "1" and both timers enabled mean updates run once a day.
Ubuntu's service that installs updates from allowed origins once a day on an apt timer; by default only security ones.
systemctl list-timers 'apt-daily*'
when the next run is
cat /etc/apt/apt.conf.d/20auto-upgrades
is it switched on
apt-config dump | grep -E '^APT::Periodic|^Unattended-Upgrade::'
sudo unattended-upgrade --dry-run -v
what it would install
sudo ls /var/log/unattended-upgrades/
run logs
sudo needrestart -b
who needs a restart
ls /var/run/reboot-required
is a reboot needed
unattended-upgrades installs updates with no one at the keyboard. apt timers start it:
| Step | Timer → service | What it does |
|---|---|---|
| 1 | apt-daily.timer → apt-daily.service |
refreshes package lists once a day, like apt update |
| 2 | apt-daily-upgrade.timer → apt-daily-upgrade.service |
runs unattended-upgrade at 6:00 plus a random delay of up to 60 minutes |
| 3 | the DPkg::Post-Invoke hook in 99needrestart |
after installation, restarts services that run old files |
Persistent=true means that if the machine was off at 6:00, the run
happens after boot. The unattended-upgrades.service unit ("Unattended
Upgrades Shutdown") does not install anything: it waits for shutdown so
as not to cut an installation short.
Steps 1 and 2 are switched on by 20auto-upgrades; the number is the
interval in days:
On the lab machine (unattended-upgrades 2.9.1) 20auto-upgrades turns on
both steps, but the timers and the service are off (disabled), and there
is no network. The old package lists hold about a hundred and fifty updates,
over a hundred of them from noble-security, and a trial run fails at the
download:
The first line is about a development release and has nothing to do with an LTS server. The trial run takes about a minute: the program goes through every candidate.
The origins are the Allowed-Origins list in 50unattended-upgrades. A
package is installed if its origin (o= — who publishes it, a= — the
archive suite) matches one of the lines:
${distro_id}:${distro_codename} is the noble release itself, which
does not change after release. The -updates line in the file is
commented out, so by default only security updates arrive. The ESM suites
work with an Ubuntu Pro subscription attached.
An update changes files on disk. A running program keeps executing the
old ones: its file is deleted but still open — an
open unlinked file. Until the service is
restarted, the fix does not apply to it. The demo-sleep binary was
replaced, and the demo-old service keeps running:
An old shared library stays in memory the same
way — marked (deleted) in /proc/<PID>/maps (see
proc-filesystem). After systemctl restart demo-old the process
starts from the new file, and the mark is gone.
Restarting services does not update the kernel. A package that needs a
reboot creates /var/run/reboot-required; the machine reboots by itself
only if Automatic-Reboot is on.
needrestart finds processes running old files and names their
services. -r sets the mode: l only lists, a restarts, i asks.
-b prints lines for scripts:
KCUR is the running kernel, KEXP the newest installed one, KSTA: 1
means they match and no reboot is needed. SVC is a service to restart.
On Ubuntu the apt hook calls needrestart after every installation, and by
default it restarts services by itself — /etc/needrestart/needrestart.conf
says so:
Some services it leaves alone even in mode a: their list is the
$nrconf{override_rc} key. Such services go to a separate list:
Here demo-lib is deferred by a line in /etc/needrestart/conf.d/demo.conf:
A deferred service is restarted by hand when it is safe.
/var/log/unattended-upgrades/ is readable by root and the adm group:
| File | What it holds |
|---|---|
unattended-upgrades.log |
which packages were installed and why others were skipped |
unattended-upgrades-dpkg.log |
dpkg output during installation |
unattended-upgrades-shutdown.log |
what the service did at shutdown |
On the lab machine the directory is empty: the upgrade has never run, and
unattended-upgrades.service is off. Timer runs show in journalctl -u
apt-daily-upgrade.
The settings are in apt format in /etc/apt/apt.conf.d/. The files are
read in alphabetical order: 20auto-upgrades is the switch,
50unattended-upgrades says what to install and how. Keep your own values
in a separate file numbered above 50: a package upgrade may offer to
replace 50unattended-upgrades, but it leaves your file alone.
A plain value from a later file replaces the earlier one, while list
items { … } are added to the earlier ones. apt-config dump shows the
result:
The main settings are in the directives table below. The machine's
50unattended-upgrades has Automatic-Reboot "false",
Remove-Unused-Dependencies "false" and Mail "" commented out — those
are the defaults.
| Directive | What it does | Example |
|---|---|---|
APT::Periodic::Update-Package-Lists 20auto-upgrades |
How often, in days, to refresh the package lists; 0 turns it off. | APT::Periodic::Update-Package-Lists "1"; |
APT::Periodic::Unattended-Upgrade 20auto-upgrades |
How often, in days, to run unattended-upgrade; 0 means no automatic updates. | APT::Periodic::Unattended-Upgrade "1"; |
Unattended-Upgrade::Allowed-Origins 50unattended-upgrades |
The list of "origin:suite" sources packages may come from; by default only -security. | Unattended-Upgrade::Allowed-Origins { "${distro_id}:${distro_codename}-security"; }; |
Unattended-Upgrade::Package-Blacklist 50unattended-upgrades |
Packages not to upgrade; the names are regular expressions. | Unattended-Upgrade::Package-Blacklist { "postgresql-"; }; |
Unattended-Upgrade::Automatic-Reboot 50unattended-upgrades |
Reboot the machine when an update needs it (/var/run/reboot-required exists). | Unattended-Upgrade::Automatic-Reboot "true"; |
Unattended-Upgrade::Automatic-Reboot-Time 50unattended-upgrades |
The reboot time instead of "right after the update". | Unattended-Upgrade::Automatic-Reboot-Time "03:30"; |
Unattended-Upgrade::Remove-Unused-Dependencies 50unattended-upgrades |
Remove dependencies that are no longer needed, like apt autoremove. | Unattended-Upgrade::Remove-Unused-Dependencies "true"; |
Unattended-Upgrade::Mail 50unattended-upgrades |
The address for the run report; the machine needs working mail delivery. | Unattended-Upgrade::Mail "admin@example.org"; |
Nothing found. Try a shorter query.
Both values "1" and both timers enabled mean updates run once a day.
The names are regular expressions: postgresql- matches every package
starting with it. Check with sudo unattended-upgrade --dry-run -v: the
names show up in the Initial blacklist: line.
20auto-upgrades has "0" or does not exist.systemctl is-enabled apt-daily-upgrade.timer.failed to download, aborting.Allowed-Origins or is in
Package-Blacklist.unattended-upgrades.log and --dry-run -v give the reason a package was
skipped.
apt says Could not get lock /var/lib/dpkg/lock-frontend. It is held by
process … (unattended-upgr). A scheduled installation is running. Wait
for it — systemctl status apt-daily-upgrade. A dpkg process killed in
the middle of an installation leaves packages half-installed.
The service runs an old copy of a file: (deleted) in
/proc/<PID>/maps, a line in lsof +L1, the service in needrestart -r
l. Restart it. A kernel update needs a reboot: /var/run/reboot-required
exists, uname -r is older than the installed kernel.
needrestart restarted it after a scheduled update. The time matches the
apt-daily-upgrade run, the packages are in
unattended-upgrades-dpkg.log. To exclude the service, use the
$nrconf{override_rc} key in /etc/needrestart/conf.d/*.conf.
Without Automatic-Reboot-Time the machine reboots right after an update
that needs it — in the middle of a working day. Set the time of your
maintenance window.
Security updates change little and rarely break things. The -updates
suite and third-party repositories bring new versions, and those would
land at night with no check. Update such sources by hand.
apt-daily* timers work.lsof +L1 and open unlinked files./proc/<PID>/maps and exe.Found an inaccuracy? Report an error in the article