[python-carbon] Migrate to systemd on Fedora >= 21 and EPEL >= 7

Jamie Nguyen jamielinux at fedoraproject.org
Wed Oct 1 11:33:49 UTC 2014


commit a22b616121c4e18b540363c3cdde8ab245d679c0
Author: Jamie Nguyen <j at jamielinux.com>
Date:   Wed Oct 1 11:51:14 2014 +0100

    Migrate to systemd on Fedora >= 21 and EPEL >= 7

 carbon-cache.service |   14 +++++++
 python-carbon.spec   |   99 ++++++++++++++++++++++++++++++++++----------------
 2 files changed, 82 insertions(+), 31 deletions(-)
---
diff --git a/carbon-cache.service b/carbon-cache.service
new file mode 100644
index 0000000..a889d8b
--- /dev/null
+++ b/carbon-cache.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Graphite Carbon Cache
+After=network.target
+
+[Service]
+Type=forking
+StandardOutput=syslog
+StandardError=syslog
+ExecStart=/usr/bin/carbon-cache --config=/etc/carbon/carbon.conf --pidfile=/var/run/carbon-cache.pid --logdir=/var/log/carbon/ start
+ExecReload=/bin/kill -USR1 $MAINPID
+PIDFile=/var/run/carbon-cache.pid
+
+[Install]
+WantedBy=multi-user.target
diff --git a/python-carbon.spec b/python-carbon.spec
index 5279202..e5a20c7 100644
--- a/python-carbon.spec
+++ b/python-carbon.spec
@@ -3,10 +3,13 @@
 %global commit eac68f82c3a06fe66155fa7adf58b39649ef2d27
 
 # Switched to system log rotation on Fedora 21 and EPEL 7.
+# systemd service files introduced in Fedora 21 and EPEL 7.
 %if 0%{?fedora} >= 21 || 0%{?rhel} >= 7
 %global with_system_logrotate 1
+%global with_systemd 1
 %else
 %global with_system_logrotate 0
+%global with_systemd 0
 %endif
 
 Name:           python-carbon
@@ -19,27 +22,41 @@ License:        ASL 2.0
 URL:            https://github.com/graphite-project
 
 Source0:        https://github.com/graphite-project/carbon/archive/%{commit}/%{name}-%{commit}.tar.gz
-Source1:        %{name}-cache.init
-Source2:        %{name}-relay.init
-Source3:        %{name}-aggregator.init
-Source4:        %{name}.sysconfig
 Source10:       carbon-aggregator.1
 Source11:       carbon-cache.1
 Source12:       carbon-client.1
 Source13:       carbon-relay.1
 Source14:       validate-storage-schemas.1
 Source20:       %{name}.logrotate
+
+Source30:       carbon-cache.service
+
+Source40:       %{name}-cache.init
+Source41:       %{name}-relay.init
+Source42:       %{name}-aggregator.init
+Source43:       %{name}.sysconfig
+
 Patch0:         %{name}-0.9.12-Set-sane-defaults.patch
 Patch1:         %{name}-0.9.12-Fix-path-to-storage-schemas.conf.patch
 
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
 BuildArch:      noarch
-BuildRequires:  python-devel, python-setuptools
-Requires:       python-whisper >= %{version}, python-twisted-core >= 8.0
-Requires(post): chkconfig
-Requires(pre):  shadow-utils
-Requires(preun): chkconfig, initscripts
+BuildRequires:  python-devel
+BuildRequires:  python-setuptools
+
+Requires:       python-twisted-core >= 8.0
+Requires:       python-whisper >= %{version}
+
+Requires(pre):    shadow-utils
+%if %{with_systemd}
+BuildRequires:    systemd
+Requires(post):   systemd
+Requires(preun):  systemd
+Requires(postun): systemd
+%else
+Requires(post):   chkconfig
+Requires(preun):  chkconfig, initscripts
+%endif
 
 
 %description
@@ -82,17 +99,6 @@ mkdir -p %{buildroot}%{_localstatedir}/lib/carbon/lists
 mkdir -p %{buildroot}%{_localstatedir}/lib/carbon/rrd
 mkdir -p %{buildroot}%{_localstatedir}/lib/carbon/whisper
 
