The best way to update the unattended upgrade time, as I compiled it from various sources and tested on our system, is to exclusively use the systemctl
commands and avoid trying to find the proper files to edit.
The only thing you have to know for sure is the service name, which in our case, is apt-daily-upgrade
(if unsure, search for it via $ systemctl | grep apt
). When a systemd service has a timer defined, it is referenced as #{service_name}.timer
, thus it’s apt-daily-upgrade.timer
for us.
As the system configuration should not be edited, we’ll have to override the default timer config in systemd. For this you need to copy-edit some parts of the original config, so let’s show it first:
$ 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=12h
Persistent=true
[Install]
WantedBy=timers.target
We’ll need to update the OnCalendar
and RandomizedDelaySec
values in the [Timer]
section. Let’s create the override config file via the following command:
$ systemctl edit apt-daily-upgrade.timer
This should open an editor with a blank file and we need to put there the amended [Timer]
section, at least:
[Timer]
# Reset the system calendar config first
OnCalendar=
# Set a new calendar timer with a 60 minute threshold
OnCalendar=*-*-* 21:00
RandomizedDelaySec=60m
As you can see, we’ve updated the OnCalendar
value to trigger the automatic updates in the evenings, instead of mornings. The blank OnCalendar
line above it must be present as this config value is additive, i.e. it may be specified more than once and only setting it to a blank value resets all previous OnCalendar
values (the ones from the system config).
Once we save the file, we can verify that systemd knows about it (there’s no need to run systemctl daemon-reload
, the edit
command does that for us upon leaving the editor) by running systemctl
again as above:
$ 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=12h
Persistent=true
[Install]
WantedBy=timers.target
# /etc/systemd/system/apt-daily-upgrade.timer.d/override.conf
[Timer]
# Reset the system calendar config first
OnCalendar=
OnCalendar=*-*-* 21:00
RandomizedDelaySec=60m
Now it shows two configurations, with our custom one overriding the default one. Good!
The final check that it all works as expected can be done via the list-timers
command of systemctl
:
$ systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
...
Thu 2020-08-06 21:51:36 UTC 12h left Thu 2020-08-06 07:10:20 UTC 2h 20min ago apt-daily-upgrade.timer apt-daily-upgrade.service
...
Find the proper line in the output and look at the NEXT
column - the value in there should reflect the time of your newly configured unattended upgrade.