Here is new version of the proposal I sent to systemd-devel some minutes
ago.
The big change is dropping %service_add_enabled : systemd folks doesn't
want to hardcode policy for a service as part of packagings and would
prefer some separate files to handle that (see
http://lists.freedesktop.org/archives/systemd-devel/2011-June/002755.html and http://lists.freedesktop.org/archives/systemd-devel/2011-July/002801.html ). Until this happens, I suggest we use "/bin/systemctl enable foobar.service >/dev/null 2>&1 || :" in specfiles.
Other changess :
-%service_* macros are expecting full unit name (sshd.service,
foobar.socket)
-%service_* macros accept several units files as parameters
(the various macros could be modified by distro if they also want to
support sysvinit service with the same macro, but it is outside the
scope of this initial proposal)
%service_add()
if [ "$1" -eq 1 ] ; then
# Initial installation
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
fi
%service_del_preun()
if [ "$1" -eq 0 ] ; then
# Package removal, not upgrade
/bin/systemctl --no-reload disable %{?*} > /dev/null 2>&1 || :
/bin/systemctl stop %{?*} > /dev/null 2>&1 || :
fi
%service_del_postun()
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
if [ "$1" -ge 1 ] ; then
# Package upgrade, not uninstall
/bin/systemctl try-restart %{1} >/dev/null 2>&1 || :
fi
(this macro could refer to different package, if people don't agree on
systemd-units as packagename)
%define systemd_requires()
# This is for /bin/systemctl
Requires(post): systemd-units \
Requires(preun): systemd-units \
Requires(postun): systemd-units \
%service_migrate_to_systemd(l)
{-l:LEVEL="-l $1 ; shift }
for service in %{?*} ; do \
if /sbin/chkconfig $LEVEL $service ; then
/bin/systemctl --no-reload enable `echo $service | sed -e
's/\.service//g'` >/dev/null 2>&1 || :
fi
usage :
%post
%service_add demo.service foobar.socket
%preun
%service_del_preun demo.service
%postun
%service_del_postun demo.service
when migrating a package from sysvinit to systemd :
%triggerun -- package_name < version_where_switch_occured
%service_migration_to_systemd [ -l run_level ] service_name.service
foobar.socket
-l