[Rpm-maint] post/preun scripts and updating

Michael Schroeder mls at suse.de
Tue May 29 13:18:06 UTC 2007


On Tue, May 29, 2007 at 03:04:44PM +0200, Lenz, Mario (LDS) wrote:
> I'm not sure if this is the correct mailing list, but I
> havn't found anything else. Maybe you can point me to
> somewhere where I get help if I'm wrong here :-)
> 
> I've tried to build my own rpm package with a postinstall
> script that starts the daemon that is part of it (chkconfig 
> mydaemon on; /etc/init.d/mydaemon start) and a preuninstall
> script to stop it (chkconfig mydaemon off; /etc/init.d/mydaemon
>  stop). But if I build a new rpm and run an update, the daemon is
> turned off. It looks to me that the preun- script of the old
> package ist run *after* the post- script of the new one. So
> of course the daemon is turned off. So there are two questions:
> 
> 1) Am I right? If so, I could stop searching for errors I made
> in the spec- file.

Yes, the uninstall of the old package is done after the install of
the new package. There is actually a bit of method to the madness:
Say you have a package libfoo which exists in two versions that
don't conflict: libfoo-1 and libfoo-2. An update to libfoo-2
is exactly equivalent to:

1) first installing libfoo-2
   now the system contains both versions of the library.
   The post install scripts of libfoo-2 get run.

   Later:
2) deleting the old libfoo-1
   The uninstall scripts of libfoo-1 get run.

> 2) How could I do what I want: Start a daemon when installing
> and stop it when deinstalling, but "update- proof".

You'll have to check $1 in the scripts, it contains the number
of installed versions of the package.

preinstall/postinstall:
  $1 == 1  -> first install of package
  $1 > 1   -> update

preuninstall/postuninstall

  $1 == 0  -> all versions deleted
  $1 > 0   -> it's just an update

Cheers,
  Michael.

-- 
Michael Schroeder                                   mls at suse.de
SUSE LINUX Products GmbH, GF Markus Rex, HRB 16746 AG Nuernberg
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}



More information about the Rpm-maint mailing list