What is /usr/lib/apt/apt.systemd.daily [duplicate]
I am trying to understand how automatic upgrades are happening through the unattended-upgrades package. What is described below is what I found on a fresh install of Ubuntu 16.04.3.
/etc/cron.daily/apt-compat
has a line exec /usr/lib/apt/apt.systemd.daily
at the end which executes the script apt.systemd.daily
.
systemd also executes /usr/lib/apt/apt.systemd.daily
and it uses a timer. The systemd service definition doing the update can be found in /lib/systemd/system/apt-daily.service
. It calls the script apt.systemd.daily
with the argument update
while the systemd service definition in /lib/systemd/system/apt-daily-upgrade.service
calls the same script with the argument install
.
As I understand, /usr/lib/apt/apt.systemd.daily
is the script used by unattended-upgrades package to do the automatic upgrades. What I would like to know is why do both cron and systemd execute it?
The two jobs are complimentary, and the relationship is described in the cron job (16.04 and newer):
# Systemd systems use a systemd timer unit which is preferable to
# run. We want to randomize the apt update and unattended-upgrade
# runs as much as possible to avoid hitting the mirrors all at the
# same time. The systemd time is better at this than the fixed
# cron.daily time
On Ubuntu 16.04 and newer systems, the systemd timer is the important job. It does all the heavy lifting. The legacy cronjob merely triggers the systemd timer, in case for some reason it had been halted.
On Ubuntu 14.04 and older systems (non-Systemd), the system works quite differently: The cronjob triggers a run of unattended-updates.