[fetch-crl] Add systemd support.

stevetraylen stevetraylen at fedoraproject.org
Thu Mar 1 21:08:05 UTC 2012


commit cd62fad20519d7682a2f7116d9be36346ec7d529
Author: Steve Traylen <steve.traylen at cern.ch>
Date:   Thu Mar 1 23:08:16 2012 +0100

    Add systemd support.

 fetch-crl-boot.service |   15 +++++++++
 fetch-crl-cron.service |   17 +++++++++++
 fetch-crl-systemd.cron |    8 +++++
 fetch-crl.spec         |   76 +++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 106 insertions(+), 10 deletions(-)
---
diff --git a/fetch-crl-boot.service b/fetch-crl-boot.service
new file mode 100644
index 0000000..aebc1dd
--- /dev/null
+++ b/fetch-crl-boot.service
@@ -0,0 +1,15 @@
+#  Run's fetch-crl once at boot time if desirable.
+#
+
+[Unit]
+Description=Runs fetch-crl once at boot time.
+After=syslog.target network.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/fetch-crl -q
+TimeoutSec=10m
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/fetch-crl-cron.service b/fetch-crl-cron.service
new file mode 100644
index 0000000..6b10c96
--- /dev/null
+++ b/fetch-crl-cron.service
@@ -0,0 +1,17 @@
+#  This is dummy service to enable the fetch-crl cron job.
+#  If this service is running the cron job in /etc/cron.d
+#  actually does something.
+
+[Unit]
+Description=Enables fetch-crl cron to run.
+After=syslog.target network.target
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/bin/true 
+
+[Install]
+WantedBy=multi-user.target
+
+
diff --git a/fetch-crl-systemd.cron b/fetch-crl-systemd.cron
new file mode 100644
index 0000000..6f9faf6
--- /dev/null
+++ b/fetch-crl-systemd.cron
@@ -0,0 +1,8 @@
+# Cron job running by default every 6 hours, at 45 minutes past the hour
+# with  +/- 3 minutes sleep.
+# The cron job file can be enabled/disabled with
+# systemctl start fetch-crl-cron
+# systemctl enable fetch-crl-cron 
+
+45 */6 * * * root ! /bin/systemctl -q is-active fetch-crl-cron.service || /usr/sbin/fetch-crl -q -r 360 
+
diff --git a/fetch-crl.spec b/fetch-crl.spec
index 5e17af0..eaaf849 100644
--- a/fetch-crl.spec
+++ b/fetch-crl.spec
@@ -2,24 +2,43 @@
   %global _initddir  %{_initrddir}
 %endif
 
+%if 0%{?el5}%{?el6}%{?fc16}%{?fc15}
+%global with_sysv 1
+%else
+%global with_sysv 0
+%endif
+
 Name: fetch-crl
 Version: 3.0.8
-Release: 2%{?dist}
+Release: 3%{?dist}
 Summary: Downloads Certificate Revocation Lists
 
 Group: Applications/System
 License: ASL 2.0
 URL: http://www.nikhef.nl/grid/gridwiki/index.php/FetchCRL3
-Source: https://dist.eugridpma.info/distribution/util/fetch-crl3/fetch-crl-%{version}.tar.gz
+Source0: https://dist.eugridpma.info/distribution/util/fetch-crl3/fetch-crl-%{version}.tar.gz
 
+# systemd files.
+Source1: fetch-crl-cron.service 
+Source2: fetch-crl-boot.service
+Source3: fetch-crl-systemd.cron
 
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildArch: noarch
 
 Requires: openssl
 
-Requires(post): chkconfig
-Requires(preun): chkconfig
+%if 0%{?with_sysv}
+Requires(post):   chkconfig
+Requires(preun):  chkconfig
+Requires(preun):  initscripts
+Requires(postun): initscripts
+%else
+Requires(post):   systemd-units
+Requires(post):   systemd-sysv
+Requires(preun):  systemd-units
+Requires(postun): systemd-units
+%endif
 
 # To ease EPEL5 -> EPEL6 migration obsolete
 # the no longer needed fetch-crl3 package.
@@ -36,6 +55,12 @@ It assumes that the installed CA files follow the hash.crl_url convention.
 
 %prep
 %setup -q
+%if 0%{with_sysv}
+%else
+cp -p %{SOURCE1} fetch-crl-cron.service 
+cp -p %{SOURCE2} fetch-crl-boot.service
+cp -p %{SOURCE3} fetch-crl.cron
+%endif
 
 # The perl script contains some modules inside of
 # it. These end up being rpm required but are 
