[systemd-devel] RFC: creating a set of systemd RPM macros across distributions ?

Frederic Crozat fcrozat at suse.com
Fri Jun 24 06:08:47 PDT 2011


Le jeudi 16 juin 2011 à 18:49 +0200, Frederic Crozat a écrit :
> Hi all,
> 
> as we are working in integrating systemd in openSUSE for next release,
> we will have to handle .unit files in various packages, enabling /
> disabling services on package install / upgrades, etc..
> 
> Fedora already hit the bullet with
> https://fedoraproject.org/wiki/Packaging:Guidelines:Systemd and
> https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd
> 
> but maybe we could improve the scriplet part by creating a
> cross-distribution set of macros to handle systemctl calls and get it
> merged in rpm 4.x (or have them shipped in systemd).
> 
> Opinions welcome..

Ok, here is a proposal that has been commented (and amended) on
opensuse-packaging mailing list :

(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_add_enabled()
if [ "$1" -eq 1 ] ; then 
# Initial installation
/bin/systemctl enable %{1}.service >/dev/null 2>&1 || :
fi

%service_del_preun()
if [ "$1" -eq 0 ] ; then
# Package removal, not upgrade
/bin/systemctl --no-reload disable %{1}.service > /dev/null 2>&1 || :
/bin/systemctl stop %{1}.service > /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}.service >/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 }
if /sbin/chkconfig $LEVEL %{1} ; then
     /bin/systemctl --no-reload enable %{1}.service >/dev/null 2>&1 || :
fi

usage :

%post
%service_add demo.service
# Alternative: %service_add_enabled demo.service

%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

-l <run_level> is optional

-- 
Frederic Crozat <fcrozat at suse.com>
SUSE



More information about the systemd-devel mailing list