Spec file bits for packages migrating from sysv to systemd, for cases where the daemon is allowed to autostart, and/or when the old package's %postun will not successfully restart the daemon on migration upgrades. %global migrfile %{_var}/run/systemd-migrate_%{name}-%{version}-%{release}.%{_arch} BuildRequires: systemd-units Requires(pre): systemd-sysv chkconfig Requires(post): systemd-units Requires(preun): systemd-units Requires(postun): systemd-units %pre rm -f %{migrfile} &>/dev/null if [ $1 -gt 1 ] && [ ! -e %{_unitdir}/FOO.service ] && \ [ -e %{_initddir}/FOO ] ; then systemd-sysv-convert --save FOO &>/dev/null chkconfig --del FOO &>/dev/null touch %{migrfile} &>/dev/null || : fi %post if [ $1 -eq 1 ] ; then systemctl daemon-reload &>/dev/null || : # If the service is allowed to autostart: systemctl --no-reload enable FOO.service &>/dev/null || : fi %preun if [ $1 -eq 0 ] ; then systemctl --no-reload disable FOO.service &>/dev/null systemctl stop FOO.service &>/dev/null || : fi %postun systemctl daemon-reload &>/dev/null [ $1 -gt 0 ] && systemctl try-restart FOO.service &>/dev/null || : %triggerpostun -- %{name} if [ $1 -gt 0 ] && [ -e %{migrfile} ] ; then systemctl daemon-reload &>/dev/null # If the service is allowed to autostart: systemctl --no-reload enable FOO.service &>/dev/null # If the old package uses sysv init script directly for # try-restart in its %postun (which will fail if the init script # is no longer installed) instead of "service", or does not do the # try-restart at all, we take care of that here: systemctl try-restart FOO.service &>/dev/null fi rm -f %{migrfile} &>/dev/null || :