From 9344f0e164a83b38791daf6b9a61d7294e1de652 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 6 Jan 2014 15:21:59 +0100 Subject: redis: add redis-sentinel (command + service) --- redis-2.8.3-conf.patch | 35 ++++++++++++-------- redis.init | 2 +- redis.logrotate | 2 +- redis.service | 2 +- redis.spec | 49 +++++++++++++++++++--------- sentinel.init | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ sentinel.service | 12 +++++++ 7 files changed, 158 insertions(+), 32 deletions(-) create mode 100644 sentinel.init create mode 100644 sentinel.service diff --git a/redis-2.8.3-conf.patch b/redis-2.8.3-conf.patch index f6ceba2..610e669 100644 --- a/redis-2.8.3-conf.patch +++ b/redis-2.8.3-conf.patch @@ -1,15 +1,7 @@ ---- redis-2.8.3/redis.conf.conf 2013-12-14 10:09:57.015046918 +0100 -+++ redis-2.8.3/redis.conf 2013-12-14 10:08:57.827879506 +0100 -@@ -18,7 +18,7 @@ - - # 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. -@@ -33,6 +33,7 @@ +diff -up redis-2.8.3/redis.conf.rpmconf redis-2.8.3/redis.conf +--- redis-2.8.3/redis.conf.rpmconf 2013-12-11 15:31:57.000000000 +0100 ++++ redis-2.8.3/redis.conf 2014-01-06 14:06:11.630724369 +0100 +@@ -33,6 +33,7 @@ port 6379 # # bind 192.168.1.100 10.0.0.1 # bind 127.0.0.1 @@ -17,7 +9,7 @@ # 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 -@@ -71,7 +72,7 @@ +@@ -71,7 +72,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 @@ -26,7 +18,7 @@ # To enable logging to the system logger, just set 'syslog-enabled' to yes, # and optionally update the other syslog parameters to suit your needs. -@@ -155,7 +156,7 @@ +@@ -155,7 +156,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. @@ -35,3 +27,18 @@ ################################# REPLICATION ################################# +diff -up redis-2.8.3/sentinel.conf.rpmconf redis-2.8.3/sentinel.conf +--- redis-2.8.3/sentinel.conf.rpmconf 2014-01-06 14:06:20.401749268 +0100 ++++ redis-2.8.3/sentinel.conf 2014-01-06 14:06:27.617769753 +0100 +@@ -4,6 +4,11 @@ + # The port that this sentinel instance will run on + port 26379 + ++# 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 /var/log/redis/sentinel.log ++ + # sentinel monitor + # + # Tells Sentinel to monitor this slave, and to consider it in O_DOWN diff --git a/redis.init b/redis.init index 14fad01..f100f9f 100644 --- a/redis.init +++ b/redis.init @@ -21,7 +21,7 @@ start() { [ -f $REDIS_CONFIG ] || exit 6 [ -x $exec ] || exit 5 echo -n $"Starting $name: " - daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG" + daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG --daemonize yes --pidfile $pidfile" retval=$? echo [ $retval -eq 0 ] && touch $lockfile diff --git a/redis.logrotate b/redis.logrotate index 43addc6..3a3d185 100644 --- a/redis.logrotate +++ b/redis.logrotate @@ -1,4 +1,4 @@ -/var/log/redis/redis.log { +/var/log/redis/*.log { weekly rotate 10 copytruncate diff --git a/redis.service b/redis.service index 3aaadb8..c7bb48a 100644 --- a/redis.service +++ b/redis.service @@ -3,7 +3,7 @@ Description=A persistent key-value database After=syslog.target network.target [Service] -ExecStart=/usr/sbin/redis-server /etc/redis.conf +ExecStart=/usr/sbin/redis-server /etc/redis.conf --daemonize no User=redis Group=redis diff --git a/redis.spec b/redis.spec index f9564ac..d57ee4b 100644 --- a/redis.spec +++ b/redis.spec @@ -36,6 +36,8 @@ Source1: %{name}.logrotate Source2: %{name}.init Source3: %{name}.service Source4: %{name}.tmpfiles +Source5: sentinel.init +Source6: sentinel.service # Update configuration for Fedora Patch0: %{name}-2.8.3-conf.patch Patch1: %{name}-deps-PIC.patch @@ -79,7 +81,7 @@ different kind of sorting abilities. %prep %setup -q -n %{name}-%{version}%{?prever:-%{prever}} -%patch0 -p1 -b .conf +%patch0 -p1 -b .rpmconf %patch1 -p1 -b .pic %patch2 -p1 -b .jem @@ -117,7 +119,8 @@ make test make install PREFIX=%{buildroot}%{_prefix} # Install misc other install -p -D -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/logrotate.d/%{name} -install -p -D -m 644 %{name}.conf %{buildroot}%{_sysconfdir}/%{name}.conf +install -p -D -m 644 %{name}.conf %{buildroot}%{_sysconfdir}/%{name}.conf +install -p -D -m 644 sentinel.conf %{buildroot}%{_sysconfdir}/%{name}-sentinel.conf install -d -m 755 %{buildroot}%{_localstatedir}/lib/%{name} install -d -m 755 %{buildroot}%{_localstatedir}/log/%{name} install -d -m 755 %{buildroot}%{_localstatedir}/run/%{name} @@ -125,12 +128,14 @@ install -d -m 755 %{buildroot}%{_localstatedir}/run/%{name} %if %{with_systemd} # Install systemd unit install -p -D -m 644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service +install -p -D -m 644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}-sentinel.service # Install systemd tmpfiles config, _tmpfilesdir only defined in fedora >= 18 install -p -D -m 644 %{SOURCE4} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf %else sed -e '/^daemonize/s/no/yes/' \ -i %{buildroot}%{_sysconfdir}/%{name}.conf install -p -D -m 755 %{SOURCE2} %{buildroot}%{_initrddir}/%{name} +install -p -D -m 755 %{SOURCE5} %{buildroot}%{_initrddir}/%{name}-sentinel %endif # Fix non-standard-executable-perm error @@ -148,19 +153,19 @@ ln -s %{name}-server %{buildroot}%{_sbindir}/%{name}-sentinel %post %if 0%{?systemd_post:1} %systemd_post redis.service -%else -if [ $1 = 1 ]; then - # Initial installation +%systemd_post redis-sentinel.service +%endif +# Initial installation (always, for new service) %if %{with_systemd} - /bin/systemctl daemon-reload >/dev/null 2>&1 || : +/bin/systemctl daemon-reload >/dev/null 2>&1 || : %else - /sbin/chkconfig --add redis -%endif -fi +/sbin/chkconfig --add redis +/sbin/chkconfig --add redis-sentinel %endif %pre -getent group redis &> /dev/null || groupadd -r redis &> /dev/null +getent group redis &> /dev/null || \ +groupadd -r redis &> /dev/null getent passwd redis &> /dev/null || \ useradd -r -g redis -d %{_sharedstatedir}/redis -s /sbin/nologin \ -c 'Redis Server' redis &> /dev/null @@ -169,13 +174,20 @@ exit 0 %preun %if 0%{?systemd_preun:1} %systemd_preun redis.service +%systemd_preun redis-sentinel.service %else if [ $1 = 0 ]; then # Package removal, not upgrade %if %{with_systemd} - /bin/systemctl --no-reload disable redis.service >/dev/null 2>&1 || : - /bin/systemctl stop redis.service >/dev/null 2>&1 || : + /bin/systemctl --no-reload disable redis-sentinel.service >/dev/null 2>&1 || : + /bin/systemctl stop redis-sentinel.service >/dev/null 2>&1 || : + + /bin/systemctl --no-reload disable redis.service >/dev/null 2>&1 || : + /bin/systemctl stop redis.service >/dev/null 2>&1 || : %else + /sbin/service redis-sentinel stop &> /dev/null + /sbin/chkconfig --del redis-sentinel &> /dev/null + /sbin/service redis stop &> /dev/null /sbin/chkconfig --del redis &> /dev/null %endif @@ -184,16 +196,19 @@ fi %if 0%{?systemd_postun_with_restart:1} %systemd_postun_with_restart redis.service +%systemd_postun_with_restart redis-sentinel.service %else %if %{with_systemd} /bin/systemctl daemon-reload >/dev/null 2>&1 || : if [ $1 -ge 1 ]; then # Package upgrade, not uninstall - /bin/systemctl try-restart redis.service >/dev/null 2>&1 || : + /bin/systemctl try-restart redis.service >/dev/null 2>&1 || : + /bin/systemctl try-restart redis-sentinel.service >/dev/null 2>&1 || : fi %else if [ $1 -ge 1 ]; then - /sbin/service redis condrestart >/dev/null 2>&1 || : + /sbin/service redis condrestart >/dev/null 2>&1 || : + /sbin/service redis-sentinel condrestart >/dev/null 2>&1 || : fi %endif %endif @@ -202,9 +217,9 @@ fi %files %defattr(-,root,root,-) %doc 00-RELEASENOTES BUGS CONTRIBUTING COPYING README -%doc sentinel.conf %config(noreplace) %{_sysconfdir}/logrotate.d/%{name} %attr(0644, redis, root) %config(noreplace) %{_sysconfdir}/%{name}.conf +%attr(0644, redis, root) %config(noreplace) %{_sysconfdir}/%{name}-sentinel.conf %dir %attr(0755, redis, root) %{_localstatedir}/lib/%{name} %dir %attr(0755, redis, root) %{_localstatedir}/log/%{name} %dir %attr(0755, redis, root) %{_localstatedir}/run/%{name} @@ -213,14 +228,18 @@ fi %if %{with_systemd} %{_prefix}/lib/tmpfiles.d/%{name}.conf %{_unitdir}/%{name}.service +%{_unitdir}/%{name}-sentinel.service %else %{_initrddir}/%{name} +%{_initrddir}/%{name}-sentinel %endif %changelog * Mon Jan 6 2014 Remi Collet - 2.8.3-2 - add redis-sentinel command (link to redis-server) +- don't rely on config for daemonize and pidfile +- add redis-sentinel service * Sat Dec 14 2013 Remi Collet - 2.8.3-1 - Redis 2.8.3 diff --git a/sentinel.init b/sentinel.init new file mode 100644 index 0000000..0ed325b --- /dev/null +++ b/sentinel.init @@ -0,0 +1,88 @@ +#!/bin/sh +# +# redis init file for starting up the redis-sentinel daemon +# +# chkconfig: - 21 79 +# description: Starts and stops the redis-sentinel daemon. + +# Source function library. +. /etc/rc.d/init.d/functions + +name="redis-sentinel" +exec="/usr/sbin/$name" +pidfile="/var/run/redis/sentinel.pid" +REDIS_CONFIG="/etc/redis-sentinel.conf" + +[ -e /etc/sysconfig/redis-sentinel ] && . /etc/sysconfig/redis-sentinel + +lockfile=/var/lock/subsys/redis + +start() { + [ -f $REDIS_CONFIG ] || exit 6 + [ -x $exec ] || exit 5 + echo -n $"Starting $name: " + daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG --daemonize yes --pidfile $pidfile" + 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/sentinel.service b/sentinel.service new file mode 100644 index 0000000..487f283 --- /dev/null +++ b/sentinel.service @@ -0,0 +1,12 @@ +[Unit] +Description=Redis sentinel +After=syslog.target network.target + +[Service] +ExecStart=/usr/sbin/redis-sentinel /etc/redis-sentinel.conf --daemonize no +User=redis +Group=redis + +[Install] +WantedBy=multi-user.target + -- cgit