Hi everyone,
I just finished merging the migration macros into the "main" systemd
macros, so here is the final result for macros (see file attached).
Usage would be like this (it will be hard to put macros in the wrong
section ;) :
Add :
%systemd_requires
and if you are compiling your package for old distributions :
%if 0%{suse_version} <= 1140
%define systemd_requires %{nil}
%endif
for scripts :
%post
%service_add_pre demo.service demo1.service
%post
%service_add_post demo.service demo1.service
%preun
%service_del_preun demo.service demo1.service
%postun
%service_del_postun demo.service demo1.servoce
Please note those macros are "systemd preset" aware (this was discussed
on this mailing list in july) : you don't need to enable a service in %
post : if it is specified in the default preset policy as "enabled by
default", it will be handled automatically.
These defaults will be in systemd-default-presets package (not yet
created, probably tomorrow).
--
Frederic Crozat
SUSE
# RPM macros for packages installing systemd unit files
#
###
#
# When a package install systemd unit files, it should use the following macros:
#
# add %systemd_requires in the specfile
#
# %post
# %service_add_pre demo.service demo1.service
#
# %post
# %service_add_post demo.service demo1.service
#
# %preun
# %service_del_preun demo.service
#
# %postun
# %service_del_postun demo.service
#
###
# This is for /bin/systemctl
%systemd_requires \
Requires(pre): systemd \
Requires(post): systemd \
Requires(preun): systemd \
Requires(postun): systemd \
%_unitdir /lib/systemd/system
%service_add_pre() \
test -n "$FIRST_ARG" || FIRST_ARG=$1 \
# disable migration if initial install under systemd \
if [ $FIRST_ARG -eq 1 ]; then \
for service in %{?*} ; do \
sysv_service=`echo $service | sed -e 's/\\.[a-z]*//g'` \
touch "/var/lib/systemd/migrated/$sysv_service" \
done \
else \
for service in %{?*} ; do \
sysv_service=`echo $service | sed -e 's/\\.[a-z]*//g'` \
if [ ! -e "/var/lib/systemd/migrated/$sysv_service" ]; then \
services_to_migrate="$services_to_migrate $sysv_service" \
fi \
done \
if [ -n "$services_to_migrate" ]; then \
/usr/sbin/systemd-sysv-convert --save $services_to_migrate >/dev/null 2>&1 || : \
fi \
fi \
%{nil}
# On install, tell systemd to reload its unit files
%service_add_post() \
test -n "$FIRST_ARG" || FIRST_ARG=$1 \
for service in %{?*} ; do \
sysv_service=`echo $service | sed -e 's/\\.[a-z]*//g'` \
if [ ! -e "/var/lib/systemd/migrated/$sysv_service" ]; then \
services_to_migrate="$services_to_migrate $sysv_service" \
touch "/var/lib/systemd/migrated/$sysv_service" \
fi \
done \
if [ -n "$services_to_migrate" ]; then \
/usr/sbin/systemd-sysv-convert --apply $services_to_migrate >/dev/null 2>&1 || : \
fi \
/bin/systemctl daemon-reload >/dev/null 2>&1 || : \
/bin/systemctl preset %{?*} >/dev/null 2>&1 || : \
%{nil}
# On uninstall, disable and stop services
%service_del_preun() \
test -n "$FIRST_ARG" || FIRST_ARG=$1 \
if [ $FIRST_ARG -eq 0 ]; then \
# Package removal, not upgrade \
/bin/systemctl --no-reload disable %{?*} > /dev/null 2>&1 || : \
/bin/systemctl stop %{?*} > /dev/null 2>&1 || : \
fi \
%{nil}
# On uninstall, tell systemd to reload its unit files
%service_del_postun() \
test -n "$FIRST_ARG" || FIRST_ARG=$1 \
if [ $FIRST_ARG -ge 1 ]; then \
# Package upgrade, not uninstall \
/bin/systemctl try-restart %{?*} >/dev/null 2>&1 || : \
else # package uninstall \
for service in %{?*} ; do \
sysv_service=`echo $service | sed -e 's/\\.[a-z]*//g'` \
rm -f "/var/lib/systemd/migrated/$sysv_service" 2> /dev/null \
done \
/bin/systemctl daemon-reload >/dev/null 2>&1 || : \
fi \
%{nil}