如何使用 rpm 更新/替换现有文件?

发布于 2024-12-14 06:08:21 字数 553 浏览 0 评论 0原文

我有几个应用程序希望使用 rpm 进行部署。我的应用程序部署中的某些文件会覆盖其他已部署包中的文件。简单地在部署包中包含新文件会导致 rpm 冲突。

我正在寻找使用 rpm 更新/替换已安装文件的正确方法。

我已经想出了一些解决方案,但似乎没有一个是完全正确的。

  • 维护包含原始文件的 rpm 的自定义版本。

尽管与其他一些可能的解决方案相比,这看起来不像黑客,但回报却相对较小。

  • 将文件包含在 rpm 中并使用其他名称,并将它们复制到帖子部分。

这可行,但意味着系统中会散布多个文件副本。它还意味着对每个文件的 rpm 构建规范进行额外的维护。

  • 在帖子部分使用 wget 替换来自某个已知服务器的原始文件。

这与复制技术类似,但文件甚至不会存在于 rpm 中。不过,这可能就像一个很好的中央配置机构。

  • 将文件部署为新文件,然后使用符号链接覆盖原始文件。

这也类似于复制技术,但更简洁。这里的问题是某些文件不能很好地作为符号链接。

I have several applications that I wish to deploy using rpm. Some of the files in my application deployments override files from other deployed packages. Simply including the new files in the deployment package will cause rpm conflicts.

I am looking for the proper way to use rpm to update/replace already installed files.

I have already come up with a few solutions but nothing seems quite right.

  • Maintain custom versions of the rpms containing the original files.

This seems like a large amount of work for a relatively small reward even though it feels less like a hack than some of the other possible solutions.

  • Include the files in the rpm with another name and copy them over in the post section.

This would work but will mean littering the system with multiple copies of the files. Also it means additional maintenance in the rpm build spec for each file.

  • Use wget in the post section to replace the original files from some known server.

This is similar to the copy technique but the files wouldn't even live in the rpm. This might act like a nice central configuration authority though.

  • Deploy the files as new files, then use symlinks to override the originals.

This is also similar to the copy technique but with less clutter. The problem here is that some files don't behave well as symlinks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瑶笙 2024-12-21 06:08:21

据我所知,RPM 的设计不允许更新/替换现有文件,因此您所做的任何事情都将是一种黑客行为。

在您列出的选项中,如果目标系统是我管理的系统(正如您所说,这需要更多工作,但是最干净的解决方案),那么我会选择#1作为最不坏的黑客,并且选择#2和#4的组合(如果我正在为其他人的系统创建 RPM(以避免必须分发一堆 RPM,但我会在文档中非常清楚地说明我的内容),则在可能的情况下使用符号链接,在没有的情况下进行复制)正在做)。

