Score:0

How can I find out when systemd schedules apt to auto-upgrade my packages?

at flag

The other day I found out that my Docker container had been killed as the docker daemon had been automatically upgraded on an AWS box I was running.

journald showed these messages in the relevant time slot:

Aug 06 05:56:01 ip-192-168-3-117 systemd[1]: Starting Daily apt download activities...
Aug 06 05:56:11 ip-192-168-3-117 systemd[1]: Started Daily apt download activities.
Aug 06 06:06:39 ip-192-168-3-117 systemd[1]: Starting Daily apt upgrade and clean activities...
Aug 06 06:06:48 ip-192-168-3-117 systemd[1]: Reloading.
Aug 06 06:06:48 ip-192-168-3-117 systemd[1]: Starting Message of the Day...
Aug 06 06:06:48 ip-192-168-3-117 systemd[1]: Reloading.
Aug 06 06:06:49 ip-192-168-3-117 systemd[1]: Reloading.
Aug 06 06:06:49 ip-192-168-3-117 systemd[1]: Stopping Docker Application Container Engine...

How can I know when this is scheduled to run? I looked through the various cron jobs in /etc and I thought /etc/cron.daily/apt-compat was involved, since it contained this at the end:

# delay the job execution by a random amount of time
random_sleep

# ensure we don't do this on battery
check_power || exit 0

# run daily job
exec /usr/lib/apt/apt.systemd.daily

but it turns out it never gets that far, as it actually just uses systemd. I overlooked this at the start of cron.daily/apt-compat:

# 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
if [ -d /run/systemd/system ]; then
    exit 0
fi

So somehow systemd schedules this to run instead.

That file, /usr/lib/apt/apt.systemd.daily, basically seems like the script responsible, although I cannot find any of the strings above, like "Starting .* activities".

So systemd is scheduling this, but where is this stored? Where does is it told to run /usr/lib/apt/apt.systemd.daily?

at flag
This was closed as a duplicate of https://askubuntu.com/questions/1006189/how-to-stop-apt-from-doing-anything, which has about nothing in common with this question. It asks how to stop Apt from doing anything, while I want to know where the time settings are stored for systemd. I do not mind a question being closed, but this was the wrong duplicate!
Score:4
us flag

That is a systemd timer. You can check the status of systemd timers using:

systemctl list-timers

It should list an apt-daily.timer. You can inspect its specification using:

systemctl show apt-daily.timer

The file is located in /lib/systemd/system/apt-daily.timer. (Do not edit that file directly if you want to modify the timer. See How do I override or configure systemd services?)

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.