-# init scripts
-mkdir -p %{buildroot}%{_localstatedir}/run/carbon
-install -Dp -m0755 %{SOURCE1} \
-    %{buildroot}%{_sysconfdir}/init.d/carbon-cache
-install -Dp -m0755 %{SOURCE2} \
-    %{buildroot}%{_sysconfdir}/init.d/carbon-relay
-install -Dp -m0755 %{SOURCE3} \
-    %{buildroot}%{_sysconfdir}/init.d/carbon-aggregator
-install -Dp -m0644 %{SOURCE4} \
-    %{buildroot}%{_sysconfdir}/sysconfig/carbon
-
 # default config
 mkdir -p %{buildroot}%{_sysconfdir}/carbon
 install -D -p -m0644 conf/carbon.conf.example \
@@ -115,6 +121,22 @@ install -D -p -m0644 %{SOURCE20} \
     %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
 %endif
 
+# init scripts
+%if %{with_systemd}
+install -D -p -m0644 %{SOURCE30} \
+    %{buildroot}%{_unitdir}/carbon-cache.service
+%else
+mkdir -p %{buildroot}%{_localstatedir}/run/carbon
+install -Dp -m0755 %{SOURCE40} \
+    %{buildroot}%{_sysconfdir}/init.d/carbon-cache
+install -Dp -m0755 %{SOURCE41} \
+    %{buildroot}%{_sysconfdir}/init.d/carbon-relay
+install -Dp -m0755 %{SOURCE41} \
+    %{buildroot}%{_sysconfdir}/init.d/carbon-aggregator
+install -Dp -m0644 %{SOURCE42} \
+    %{buildroot}%{_sysconfdir}/sysconfig/carbon
+%endif
+
 # remove .py suffix
 for i in %{buildroot}%{_bindir}/*.py; do
     mv ${i} ${i%%.py}
@@ -131,9 +153,20 @@ getent passwd carbon >/dev/null || \
     useradd -r -g carbon -d %{_localstatedir}/lib/carbon \
     -s /sbin/nologin -c "Carbon cache daemon" carbon
 
+%post
+%if %{with_systemd}
+%systemd_post carbon-cache.service
+%else
+/sbin/chkconfig --add carbon-cache
+/sbin/chkconfig --add carbon-relay
+/sbin/chkconfig --add carbon-aggregator
+%endif
 
 %preun
-if [ $1 -eq 0 ] ; then
+%if %{with_systemd}
+%systemd_preun carbon-cache.service
+%else
+if [ $1 -eq 0 ]; then
     /sbin/service carbon-cache stop >/dev/null 2>&1
     /sbin/chkconfig --del carbon-cache
     /sbin/service carbon-relay stop >/dev/null 2>&1
@@ -141,22 +174,18 @@ if [ $1 -eq 0 ] ; then
     /sbin/service carbon-aggregator stop >/dev/null 2>&1
     /sbin/chkconfig --del carbon-aggregator
 fi
+%endif
 
-
-%post
-/sbin/chkconfig --add carbon-cache
-/sbin/chkconfig --add carbon-relay
-/sbin/chkconfig --add carbon-aggregator
+%if %{with_systemd}
+%postun
+%systemd_postun_with_restart carbon-cache.service
+%endif
 
 
 %files
 %doc LICENSE README.md
 %doc conf/ examples/
 
-%dir %{_localstatedir}/run/carbon
-%{_sysconfdir}/init.d/carbon-*
-%config(noreplace) %{_sysconfdir}/sysconfig/carbon
-
 %dir %{_sysconfdir}/carbon
 %config(noreplace) %{_sysconfdir}/carbon/carbon.conf
 %config(noreplace) %{_sysconfdir}/carbon/storage-schemas.conf
@@ -190,6 +219,14 @@ fi
 %{python_sitelib}/carbon-*-py?.?.egg-info
 %endif
 
+%if %{with_systemd}
+%{_unitdir}/carbon-cache.service
+%else
+%dir %{_localstatedir}/run/carbon
+%{_sysconfdir}/init.d/carbon-*
+%config(noreplace) %{_sysconfdir}/sysconfig/carbon
+%endif
+
 
 %changelog
 * Sat Jun 07 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 0.9.12-4


More information about the scm-commits mailing list