While I build rpm’s very often, there are always some facts I have to lookup on different sources. This article is indended to combine some interesting facts about rpm scriptlets to save time and maybe help somebody.

Order of execution

It is always a good idea to know about the order of execution to prevent strange behavior of your rpm packages. Specially the relationship between old and new package on update is quite interesting.

  1.  %pretrans of new package
  2.  %pre of new package
  3. (package install)
  4.  %post of new package
  5.  %triggerin of other packages (set off by installing new package)
  6.  %triggerin of new package (if any are true)
  7.  %triggerun of old package (if it’s set off by uninstalling the old package)
  8.  %triggerun of other packages (set off by uninstalling old package)
  9.  %preun of old package
  10. (removal of old package)
  11.  %postun of old package
  12.  %triggerpostun of old package (if it’s set off by uninstalling the old package)
  13.  %triggerpostun of other packages (if they’re setu off by uninstalling the old package)
  14.  %posttrans of new package

(source: https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#RPM_scriptlet_recipes)

Install/Uninstall/Update?

Some scriptlets get executed in multiple states of the rpm lifecycle. To differentiate these states, there are parameters given during execution.

 installupgradeuninstall
%pretrans$1 == 0$1 == 0 (N/A)
%pre$1 == 1$1 == 2(N/A)
%post$1 == 1$1 == 2(N/A)
%preun(N/A)$1 == 1$1 == 0
%postun(N/A)$1 == 1$1 == 0
%posttrans$1 == 0$1 == 0(N/A)

Scriptlet flag checks

A simple example to differenciate between the scriptlet flags.

%post
# restart service only on update and if it was running
if [ $1 -gt 1 ]; then
    if /sbin/service myservice status > /dev/null 2>&1; then
        echo "Restarting myservice service because it was running."
        if ! /sbin/service myservice restart ; then
                logger -s -t "%{name}" -- "Installation failure. Not able to restart the service."
                exit 1
        fi
    fi
fi

 

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden .