You are not logged in.
Is it possible to safely stop a system upgrade (pacman -Syu) once started? If so, at what point and how?
I couldn't find this in the wiki (pacman, faq on package management, pacman tips) or searching using startpage.com but I suspect I've missed something as it seems like an obvious question. (Also, I thought I'd read something about this but might be imagining it.)
Last edited by cfr (2013-09-03 20:49:06)
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
Have you tried Ctrl+C?
^C
Interrupt signal receivedworks for retrieving databases and packages, works for checking package integrity, loading package files etc. etc. up to an including upgrading the packages - it works all the way.
I have no idea how dangerous is it.
Offline
I wouldn't see a problem interrupting the upgrade, provided the packages were still being downloaded; once they were installing then the risk of subsequent b0rkage would start to increase assuming you did forget that you had interrupted an upgrade and later issued a pacman -S{,y} package without completing the interrupted upgrade (via -Syu)...
Offline
Thanks. I have not tried it. I am guessing it would work. I'm really interested in how safe or otherwise it would be!
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
You mean stop via a SIGINT/Ctrl-C, or some other method?
It's perfectly safe (almost) to stop pacman after it says what it will install and asks something to the effect of "do you want to continue [Y/n]". I have "almost" in parentheses as at that you have done the -Sy without allowing the 'u' to finish, so before anything else can be installed you would have to finish the -Syu to avoid a partial upgrade scenario.
As far as with Ctrl-C, there might be slightly more troublesome issues, but probably not by much. If you send a SIGINT during the any of the steps before actually installing the packages (eg checking package validity) it would be the same situation as above, except you'll already have the package files downloaded - so a bit like an -Syuw if I remember correctly what the 'w' flag does.
If you SIGINT during the installation stage - assuming it was directly between two packages (one completed, the next hadn't started) It would be much like above.
If you SIGINT in the middle of an actual installation step, then perhaps one of the devs could answer whether pacman gets the chance to cleanup or not, but I wouldn't be surprised if you did get a half installed package. But this would only be the one package that you caught right in the middle. Worst case here - even assuming pacman doesn't get the chance to clean up - you'll have a single broken package which could be found with a pacman -Qk or related command, then properly installed afterwards.
If there is no battery in a laptop, or on a desktop, and there is a power outage in the middle, then pacman certainly couldn't clean up the package it was in the middle of installing so the last mentioned issue might be more likely.
NOTE: this is all just based on the reasoning presented within this post - not on any knowledge of pacman's code.
EDIT: Just doing some fact checking (still without looking at pacman's code) and SIGINT is commonly handled the same as SIGTERM, for which - in general - the program would clean up any immediate issue before exiting. I *suspect* that if pacman were in the middle of the actual installation step for any package (actually moving files), then that package might just be removed, so this would be the same as the interrupt between two package installations. If it is not already done this way - or some even better way - this would be a reasonable feature request for pacman, but again, I'd guess this is already done. SIGKILL or the power outage, though, might still leave a half-installed package.
Last edited by Trilby (2013-09-02 23:10:02)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
While testing this out (I wasn't 100% sure I can abort at every step) I issued 'pacman -Su' every time and nothing bad happened.
What's the use case for aborting an upgrade?
Offline
From pacman.c (lines ~310):
} else if(signum == SIGINT || signum == SIGHUP) {
if(signum == SIGINT) {
msg = "\nInterrupt signal received\n";
} else {
msg = "\nHangup signal received\n";
}
xwrite(err, msg, strlen(msg));
if(alpm_trans_interrupt(config->handle) == 0) {
/* a transaction is being interrupted, don't exit pacman yet. */
return;
}
}So pacman will not exit on a SIGINT in an "unclean" state. But if I'm reading the code correctly, SIGTERM might leave things in a less clean state.
Last edited by Trilby (2013-09-02 23:17:40)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
and if youre paranoid after the signal run testdb
end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'the machine is not the end to the means., we are. In history, in board rooms and politic the greatest decision and effort
evolves from passion, lust for life, and a common sense of humanity. Never forget what you are and why'. -me
Offline
Pacman operations are not atomic, so killing it during package installation can result in an unusable system if the packages are critical. For example, if the package queue includes a library and executables that depend on it, then interrupting the operation after installation of the library but before installation of the executables will leave the existing executables unable to run.
If the packages are non-critical (e.g. an image editor or media player), then simply re-running the command should clean up any mess left by the aborted operation.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
You mean stop via a SIGINT/Ctrl-C, or some other method?
Any method. At least, any practically available method.
Thanks for your (and others') analyses.
The use case which I had in mind (having just initiated such a situation) was one where I idiotically issue a pacman -Syu and OK installation before I realise that the network I'm on is much slower than I realised and that I have a choice between sitting in the hotel stairwell for half the night while the upgrade finishes (assuming my battery lasts), leaving the laptop and hoping it is still there in the morning, or somehow aborting the upgrade. The hotel had misconfigured their wifi access points with the effect that although I had an excellent signal in my room, I couldn't connect to the network except by sitting in the stairwell.
In this particular case, the download rate apparently speeded up so I was able to finish the upgrade without sitting on the stairs for more than an hour or so. However, it looked as if it would be a lot longer originally and I would have preferred not to spend more than an hour, to be honest. Hence the question. Plus once it occurred to me I realised it was just the kind of situation I would probably get myself into again at some point and that other people might be equally idiotic (or maybe not) and want to know the same thing. Anyway, by the time I'd done a web search and searched the wiki and posted and so on, the network had apparently let me download the updates and complete the upgrade.
So I was most interested in the safety of stopping the upgrade during the download of packages and of the safest way to do so. Is ^c really the safest method?
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
In that situation, the downloading is the only part that would be slow. Pacman does not download and install each package in sequence; it downloads *all* the packages that are to be upgraded, then only upgrades them once they are all stored locally (there may be exceptions to this if you use some alternate downloading agent with some parallelization set up - but not vanilla pacman).
So breaking at any time in the download would not be any issue at all. It would be like a partial `pacman -Syuw`. The only issue might come from a later partial upgrade if you did another `pacman -S <pkg>` without completing the Syu.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Ah, OK. Thanks. I can see pacman downloads everything first so that's fine. I'll just ^c if I end up there again. I'm may or may not remember I've done this but I'm also unlikely (statistically) to run pacman -S <pkg> so the chances of my messing things up will be fairly low. (Requires unusual circumstances + idiocy (fairly usual) + forget + run pacman -S <pkg> + pick <pkg> which causes major issues rather than just not working. That's not worth sitting on the stairs all night for!)
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
You can use this script to ensure that you never forget:
#!/bin/bash
set -e
PACMAN_EXE=/usr/bin/pacman
if [[ -z $1 ]]
then
echo "usage: $0 <temporary database directory> [pacman options]" >&2
exit 1
fi
dbdir="$(readlink -f "$1")"
shift
mkdir -p "$dbdir"
ln -fst "$dbdir" /var/lib/pacman/local
"$PACMAN_EXE" --dbpath "$dbdir" -Syw "$@"Use it download packages to the cache, e.g. download all upgradable packages along with foo, bar and baz:
$ pacsyw -u foo bar bazThe system sync db will not be touched but the packages will download to the system cache. You can then run "pacman -Syu foo bar baz" when you want without having to wait for the downloads. Aborting pacsyw is not dangerous, although it may leave some metafiles in the cache, depending on your download manager. Those are trivial to clean up and will normally be purged automatically the next time the download runs.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline