[redis/epel7] Cleanup spec

Haïkel Guémar hguemar at fedoraproject.org
Thu Sep 11 21:44:18 UTC 2014


commit 41ba9e8107d0b362d3ea49233c0bd3711dd78a80
Author: Haïkel Guémar <hguemar at fedoraproject.org>
Date:   Thu Sep 11 21:40:02 2014 +0200

    Cleanup spec
    
    Fix shutdown for redis-{server,sentinel}
    Backport fixes from Remi Collet repository
    Drop unused patch

 redis-sentinel.service |    5 ++-
 redis-shutdown         |   28 +++++++++++++++++++++++
 redis.service          |    1 +
 redis.spec             |   57 +++++++++++++++++++++++++++++------------------
 4 files changed, 67 insertions(+), 24 deletions(-)
---
diff --git a/redis-sentinel.service b/redis-sentinel.service
index b58ccae..43d4ad4 100644
--- a/redis-sentinel.service
+++ b/redis-sentinel.service
@@ -3,8 +3,9 @@ Description=Redis Sentinel
 After=network.target
 
 [Service]
-ExecStart=/usr/bin/redis-sentinel /etc/sentinel.conf
-ExecStop=/usr/bin/redis-cli shutdown
+ExecStartPre=/usr/bin/mkdir -p /var/lib/redis
+ExecStart=/usr/bin/redis-sentinel /etc/redis-sentinel.conf
+ExecStop=/usr/bin/redis-shutdown sentinel
 User=redis
 Group=redis
 
diff --git a/redis-shutdown b/redis-shutdown
new file mode 100644
index 0000000..4ab3e71
--- /dev/null
+++ b/redis-shutdown
@@ -0,0 +1,28 @@
+#! /bin/bash
+#
+# Wrapper to close properly redis and sentinel
+test x"REDIS_DEBUG" != x && set -x
+
+REDIS_CLI=/usr/bin/redis-cli
+
+# Retrieve service name
+SERVICE_NAME="$2"
+if [ -z "$SERVICE_NAME" ]; then
+   SERVICE_NAME=redis
+fi
+
+# Get the proper config file based on service name
+CONFIG_FILE="/etc/$SERVICE_NAME.conf"
+
+# Use awk to retrieve port from config file
+PORT=`awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE`
+
+# Just in case, use default port
+if [ "$SERVICE_NAME" = redis ]; then
+    PORT=${PORT:-6279}
+else
+    PORT=${PORT:-26739}
+fi
+
+# shutdown the service properly
+$REDIS_CLI -p $PORT shutdown
\ No newline at end of file
diff --git a/redis.service b/redis.service
index 3bfcbee..1c549b4 100644
--- a/redis.service
+++ b/redis.service
@@ -4,6 +4,7 @@ After=network.target
 
 [Service]
 ExecStart=/usr/bin/redis-server /etc/redis.conf --daemonize no
+ExecStop=/usr/bin/redis-shutdown
 User=redis
 Group=redis
 
diff --git a/redis.spec b/redis.spec
index 112bd5a..f0892a2 100644
--- a/redis.spec
+++ b/redis.spec
@@ -1,5 +1,4 @@
 %global _hardened_build 1
-
 %global with_perftools 0
 
 # redis 2.8 sentinel is the first upstream version to work
@@ -15,17 +14,13 @@
 %global with_systemd 0
 %endif
 
-# tcl 8.4 in EL5.
-%if 0%{?el5}
-%global with_tests 0
-%else
-%global with_tests 1
-%endif
+# Tests fail in mock, not in local build.
+%global with_tests   %{?_with_tests:1}%{!?_with_tests:0}
 
 Name:              redis
 Version:           2.8.14
-Release:           1%{?dist}
-Summary:           A persistent caching system, key-value and data structures database
+Release:           2%{?dist}
+Summary:           A persistent key-value database
 License:           BSD
 URL:               http://redis.io
 Source0:           http://download.redis.io/releases/%{name}-%{version}.tar.gz
@@ -35,6 +30,7 @@ Source3:           %{name}.service
 Source4:           %{name}.tmpfiles
 Source5:           %{name}-sentinel.init
 Source6:           %{name}.init
+Source7:           %{name}-shutdown
 # Update configuration for Fedora
 Patch0:            redis-2.8.11-redis-conf.patch
 Patch1:            redis-2.8.11-deps-library-fPIC-performance-tuning.patch
@@ -55,6 +51,8 @@ BuildRequires:     systemd
 %if 0%{?with_tests}
 BuildRequires:     tcl
 %endif
+# Required for redis-shutdown
+Requires:          /bin/awk
 Requires:          logrotate
 Requires(pre):     shadow-utils
 %if 0%{?with_systemd}
