2

We're using RPM for packaging and deployment of our product. Our product depends on other components, like postgresql database, etc., which are specified in our .spec file. Let's say, one of 3rd party component's configuration files must be patched before our product is installed (and reverted back after it's uninstalled). What's the correct procedure of doing so? Are there any examples of RPM packages that do the same?

Thanks!

1

RPM spec files support per-installation (%pre) and post-installation (%post) or pre-uninstallation (%preun) and post-uninstallation (%postun) scriptlets which can be used to update any system configuration before RPM package is installed or when it's removed.

You can check for example httpd package where in %pre section is defined to add apache user and in %post section is defined to enable the httpd service on boot.

rpm -q --scripts httpd

preinstall scriptlet (using /bin/sh):
# Add the "apache" user
getent group apache >/dev/null || groupadd -g 48 -r apache
getent passwd apache >/dev/null || \
  useradd -r -u 48 -g apache -s /sbin/nologin \
    -d /var/www -c "Apache" apache
exit 0
postinstall scriptlet (using /bin/sh):
# Register the httpd service
/sbin/chkconfig --add httpd
/sbin/chkconfig --add htcacheclean
preuninstall scriptlet (using /bin/sh):
if [ $1 = 0 ]; then
        /sbin/service httpd stop > /dev/null 2>&1
        /sbin/chkconfig --del httpd
        /sbin/service htcacheclean stop > /dev/null 2>&1
        /sbin/chkconfig --del htcacheclean
fi
posttrans scriptlet (using /bin/sh):
test -f /etc/sysconfig/httpd-disable-posttrans || \
 /sbin/service httpd condrestart >/dev/null 2>&1 || :

Here are the related sections in SPEC file for httpd package:

%pre
# Add the "apache" user
getent group apache >/dev/null || groupadd -g 48 -r apache
getent passwd apache >/dev/null || \
  useradd -r -u 48 -g apache -s /sbin/nologin \
    -d %{contentdir} -c "Apache" apache
exit 0

%post
# Register the httpd service
/sbin/chkconfig --add httpd

I thing Maximum RPM guide is the definitive source of information how to do this stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.