[polipo] add support for systemd starting in F17

Bernard Johnson bjohnson at fedoraproject.org
Tue Sep 27 03:56:15 UTC 2011


commit 92f0aef90da0f27a18bb6a8da4c16c452f3634f6
Author: Bernard Johnson <bjohnson at symetrix.com>
Date:   Mon Sep 26 21:55:56 2011 -0600

    add support for systemd starting in F17

 polipo.service |   14 ++++++++++++
 polipo.spec    |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 76 insertions(+), 4 deletions(-)
---
diff --git a/polipo.service b/polipo.service
new file mode 100644
index 0000000..af6fe39
--- /dev/null
+++ b/polipo.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=A caching web proxy
+After=syslog.target
+
+[Service]
+Type=oneshot
+User=polipo
+Group=polipo
+EnvironmentFile=/etc/sysconfig/polipo
+ExecStart=/usr/sbin/polipo -c $CONFIG
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/polipo.spec b/polipo.spec
index fa4e759..5d51044 100644
--- a/polipo.spec
+++ b/polipo.spec
@@ -3,6 +3,11 @@
 %global _with_tmpfilesd 1
 %endif
 
+# systemd was introduced in Fedora 15, but we don't support it until Fedora 17
+%if 0%{?fedora} && 0%{?fedora} > 16
+%global _with_systemd 1
+%endif
+
 Name:           polipo
 Version:        1.0.4.1
 Release:        4%{?dist}
@@ -19,6 +24,9 @@ BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 Group:          System Environment/Daemons
 URL:            http://www.pps.jussieu.fr/~jch/software/%{name}/
 BuildRequires:  texinfo
+%if 0%{?_with_systemd}
+BuildRequires:  systemd-units
+%endif
 Requires:       logrotate
 Requires(post): info
 Requires(preun):info
@@ -27,9 +35,17 @@ Requires(post): chkconfig
 Requires(preun):chkconfig
 
 Requires(pre):  %{_sbindir}/useradd
+
+%if 0%{?_with_systemd}
+Requires(preun):systemd-units
+Requires(post): systemd-units, %{_sbindir}/usermod
+Requires(postun):systemd-units
+Requires(triggerun): system-units
+%else
 Requires(preun):initscripts, chkconfig
 Requires(post): initscripts, chkconfig, %{_sbindir}/usermod
 Requires(postun):initscripts
+%endif
 
 
 %description
@@ -76,25 +92,61 @@ done
 exit 0
 
 %post
-/sbin/chkconfig --add %{name}
 [ -e %{_localstatedir}/log/%{name} ] || /bin/touch %{_localstatedir}/log/%{name}
 /bin/chmod -f 0640 %{_localstatedir}/log/%{name}
 /bin/chown -f %{name}:%{name} %{_localstatedir}/log/%{name}
 
 /sbin/install-info --quiet --info-dir=%{_infodir} %{_infodir}/%{name}.info.gz || : 
 
+if [ $1 -eq 1 ]; then
+    # package install, not upgrade
+
+%if 0{?_with_systemd}
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%else
+    /sbin/chkconfig --add %{name}
+%endif
+
+fi
+
 %preun
 if [ $1 = 0 ] ; then
+    # package removal, not upgrade
+
+%if 0{?_with_systemd}
+    /sbin/systemctl disable %{name}.service > /dev/null 2>&1 || :
+    /sbin/systemctl stop %{name}.service > /dev/null 2>&1 || :
+%else
     /sbin/service %{name} stop >/dev/null 2>&1
     /sbin/chkconfig --del %{name}
+%endif
+
     /sbin/install-info --quiet --info-dir=%{_infodir} --delete %{_infodir}/%{name}.info.gz || :
 fi
 
 %postun
-if [ "$1" -ge "1" ] ; then
-    /sbin/service %{name} condrestart >/dev/null 2>&1
+%if 0{?_with_systemd}
+    /bin/systemctl daemon-reload > /dev/null 2>&1 || :
+%endif
+
+if [ $1 -ge 1 ] ; then
+    # package upgrade, not uninstall
+
+%if 0{?_with_systemd}
+    /bin/systemctl try-restart %{name}.service > /dev/null 2>&1 || :
+%else
+    /sbin/service %{name} condrestart >/dev/null 2>&1 || :
+%endif
+
 fi
 
+%if 0{?_with_systemd}
+%triggerun -- %{name} < 1.0.4.1-4
+if /sbin/chkconfig %{name}; then
+    /bin/systemctl enable %{name}.service > /dev/null 2>&1 || :
+fi
+%endif
+
 %files
 %defattr(-,root,root,-)
 %doc README CHANGES COPYING *.sample
@@ -108,10 +160,15 @@ fi
 %{_infodir}/%{name}.*
 %config(noreplace) %{_sysconfdir}/%{name}/config
 %config(noreplace) %{_sysconfdir}/%{name}/forbidden
-%attr(0755,root,root) %{_initddir}/%{name}
 %attr(0755,root,root) %{_sysconfdir}/NetworkManager/dispatcher.d/*
 %config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
 
+%if 0{?_with_systemd}
+%{_unitdir}/%{name}.service
+%else
+%attr(0755,root,root) %{_initddir}/%{name}
+%endif
+
 %if 0%{?_with_tmpfilesd}
 %config(noreplace) %{_sysconfdir}/tmpfiles.d/%{name}.conf
 %else
@@ -124,6 +181,7 @@ fi
 - remove log file / dir creation in spec too
 - NetworkManager integration should use restart rather than reload (bz #699677)
 - add support for tmpfiles.d (bz #656669)
+- add support for systemd starting in F17
 
 * Wed Feb 09 2011 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.0.4.1-3
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild


More information about the scm-commits mailing list