29

我正在升级我们的项目 RPM。问题是当我从 projectname-1.0-0 升级到 projectname-1.0-1 时,它首先安装新项目并卸载旧项目,从总体上看,这完全删除了我的项目。我在升级时使用了“vv”选项,输出显示安装后卸载完成。

有人请帮助解决这个问题。在 RPM 规范或 rpmbuild 选项中有什么我应该特别改变的吗?

4

4 回答 4

64

是的,当发生 RPM 升级时,RPM 首先安装新版本的软件包,然后卸载旧版本的软件包。仅删除旧包的文件。但是您的脚本(即 %pre、%post、%preun、%postun)需要知道它们是在处理升级还是只是简单的安装或卸载。

rpm 命令将向您的脚本传递一个参数,即 $1,它是已安装软件包版本数的计数。下表(来自 Eric Foster-Johnston 的 RedHat RPM Guide)提供了可能值的示例。

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

因此,在您的 %preun 中,您可能想在删除任何服务之前检查“$1 = 0”是否。

更多信息(和更好的表格)参见:http ://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html

于 2011-11-09T22:19:27.370 回答
9

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

于 2014-12-26T09:28:39.323 回答
6

是的。在 rpm 安装期间,将调用 %install 和 %post 脚本。安装成功后,会调用 %preun 和 %postun 脚本卸载之前版本的 rpm。如果处理不当,这些 %preun 和 %postun 脚本可能会操纵 %install 和 %post 脚本带来的更改。

rpm 使用适当的值设置 $1 参数以区分安装的 rpm 版本的数量。在全新安装 projectname-1.0-0 期间,将调用 %install 和 %post 脚本,其中 $1 设置为 1,表示这是唯一的活动版本。升级到 projectname-1.0-1 后,%install 和 %post 脚本将被调用,$1 设置为 2。之后,%preun 和 %postun 脚本将被调用,$1 设置为 1,以清理 projectname 的东西-1.0-0。因此,通过基于 $1 值编写规范文件,我们可以有效地处理升级。

于 2011-10-07T20:14:47.807 回答
0

了解卸载部分在升级时的工作方式很重要

我们有一个变量 $1 可以在 pre、post、unpre、unpost 中检查(它的值根据安装、升级、卸载而不同)根据它的值,我们可以说它是从 rpm 中安装还是升级

例如:

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

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

考虑将 abc-1 从版本 1 升级到版本 2 (abc-2)

Run %pre from "abc-2".
Run %post from "abc-2".
Run %preun from "abc-1".
Run %postun from "abc-1".
于 2018-08-19T11:46:05.710 回答