RPM's scriptlet execution order is the following (rpm -U, triggers not included)
%pretrans
of the new package
%pre
of the new package
- (unpack new files)
%post
of the new package
%preun
of the old package
- (delete old leftover files)
%postun
of the old package
%posttrans
of the new package
(See also https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#ordering)
If you naively stop your service in %preun
and start it in %post
, you end up with the service not running after an update, because %preun
runs after %post
.
Since the scriptlets get arguments depending on whether they're being upgraded, removed or freshly installed, a workaround is to place the start command into the install-only part of %post
and into the upgrade-only part of %postun
.
To be on the safe side, one would have to mirror this change for stopping the service, but that is usually not that critical.
But since %preun
and %postun
reside in the old package, while %pre
and %post
reside in the new package, you run into a problem if the commands needed to start the service ever need to be changed.
This is why we usually start our services in %posttrans
instead of %post
.
Recently, we decided we don't want to depend on the unportable rpm-maven-plugin anymore and wanted to switch to rpm-builder.
Unfortunately, rpm-builder does not support %posttrans
.
Btw, I tried to develop a patch, but while I can build the plugin, I didn't have any luck building the packagedrone dependency, which also needs to be changed.
EDIT: I did some research, the tag IDs for %pretrans
and %posttrans
are as follows:
RPMTAG_PRETRANS = 1151,
RPMTAG_POSTTRANS = 1152,
RPMTAG_PRETRANSPROG = 1153,
RPMTAG_POSTTRANSPROG = 1154,
Source: http://ftp.rpm.org/api/4.11.1/group__rpmtag.html
See also:
#49
eclipse/packager#11