On Wed, 21.07.10 20:08, Toshio Kuratomi (a.badger(a)gmail.com) wrote:
> - If you want to enable and possibly start a service from the
%post of
> an RPM then use the "systemd-install enable" command, which will
> create a few symlinks as listed in the [Install] section of the unit
> file. On top of that you may also pass --realize=... to the command,
> which allows you to not only enable the unit for the next boot, but
> also have the changes take effect immediately: i.e. --realize=reload
> is the very least you should use, which simply makes systemd aware of
> the changed symlinks. Then, at time of %preun you should use
> --realize=yes which makes sure the daemon is stopped in
> deinstallation. For a few daemons it makes sense to restart them if
> they are running already during upgrade. Use --realize=minimal for
> those. For even others (usually very low-level ones) it might even
> make sense to start them right-away after installation, even if they
> were not running before. For those use --realize=maybe. But which
> option you use really depends on the package. Most packages
> should probably stick to --realize=yes on %preun and --realize=reload
> in %post. Suggested .spec file fragments you find in the daemon(7) man
> page.
>
Normally, we don't want a service to be started just because the package has
been installed:
Yepp, which is why I said "very low-level ones", i.e. as low-level as
for example udev, which you really want to be running.
https://fedoraproject.org/wiki/Packaging/SysVInitScript.
This is the current recommended scriptlets:
%post
# This adds the proper /etc/rc*.d links for the script
/sbin/chkconfig --add <script>
%preun
if [ $1 = 0 ] ; then
/sbin/service <script> stop >/dev/null 2>&1
/sbin/chkconfig --del <script>
fi
%postun
if [ "$1" -ge "1" ] ; then
/sbin/service <script> condrestart >/dev/null 2>&1 || :
fi
I think I've got the %preun translated correctly but I'm not sure about
either the %post or %postun::
%post
# Don't need a %post as systemd automatically knows about the defaults?
It is needed:
if [ $1 -eq 1 ] ; then
# For new installations, hook unit file into the appropriate places via symlinks
/usr/bin/systemd-install enable --realize=reload %{unit name}.service >
/dev/null 2>&1 || :
else
# For old installations, just reload the configuration, don't change symlinks
/bin/bin/systemd-install realize --realize=reload %{unit name}.service >
/dev/null 2>&1 || :
fi
%preun
if [ $1 = 0 ] ; then
/usr/bin/systemd-install disable %{unit name}.service --realize=disable >
/dev/null 2>&1 || :
fi
Almost:
if [ $1 -eq 0 ] ; then
/usr/bin/systemd-install disable --realize=yes %{unit name}.service > /dev/null
2>&1 || :
fi
%postun
if [ "$1" -ge "1" ] ; then
# Can't figure out how to do a conditional restart here. Help?
fi
If you want to restart the service on upgrade I'd do that in %post. It
should be sufficient to replace --realize=reload by --realize=minimal
which will restart the unit if it is running, and only then.
Lennart
--
Lennart Poettering - Red Hat, Inc.