@@ -59,6 +84,7 @@ chmod +x %{__perl_requires}
 
 
 %build
+# Nothing to build.
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -66,25 +92,39 @@ rm -rf $RPM_BUILD_ROOT
 %install
 rm -rf $RPM_BUILD_ROOT
 make install PREFIX=$RPM_BUILD_ROOT%{_usr} ETC=$RPM_BUILD_ROOT%{_sysconfdir} CACHE=$RPM_BUILD_ROOT%{_var}/cache
+mkdir $RPM_BUILD_ROOT%{_sysconfdir}/cron.d
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d
+
+%if 0%{?with_sysv}
 mkdir -p $RPM_BUILD_ROOT%{_initddir}
 install -p -m 755 $RPM_BUILD_ROOT%{_usr}/share/doc/%{name}-%{version}/%{name}-cron.init $RPM_BUILD_ROOT%{_initddir}/%{name}-cron
 install -p -m 755 $RPM_BUILD_ROOT%{_usr}/share/doc/%{name}-%{version}/%{name}-boot.init $RPM_BUILD_ROOT%{_initddir}/%{name}-boot
-mkdir $RPM_BUILD_ROOT%{_sysconfdir}/cron.d
-install -p -m 644 $RPM_BUILD_ROOT%{_usr}/share/doc/%{name}-%{version}/%{name}-cron.cron $RPM_BUILD_ROOT%{_sysconfdir}/cron.d/%{name}
 
-mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d
+install -p -m 644 $RPM_BUILD_ROOT%{_usr}/share/doc/%{name}-%{version}/%{name}-cron.cron $RPM_BUILD_ROOT%{_sysconfdir}/cron.d/%{name}
+%else
+mkdir -p $RPM_BUILD_ROOT%{_unitdir}
+install -p -m 644  %{name}-boot.service $RPM_BUILD_ROOT%{_unitdir}/%{name}-boot.service
+install -p -m 644  %{name}-cron.service $RPM_BUILD_ROOT%{_unitdir}/%{name}-cron.service
+install -p -m 644  %{name}.cron $RPM_BUILD_ROOT%{_sysconfdir}/cron.d/%{name}
+%endif
 
 # Remove some files that have been duplicated as docs.
 rm $RPM_BUILD_ROOT%{_defaultdocdir}/%{name}-%{version}/%{name}-boot.init
 rm $RPM_BUILD_ROOT%{_defaultdocdir}/%{name}-%{version}/%{name}-cron.cron
 rm $RPM_BUILD_ROOT%{_defaultdocdir}/%{name}-%{version}/%{name}-cron.init
 
-
+%if 0%{?with_sysv}
 %post
-# This adds the proper /etc/rc*.d links for the script
 /sbin/chkconfig --add %{name}-cron
 /sbin/chkconfig --add %{name}-boot
+%else
+%post
+if [ $1 -eq 1 ] ; then   # Initial installation 
+   /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+%endif
 
+%if 0%{?with_sysv}
 %preun
 if [ $1 = 0 ] ; then
     /sbin/service %{name}-cron stop >/dev/null 2>&1
@@ -92,13 +132,26 @@ if [ $1 = 0 ] ; then
     /sbin/chkconfig --del %{name}-cron
     /sbin/chkconfig --del %{name}-boot
 fi
-
+%else
+%preun
+if [ $1 -eq 0 ] ; then   #Package removal, not upgrade
+   /bin/systemctl --no-reload disable fetch-crl-boot.service > /dev/null 2>&1 || :
+   /bin/systemctl stop fetch-crl-boot.service > /dev/null 2>&1 || :
+   /bin/systemctl --no-reload disable fetch-crl-cron.service > /dev/null 2>&1 || :
+   /bin/systemctl stop fetch-crl-cron.service > /dev/null 2>&1 || :
+fi
+%endif
 
 %files
 %defattr(-,root,root,-)
 %{_sbindir}/%{name}
+%if 0%{?with_sysv}
 %{_initddir}/%{name}-cron
 %{_initddir}/%{name}-boot
+%else
+%{_unitdir}/%{name}-cron.service
+%{_unitdir}/%{name}-boot.service
+%endif
 %dir %{_var}/cache/%{name}
 %dir %{_sysconfdir}/%{name}.d
 %doc %{_mandir}/man8/%{name}.8.gz
@@ -108,6 +161,9 @@ fi
 
 
 %changelog
+* Thu Mar 1 2012 Steve Traylen <steve.traylen at cern.ch> - 3.0.8-2
+- Add systemd support.
+
 * Fri Jan 13 2012 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 3.0.8-2
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild
 


More information about the scm-commits mailing list