@@ -165,6 +163,13 @@ install -pDm755 %{S:6} %{buildroot}%{_initrddir}/%{name}
 # Fix non-standard-executable-perm error.
 chmod 755 %{buildroot}%{_bindir}/%{name}-*
 
+# create redis-sentinel command as described on
+# http://redis.io/topics/sentinel
+ln -s %{name}-server %{buildroot}%{_bindir}/%{name}-sentinel
+
+# Install redis-shutdown
+install -pDm755 %{S:7} %{buildroot}%{_bindir}/%{name}-shutdown
+
 %check
 %if 0%{?with_tests}
 make test
@@ -174,7 +179,8 @@ make test-sentinel
 %endif
 
 %pre
-getent group %{name} &> /dev/null || groupadd -r %{name} &> /dev/null
+getent group %{name} &> /dev/null || \
+groupadd -r %{name} &> /dev/null
 getent passwd %{name} &> /dev/null || \
 useradd -r -g %{name} -d %{_sharedstatedir}/%{name} -s /sbin/nologin \
 -c 'Redis Database Server' %{name} &> /dev/null
@@ -182,54 +188,56 @@ exit 0
 
 %post
 %if 0%{?with_systemd}
+%systemd_post %{name}.service
 %if 0%{?with_sentinel}
 %systemd_post %{name}-sentinel.service
 %endif
-%systemd_post %{name}.service
 %else
+chkconfig --add %{name}
 %if 0%{?with_sentinel}
 chkconfig --add %{name}-sentinel
 %endif
-chkconfig --add %{name}
 %endif
 
 %preun
 %if 0%{?with_systemd}
+%systemd_preun %{name}.service
 %if 0%{?with_sentinel}
 %systemd_preun %{name}-sentinel.service
 %endif
-%systemd_preun %{name}.service
 %else
 if [ $1 -eq 0 ] ; then
+service %{name} stop &> /dev/null
+chkconfig --del %{name} &> /dev/null
 %if 0%{?with_sentinel}
 service %{name}-sentinel stop &> /dev/null
 chkconfig --del %{name}-sentinel &> /dev/null
 %endif
-service %{name} stop &> /dev/null
-chkconfig --del %{name} &> /dev/null
 %endif
 
 %postun
 %if 0%{?with_systemd}
+%systemd_postun_with_restart %{name}.service
 %if 0%{?with_sentinel}
 %systemd_postun_with_restart %{name}-sentinel.service
 %endif
-%systemd_postun_with_restart %{name}.service
 %else
 if [ "$1" -ge "1" ] ; then
+    service %{name} condrestart >/dev/null 2>&1 || :
 %if 0%{?with_sentinel}
     service %{name}-sentinel condrestart >/dev/null 2>&1 || :
 %endif
-    service %{name} condrestart >/dev/null 2>&1 || :
 fi
 %endif
 
 %files
-%doc 00-RELEASENOTES BUGS CONTRIBUTING COPYING MANIFESTO README
+%{!?_licensedir:%global license %%doc}
+%license COPYING
+%doc 00-RELEASENOTES BUGS CONTRIBUTING MANIFESTO README
 %config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
-%config(noreplace) %{_sysconfdir}/%{name}.conf
+%attr(0644, redis, root) %config(noreplace) %{_sysconfdir}/%{name}.conf
 %if 0%{?with_sentinel}
-%config(noreplace) %{_sysconfdir}/%{name}-sentinel.conf
+%attr(0644, redis, root) %config(noreplace) %{_sysconfdir}/%{name}-sentinel.conf
 %endif
 %dir %attr(0750, redis, redis) %{_sharedstatedir}/%{name}
 %dir %attr(0750, redis, redis) %{_localstatedir}/log/%{name}
@@ -237,18 +245,23 @@ fi
 %{_bindir}/%{name}-*
 %if 0%{?with_systemd}
 %{_tmpfilesdir}/%{name}.conf
+%{_unitdir}/%{name}.service
 %if 0%{?with_sentinel}
 %{_unitdir}/%{name}-sentinel.service
 %endif
-%{_unitdir}/%{name}.service
 %else
+%{_initrddir}/%{name}
 %if 0%{?with_sentinel}
 %{_initrddir}/%{name}-sentinel
 %endif
-%{_initrddir}/%{name}
 %endif
 
 %changelog
+* Thu Sep 11 2014 Haïkel Guémar <hguemar at fedoraproject.org> - 2.8.14-2
+- Cleanup spec
+- Fix shutdown for redis-{server,sentinel}
+- Backport fixes from Remi Collet repository (ie: sentinel working)
+
 * Thu Sep 11 2014 Haïkel Guémar <hguemar at fedoraproject.org> - 2.8.14-1
 - Upstream 2.8.14
 - Bugfix for lua scripting users (server crash)


More information about the scm-commits mailing list