RPM upgrade uninstalls the RPM
Asked Answered
A

4

30

I am upgrading our project RPM. The problem is when I upgrade from projectname-1.0-0 to projectname-1.0-1, it first installs the new project and uninstalls the old project, which, in overall view, removes my project entirely. I have used "vv" option while upgrading and the output showed the uninstallation is done after installation.

Somebody please help with this problem. Is there anything I should change specifically in the RPM spec or rpmbuild options?

Amieva answered 13/9, 2011 at 8:25 Comment(0)
B
65

Yes, when an RPM upgrade occurs, RPM first installs the new version of the package and then uninstalls the old version of the package. Only the files of the old package are removed. But your scripts (i.e. %pre, %post, %preun, %postun) need to know whether they are handling an upgrade or just a plain install or uninstall.

The rpm command will pass one argument to your scripts, that is, $1, which is a count of the number of versions of the package that are installed. The table below (from the RedHat RPM Guide by Eric Foster-Johnston) provides a sample of possible values.

Install the first time:          1
Upgrade:                         2 or higher 
                                 (depending on the number of versions installed)
Remove last version of package:  0

So, in your %preun, you probably want to check if "$1 = 0" before removing any services.

For more information (and a better table) see: http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html

Bolitho answered 9/11, 2011 at 22:19 Comment(2)
What if you already have package 1.0.0 in production and you can't modify its preun or postun and they do the wrong thing? As in override what package 1.0.1 just installed.Chamblee
RPM has a --noscripts flag to prevent any pre or post scripts from running. Not sure what, if anything, is the equivalent with yum.Afeard
E
10

When you upgrade a RPM package, scripts are executed in following order:

 1. %Pre of new package
     copy in files for new package
 2. %Post of new package
 3. %Preun of old package
     remove files of old package
 4. %Postun of old package

Whether the installation is fresh or upgrade, there is one argument passed to each script which represents number of RPMs installed of the same package with different versions. For pre & post scripts it will be 1 in case of first install. For preun & postun scripts it will be 0 for last uninstall.

What might be happening in your case is that preun or postun scripts might be deleting files that are useful for new package. You don't need to worry about manual file deletion in postun scripts, it will be handled intelligently be RPM itself.

ref: Upgrading & uninstalling

Exorable answered 26/12, 2014 at 9:28 Comment(1)
Interesting that the new package is installed before the old one is uninstalled. Seems backwards, but I'm sure there's a good reason for it!Janot
P
6

Yes. During the rpm install, the %install and %post scripts will be called. After successful installation, the %preun and %postun scripts will be called to uninstall the previous version of rpm. If not handled properly, these %preun and %postun scripts may manipulate the changes brought in by %install and %post scripts.

The rpm sets $1 argument with appropriate values to distinguish the number of rpm versions installed. During fresh installation of projectname-1.0-0, %install and %post scripts will be called with $1 set to 1 indicating that this is the only active version. When upgraded to projectname-1.0-1, %install and %post scripts will be called with $1 set to 2. After which, the %preun and %postun scripts will be called with $1 set to 1 so as to clean up stuffs of projectname-1.0-0. Thus by writing the spec file based on $1 value, we can handle the upgrades effectively.

Presnell answered 7/10, 2011 at 20:14 Comment(1)
%install is not ran during RPM installation but during build (yes, the name can be pretty misleading). I think you mean %pre.Durkin
F
0

it is important to understand how uninstall sections work on upgrade

We have a variable $1 which can be checked at pre, post, unpre, unpost (its value differs based on install, upgrade, uninstall) Depending on its value we can say whether it is install or upgrade from within rpm

E.g:

In Pre/post
if $1 == 1 initial installation
if $1 == 2 upgrade

In preun/postun
if $1 == 0 uninstall
if $1 == 1 upgrade

consider upgrading abc-1 from version 1 to version 2 (abc-2)

Run %pre from "abc-2".
Run %post from "abc-2".
Run %preun from "abc-1".
Run %postun from "abc-1".
Fur answered 19/8, 2018 at 11:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.