diff --git a/bandwidthd.spec b/bandwidthd.spec index 9c63e2a..f33dc76 100644 --- a/bandwidthd.spec +++ b/bandwidthd.spec @@ -23,11 +23,15 @@ BuildRequires: libpcap %else BuildRequires: libpcap-devel %endif +%if 0%{?fedora} || 0%{?rhel} > 6 +Requires(post): systemd-units +Requires(preun): systemd-units +Requires(postun): systemd-units +BuildRequires: systemd-units +%else Requires(post): /sbin/chkconfig Requires(preun):/sbin/chkconfig Requires(preun):/sbin/service -%if 0%{?fedora} || 0%{?rhel} > 6 -BuildRequires: systemd-units %endif %description @@ -89,14 +93,24 @@ rm -rf $RPM_BUILD_ROOT %post -/sbin/chkconfig --add bandwidthd +if [ $1 -eq 1 ] ; then + # Initial installation + /bin/systemctl daemon-reload >/dev/null 2>&1 || : +fi %preun -if [ $1 = 0 ]; then - /sbin/service bandwidthd stop > /dev/null 2>&1 - /sbin/chkconfig --del bandwidthd +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + /bin/systemctl --no-reload disable %{name}.service > /dev/null 2>&1 || : + /bin/systemctl stop %{name}.service > /dev/null 2>&1 || : fi +%postun +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +if [ $1 -ge 1 ] ; then + # Package upgrade, not uninstall + /bin/systemctl try-restart %{name}.service >/dev/null 2>&1 || : +fi %files %defattr(-,root,root,-)