Permalink
Browse files

rpm: fix systemd integration with spec file

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information...
1 parent 3ab9121 commit 88b2c2cad6648ed848cfe608a84801e279756b01 @fabbione committed Dec 31, 2012
Showing with 47 additions and 4 deletions.
  1. +47 −4 kronosnet.spec.in
View
@@ -26,8 +26,6 @@ License: GPLv2+ and LGPLv2+
Group: System Environment/Base
URL: https://github.com/fabbione/kronosnet/
Source0: https://github.com/fabbione/kronosnet/archive/%{name}-%{version}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}.tar.gz
-Requires(post): chkconfig, shadow-utils
-Requires(preun): chkconfig, shadow-utils, initscripts
## Setup/build bits
@@ -40,7 +38,11 @@ BuildRequires: libqb-devel nss-devel pam-devel
%setup -q -n %{name}-%{version}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}
%build
+%if %{defined _unitdir}
+%{configure} --with-systemddir=%{_unitdir}
+%else
%{configure} --with-initddir=%{_sysconfdir}/rc.d/init.d/
+%endif
make %{_smp_mflags}
@@ -53,8 +55,16 @@ make install DESTDIR=%{buildroot}
find %{buildroot} -name "*.a" -exec rm {} \;
# remove libtools leftovers
find %{buildroot} -name "*.la" -exec rm {} \;
+
+# handle systemd vs init script
+%if %{defined _unitdir}
+# remove init scripts
+rm -rf %{buildroot}/etc/init.d
+%else
# remove systemd specific bits
find %{buildroot} -name "*.service" -exec rm {} \;
+%endif
+
# remove docs
rm -rf %{buildroot}/usr/share/doc/kronosnet
@@ -69,8 +79,18 @@ kronosnet source
%package -n kronosnetd
Group: System Environment/Base
Summary: Multipoint-to-Multipoint VPN daemon
-Requires(post): chkconfig, shadow-utils
-Requires(preun): chkconfig, shadow-utils, initscripts
+%if %{defined _unitdir}
+# Needed for systemd unit
+Requires(post): systemd-sysv
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+%else
+Requires(post): chkconfig
+Requires(preun): chkconfig, initscripts
+%endif
+Requires(post): shadow-utils
+Requires(preun): shadow-utils
Requires: pam, /etc/pam.d/passwd
%description -n kronosnetd
@@ -84,14 +104,33 @@ Requires: pam, /etc/pam.d/passwd
or service disruption.
%post -n kronosnetd
+%if %{defined _unitdir}
+ %if 0%{?systemd_post:1}
+ %systemd_post kronosnetd.service
+ %else
+ /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+ %endif
+%else
/sbin/chkconfig --add kronosnetd
+%endif
/usr/sbin/groupadd --force --system kronosnetadm
%preun -n kronosnetd
+%if %{defined _unitdir}
+ %if 0%{?systemd_preun:1}
+ %systemd_preun kronosnetd.service
+ %else
+if [ "$1" -eq 0 ]; then
+ /bin/systemctl --no-reload disable kronosnetd.service
+ /bin/systemctl stop kronosnetd.service >/dev/null 2>&1
+fi
+%endif
+%else
if [ "$1" = 0 ]; then
/sbin/service kronosnetd stop >/dev/null 2>&1
/sbin/chkconfig --del kronosnetd
fi
+%endif
%files -n kronosnetd
%defattr(-,root,root,-)
@@ -100,7 +139,11 @@ fi
%dir %{_sysconfdir}/kronosnet/*
%config(noreplace) %{_sysconfdir}/pam.d/kronosnetd
%config(noreplace) %{_sysconfdir}/logrotate.d/kronosnetd
+%if %{defined _unitdir}
+%{_unitdir}/kronosnetd.service
+%else
%config(noreplace) %{_sysconfdir}/rc.d/init.d/kronosnetd
+%endif
%{_sbindir}/*
%{_mandir}/man8/*

0 comments on commit 88b2c2c

Please sign in to comment.