There's an irony of you wanting to do a manual upgrade: Unattended Upgrades is already doing exactly that for you. When systemd detects that your newly-booted system has missed it's apt-update and apt-upgrade timers, it promptly triggers them.
- For most users, simply let those jobs complete -- it what you wanted to do anyway. Monitor
ps
or /var/run/apt/periodic
to find out when Unattended Upgrades finished it's work.
However, for your use case of long periods between booting, consider editing /etc/apt/apt.conf.d/20auto-upgrades
to disable automated updates and upgrades. We recommend against most users disabling merely so they can upgrade manually...folks tend to slack on that method after a few weeks.
Making Unattended Upgrades abortable is possible, but it's NOT RECOMMENDED for most general purpose users.
Edit /etc/apt/apt.conf.d/50unattended-upgrades
to enable this option:
// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGTERM. This makes the upgrade
// a bit slower but it has the benefit that shutdown while a upgrade
// is running is possible (with a small delay)
//Unattended-Upgrade::MinimalSteps "false";
Obviously, you must have a clear understanding of how to use SIGTERM.
Note that the same file has a setting to move Unattended Upgrades to shutdown (like Windows).
Alternately, automated updates and upgrades use systemd timers. You can change the time at which they run by simply editing /lib/systemd/system/apt-daily.timer and /lib/systemd/system/apt-daily-upgrade.timer. Remove the randomization and specify the constant time you wish.
For General Purpose Users: You probably don't need any of these tools, but they are available. In general, DO NOT INTERRUPT APT under most circumstances. Doing so inexpertly WON'T release the lock, and may damage your system. Cleaning up after an apt breakage can be confusing and tedious...and is completely avoidable. For most users (including experts), best practice is to simply wait 5-10 minutes until apt completes it's task. Good time for a sandwich.
- 5-10 minutes really means that. Be patient. The time to get concerned and seek help is if apt seems to make no progress for, say, 20 minutes or more. (20 minutes is not a rule -- that's my personal guideline).
Note that unattended-upgrades will stall for any number of reasons, including just a slow connection to one of the servers, but a stuck lockfile is also no excuse. It is simply poorly designed for a system process out of user control to block normal operation of the computer for extended periods of time for whatever reason. System processes must be designed with fault mitigation in mind.
– James Oct 13 '20 at 06:40sudo apt-get updates && sudo apt-get upgrade -y
could work better in some cases... Not voting it directly as answered because I need a solution to terminate one time unattended-upgrades and cast the updates commands manually, however you got a point. – user3450548 Sep 22 '21 at 14:17