You are not logged in.

#1 2013-09-02 22:38:17

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,173

[Ans: yes] Possible to safely stop upgrade?

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

#2 2013-09-02 22:55:46

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Ans: yes] Possible to safely stop upgrade?

Have you tried Ctrl+C?

^C
Interrupt signal received

works 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

#3 2013-09-02 23:01:34

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [Ans: yes] Possible to safely stop upgrade?

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)...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2013-09-02 23:01:52

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,173

Re: [Ans: yes] Possible to safely stop upgrade?

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

#5 2013-09-02 23:02:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,459
Website

Re: [Ans: yes] Possible to safely stop upgrade?

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

#6 2013-09-02 23:07:27

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Ans: yes] Possible to safely stop upgrade?

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

#7 2013-09-02 23:14:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,459
Website

Re: [Ans: yes] Possible to safely stop upgrade?

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

#8 2013-09-02 23:54:11

rufus
Banned
From: san francisco
Registered: 2013-04-20
Posts: 153

Re: [Ans: yes] Possible to safely stop upgrade?

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

#9 2013-09-03 01:42:26

Xyne
Forum Fellow
Registered: 2008-08-03
Posts: 6,965
Website

Re: [Ans: yes] Possible to safely stop upgrade?

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 StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#10 2013-09-03 19:49:06

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,173

Re: [Ans: yes] Possible to safely stop upgrade?

Trilby wrote:

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

#11 2013-09-03 20:27:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,459
Website

Re: [Ans: yes] Possible to safely stop upgrade?

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

#12 2013-09-03 20:48:43

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,173

Re: [Ans: yes] Possible to safely stop upgrade?

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

#13 2013-09-03 21:45:10

Xyne
Forum Fellow
Registered: 2008-08-03
Posts: 6,965
Website

Re: [Ans: yes] Possible to safely stop upgrade?

You can use this script to ensure that you never forget:

pacsyw
#!/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 baz

The 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 StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB