From bfae9dba22d4064274d09231dfec9c9a431a3736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AFkel=20Gu=C3=A9mar?= Date: Thu, 11 Sep 2014 21:40:02 +0200 Subject: [PATCH] Cleanup spec Fix shutdown for redis-{server,sentinel} Backport fixes from Remi Collet repository Drop unused patch --- ...2.8.11-redis-conf-location-variables.patch | 54 ----------- redis-sentinel.service | 4 +- redis-server.init | 93 ------------------- redis-server.service | 13 --- redis-shutdown | 28 ++++++ redis.service | 1 + redis.spec | 57 +++++++----- 7 files changed, 66 insertions(+), 184 deletions(-) delete mode 100644 redis-2.8.11-redis-conf-location-variables.patch delete mode 100644 redis-server.init delete mode 100644 redis-server.service create mode 100644 redis-shutdown diff --git a/redis-2.8.11-redis-conf-location-variables.patch b/redis-2.8.11-redis-conf-location-variables.patch deleted file mode 100644 index 47e70f3..0000000 --- a/redis-2.8.11-redis-conf-location-variables.patch +++ /dev/null @@ -1,54 +0,0 @@ -Index: redis-2.8.11/redis.conf -=================================================================== ---- redis-2.8.11.orig/redis.conf -+++ redis-2.8.11/redis.conf -@@ -34,11 +34,11 @@ - - # By default Redis does not run as a daemon. Use 'yes' if you need it. - # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. --daemonize no -+daemonize yes - - # When running daemonized, Redis writes a pid file in /var/run/redis.pid by - # default. You can specify a custom pid file location here. --pidfile /var/run/redis.pid -+pidfile /var/run/redis/redis.pid - - # Accept connections on the specified port, default is 6379. - # If port 0 is specified Redis will not listen on a TCP socket. -@@ -61,7 +61,7 @@ tcp-backlog 511 - # Examples: - # - # bind 192.168.1.100 10.0.0.1 --# bind 127.0.0.1 -+bind 127.0.0.1 - - # Specify the path for the Unix socket that will be used to listen for - # incoming connections. There is no default, so Redis will not listen -@@ -87,7 +87,7 @@ timeout 0 - # On other kernels the period depends on the kernel configuration. - # - # A reasonable value for this option is 60 seconds. --tcp-keepalive 0 -+tcp-keepalive 60 - - # Specify the server verbosity level. - # This can be one of: -@@ -100,7 +100,7 @@ loglevel notice - # Specify the log file name. Also the empty string can be used to force - # Redis to log on the standard output. Note that if you use standard - # output for logging but daemonize, logs will be sent to /dev/null --logfile "" -+logfile /var/log/redis/redis.log - - # To enable logging to the system logger, just set 'syslog-enabled' to yes, - # and optionally update the other syslog parameters to suit your needs. -@@ -184,7 +184,7 @@ dbfilename dump.rdb - # The Append Only File will also be created inside this directory. - # - # Note that you must specify a directory here, not a file name. --dir ./ -+dir /var/lib/redis/ - - ################################# REPLICATION ################################# - diff --git a/redis-sentinel.service b/redis-sentinel.service index f71e33a..43d4ad4 100644 --- a/redis-sentinel.service +++ b/redis-sentinel.service @@ -4,8 +4,8 @@ After=network.target [Service] ExecStartPre=/usr/bin/mkdir -p /var/lib/redis -ExecStart=/usr/bin/redis-sentinel /etc/sentinel.conf -ExecStop=/usr/bin/redis-cli shutdown +ExecStart=/usr/bin/redis-sentinel /etc/redis-sentinel.conf +ExecStop=/usr/bin/redis-shutdown sentinel User=redis Group=redis diff --git a/redis-server.init b/redis-server.init deleted file mode 100644 index 0a3d318..0000000 --- a/redis-server.init +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/sh -# -# redis init file for starting up the redis daemon -# -# chkconfig: - 20 80 -# description: Starts and stops the redis daemon. - -# Source function library. -. /etc/rc.d/init.d/functions - -NAME="redis-server" -EXEC="/usr/bin/$NAME" -REDIS_CONFIG="/etc/redis.conf" -RUNDIR="/var/run/redis" -PIDFILE="$RUNDIR/redis.pid" - -[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis - -lockfile=/var/lock/subsys/redis - -start() { - [ -f $REDIS_CONFIG ] || exit 6 - [ -x $EXEC ] || exit 5 - echo -n $"Starting $NAME: " - mkdir -p $RUNDIR - touch $PIDFILE - chown redis:redis $RUNDIR $PIDFILE - chmod 750 $RUNDIR - daemon --user ${REDIS_USER-redis} "$EXEC $REDIS_CONFIG" - retval=$? - echo - [ $retval -eq 0 ] && touch $lockfile - return $retval -} - -stop() { - echo -n $"Stopping $NAME: " - killproc -p $PIDFILE $NAME - retval=$? - echo - [ $retval -eq 0 ] && rm -f $lockfile - return $retval -} - -restart() { - stop - start -} - -reload() { - false -} - -rh_status() { - status -p $PIDFILE $NAME -} - -rh_status_q() { - rh_status >/dev/null 2>&1 -} - - -case "$1" in - start) - rh_status_q && exit 0 - $1 - ;; - stop) - rh_status_q || exit 0 - $1 - ;; - restart) - $1 - ;; - reload) - rh_status_q || exit 7 - $1 - ;; - force-reload) - force_reload - ;; - status) - rh_status - ;; - condrestart|try-restart) - rh_status_q || exit 0 - restart - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" - exit 2 -esac -exit $? diff --git a/redis-server.service b/redis-server.service deleted file mode 100644 index a8411b1..0000000 --- a/redis-server.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Redis persistent key-value database -After=network.target - -[Service] -ExecStartPre=/usr/bin/mkdir -p /var/lib/redis -ExecStart=/usr/bin/redis-server /etc/redis.conf -ExecStop=/usr/bin/redis-cli shutdown -User=redis -Group=redis - -[Install] -WantedBy=multi-user.target 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 7f326d0..c968ba8 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 - 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 - 2.8.14-1 - Upstream 2.8.14 (RHBZ #1136287) - Bugfix for lua scripting users (server crash)