您还没有描述哪些文件需要更新或替换以及如何更新它们。根据这些问题的答案,您可能有几个其他选项:

  • 许多程序设计为使用单个默认配置文件,并且还从 .d 子目录获取配置文件。例如,Apache 使用 /etc/httpd/conf/httpd.conf/etc/httpd/conf.d/*.conf,因此您的 RPM 可以将文件放在/etc/httpd/conf.d 而不是修改 /etc/httpd/conf/httpd.conf。如果您需要修改的文件是不遵循此模式但可以修改的配置文件,您可以建议包维护者添加此功能;这不会立即对您有帮助,但会使将来的版本更容易。
  • 对于可由多个包提供的诸如 sendmaillpr 之类的命令行实用程序,alternatives 系统(请参阅 man Alternatives code>) 允许超过 1 RPM,提供这些实用程序并排安装。同样,如果您需要修改的文件是不遵循此模式但可以执行的命令行实用程序,您可以建议包维护者添加此功能。
  • 您管理的系统上的配置文件更改可以通过 CfenginePuppet 而不是通过自定义 RPM。我认为红帽更喜欢 Puppet。
  • 如果我为我不管理的系统创建 RPM,我会考虑使用像 Bitrock 这样的第三方工具,并将我的所有内容转储到 /opt 下,这样我就不必踩踏其他管理员的 RPM 安装的文件。
  • 编辑(2019):如今,软件集合提供了一个有用的替代方案。您可以创建安装在 /opt 下某处的软件包,软件集合工具为用户提供了一种标准化的方式来选择使用这些软件包,而不是通常安装在 /usr 下的软件包。 。红帽使用它来分发较新版本的工具,以用于其稳定且长期(即较旧的)红帽企业 Linux 发行版。

To the best of my knowledge, RPM is not designed to permit updating / replacing existing files, so anything that you do is going to be a hack.

Of the options you list, I'd choose #1 as the least bad hack if the target systems are systems that I admin (as you say, it's more work but is the cleanest solution) and a combination of #2 and #4 (symlinks where possible, copies where not) if I'm creating the RPMs for others' systems (to avoid having to distribute a bunch of RPMs, but I'd make it very clear in the docs what I'm doing).

You haven't described which files need to be updated or replaced and how they need to be updated. Depending on the answers to those questions, you may have a couple of other options:

  • Many programs are designed to use a single default configuration file and also to grab configuration files from a .d subdirectory. For example, Apache uses /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/*.conf, so your RPMs could drop files under /etc/httpd/conf.d instead of modifying /etc/httpd/conf/httpd.conf. And if the files that you need to modify are config files that don't follow this pattern but could be made to, you can suggest to the package maintainers that they add this capability; this wouldn't help you immediately but would make future releases easier.
  • For command-line utilities like sendmail and lpr that can be provided by multiple packages, the alternatives system (see man alternatives) permits more than 1 RPM that provides these utilities to be installed side by side. Again, if the files that you need to modify are command-line utilities that don't follow this pattern but could be made to, you can suggest to the package maintainers that they add this capability.
  • Config file changes on systems that you administer are better managed through a tool like Cfengine or Puppet rather than through custom RPMs. I think that Red Hat favors Puppet.
  • If I were creating the RPMs for systems I don't administer, I'd consider using a third-party tool like Bitrock and dumping all of my stuff under /opt just so I wouldn't have to stomp on files installed by other admins' RPMs.
  • Edit (2019): Nowadays, Software Collections offers a useful alternative. You can create packages that install somewhere under /opt, and the Software Collections tools offer a standardized way for users to opt in to using those instead of whatever's normally installed under /usr. Red Hat uses this to distribute newer versions of tools for their otherwise stable and long-lived (i.e., older) Red Hat Enterprise Linux distributions.
忆伤 2024-12-21 06:08:21

您还可以执行 rpm -U --replacefiles --replacepkgs ...,这将为您提供您想要的内容。

You can also execute rpm -U --replacefiles --replacepkgs ..., which will give you what you want.

·深蓝 2024-12-21 06:08:21

有关 RPM %files 指令的更多信息,请参阅此处:

http://www.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html

您可以使用 RPM scriptlet 中 %post 和 %pre 部分的参数来确定如果你是安装、升级或删除软件包。

如果 $1 是 0 - 那么我们将删除旧的东西。目标安装了 0 个软件包。
如果 $1 是 1 - 那么我们正在安装新的东西。总共要安装 1 个软件包。
如果 $1 是 2 或更多 - 那么我们正在升级此软件包,并且 $1 代表已安装的软件包数量。

这些部分有助于管理版本之间的文件。
跟踪您在版本之间所做的事情,并考虑如果他们要跳过一两个版本,他们可能会做什么。

考虑到这些事情,你就可以开始了!

See here for more info on RPM %files directives:

http://www.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html

You can use the arguments from the %post and %pre sections in the RPM scriptlets to determine if you are installing, upgrading or removing packages.

If $1 is 0 - then we're removing old stuff. Targeting 0 packages installed.
If $1 is 1 - then we're installing new stuff. Targeting a total of 1 package to be installed.
If $1 is 2 or more - then we're upgrading this package and $1 represents the number of packages already installed.

These sections help with managing files among the versions.
Keep track of what you're doing between versions and consider what one might do if they were to skip a version or two.

Have consideration for these things and you should be good to go!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文