Sunday, March 13, 2022

[SOLVED] Configure dependencies in RPM

Issue

I have built a RPM-package for Centos 6.6 that is installed on a machine of our customer. This package contains our own software, customized for the specific use case, but also uses the open-source package HAProxy.

HAProxy (RPM-version 1.5.4-2.el6_7.1) comes with a default-configuration in /etc/haproxy/haproxy.conf and it cannot be customized without changing this file. But I want the configuration to be part my generated package. RPM throws an error if the /etc/haproxy/haproxy.conf file is in my package, because it is also part of the haproxy-package.

I have worked around this problem by providing a custom upstart-script which starts HAProxy with a different config file, but this does not seem to be the right way to do this.

Is there a preferred way to handle such customizations?


Solution

In cases like this, I've created an RPM which installs configuration files into a different subdirectory, and in its %post and %preun scriptlets modifies the uncooperative package's config-files:

  • when installing, I renamed the original config-files, and made symbolic links from those pathnames to the overwriting config-files, and
  • when uninstalling, the package removed the symbolic links and restored the original package's files.

Doing it that way of course meant that my config-RPM was dependent on the original RPM. A little awkward to describe, but it works.

In followup, the issue of updating was mentioned. Updating an RPM requires special handling to avoid uninstalling things. The rpm program passes a parameter $1 which you can test in the %pre and %preun scriptlets to notice that this is an upgrade and that there is no need to save the original config-files (or restore them). The rest of the scriptlet would be the same, by copying the new versions of your config-files over the others.

Further reading:



Answered By - Thomas Dickey
Answer Checked By - David Marino (WPSolving Volunteer)