https://fedorahosted.org/sssd/ticket/1437
From b705c12d35f9b68f971413e2934c281fbc4a1636 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com>
Date: Mon, 15 Oct 2012 16:20:24 +0200
Subject: [PATCH] use systemd by default on fedora15+

https://fedorahosted.org/sssd/ticket/1437
---
 contrib/sssd.spec.in |   59 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
index 7cca646595686e9208ae9e9f2a8db3363d3a2b07..15270685c590bc804125689b7332749fd2138b50 100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -22,6 +22,10 @@
     %global with_ccache --with-default-ccache-dir='/run/user/%U' --with-default-ccname-template="DIR:%d/krb5cc"
 %endif
 
+%if (0%{?fedora} >= 15)
+    %global use_systemd 1
+%endif
+
 %global enable_experimental 1
 
 %if (0%{?enable_experimental} == 1)
@@ -57,6 +61,12 @@ Requires(post): initscripts chkconfig
 Requires(preun):  initscripts chkconfig
 Requires(postun): initscripts chkconfig
 
+%if (0%{?use_systemd} == 1)
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
+%endif
+
 %global servicename sssd
 %global sssdstatedir %{_localstatedir}/lib/sss
 %global dbpath %{sssdstatedir}/db
@@ -291,6 +301,13 @@ install -m644 src/examples/logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/s
 mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rwtab.d
 install -m644 src/examples/rwtab $RPM_BUILD_ROOT%{_sysconfdir}/rwtab.d/sssd
 
+%if (0%{?use_systemd} == 1)
+# Replace sysv init script with systemd unit file
+rm -f $RPM_BUILD_ROOT/%{_initrddir}/%{name}
+mkdir -p $RPM_BUILD_ROOT/%{_unitdir}/
+cp src/sysv/systemd/sssd.service $RPM_BUILD_ROOT/%{_unitdir}/
+%endif
+
 # Remove .la files created by libtool
 find $RPM_BUILD_ROOT -name "*.la" -exec rm -f {} \;
 
@@ -334,8 +351,12 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(-,root,root,-)
 %doc COPYING
 %doc src/examples/sssd-example.conf
-%{_initrddir}/%{name}
 %{_sbindir}/sssd
+%if (0%{?use_systemd} == 1)
+%{_unitdir}/sssd.service
+%else
+%{_initrddir}/%{name}
+%endif
 
 %dir %{_libexecdir}/%{servicename}
 %{_libexecdir}/%{servicename}/krb5_child
@@ -503,6 +524,41 @@ A utility library to allow communication between Autofs and SSSD
 %doc src/sss_client/COPYING src/sss_client/COPYING.LESSER
 %{_libdir}/sssd/modules/libsss_autofs.so*
 
+%if (0%{?use_systemd} == 1)
+# systemd
+%post
+if [ $1 -ge 1 ] ; then
+    # Initial installation
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+
+%preun
+if [ $1 = 0 ]; then
+     # Package removal, not upgrade
+    /bin/systemctl --no-reload disable sssd.service > /dev/null 2>&1 || :
+    /bin/systemctl stop sssd.service > /dev/null 2>&1 || :
+fi
+
+%triggerun -- sssd < %{version}-%{release}
+if /sbin/chkconfig --level 3 sssd ; then
+        /bin/systemctl --no-reload enable sssd.service >/dev/null 2>&1 || :
+fi
+
+if /sbin/chkconfig --level 5 sssd ; then
+        /bin/systemctl --no-reload enable sssd.service >/dev/null 2>&1 || :
+fi
+
+/sbin/chkconfig --del sssd >/dev/null 2>&1 || :
+
+%postun
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+if [ $1 -ge 1 ] ; then
+    # On upgrade, reload init system configuration if we changed unit files
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+    /bin/systemctl try-restart sssd.service >/dev/null 2>&1 || :
+fi
+%else
+# sysv
 %post
 /sbin/chkconfig --add %{servicename}
 
@@ -515,6 +571,7 @@ if [ $1 = 0 ]; then
     /sbin/service %{servicename} stop 2>&1 > /dev/null
     /sbin/chkconfig --del %{servicename}
 fi
+%endif
 
 %post client -p /sbin/ldconfig
 
-- 
1.7.6.5

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to