#!/bin/sh | |
# | |
# redis - this script starts and stops the redis-server daemon | |
# | |
# chkconfig: - 85 15 | |
# description: Redis is a persistent key-value database | |
# processname: redis-server | |
# config: /etc/redis/redis.conf | |
# config: /etc/sysconfig/redis | |
# pidfile: /var/run/redis.pid | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
# Source networking configuration. | |
. /etc/sysconfig/network | |
# Check that networking is up. | |
[ "$NETWORKING" = "no" ] && exit 0 | |
redis="/usr/local/sbin/redis-server" | |
prog=$(basename $redis) | |
REDIS_CONF_FILE="/etc/redis/redis.conf" | |
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis | |
lockfile=/var/lock/subsys/redis | |
start() { | |
[ -x $redis ] || exit 5 | |
[ -f $REDIS_CONF_FILE ] || exit 6 | |
echo -n $"Starting $prog: " | |
daemon $redis $REDIS_CONF_FILE | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && touch $lockfile | |
return $retval | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
killproc $prog -QUIT | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && rm -f $lockfile | |
return $retval | |
} | |
restart() { | |
stop | |
start | |
} | |
reload() { | |
echo -n $"Reloading $prog: " | |
killproc $redis -HUP | |
RETVAL=$? | |
echo | |
} | |
force_reload() { | |
restart | |
} | |
rh_status() { | |
status $prog | |
} | |
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|configtest) | |
$1 | |
;; | |
reload) | |
rh_status_q || exit 7 | |
$1 | |
;; | |
force-reload) | |
force_reload | |
;; | |
status) | |
rh_status | |
;; | |
condrestart|try-restart) | |
rh_status_q || exit 0 | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | |
exit 2 | |
esac |
This comment has been minimized.
This comment has been minimized.
Caveat emptor: I'm no longer running CentOS, and haven't tested this. When Redis receives a SIGTERM it performs a graceful shutdown. There's no need to use the However, this script was written to use SIGQUIT instead of SIGTERM, which was probably a mistake. If you're using this script, you might want to try using SIGTERM (change L43). That should give you graceful shutdown without increasing complexity. |
This comment has been minimized.
This comment has been minimized.
Looking at the source, I think redis ignores SIGHUP. |
This comment has been minimized.
This comment has been minimized.
Thanks a lot for this script! |
This comment has been minimized.
This comment has been minimized.
I'd like to suggest adding a user variable and changing the start command to this (line 34): |
This comment has been minimized.
This comment has been minimized.
Hi, Stopping with killproc there are the problem that is possible lost data. Redis in his documentation say: Redis will spontaneously save the dataset only from time to time (for instance after at least five minutes if you have at least 100 changes in your data), so if you want your database to persist and be reloaded after a restart make sure to call the SAVE command manually every time you want to force a data set snapshot. Otherwise make sure to shutdown the database using the SHUTDOWN command I'm in correct? How Can I do that this script stop with shutdown command ? Thanks Regards |
This comment has been minimized.
This comment has been minimized.
mrcmorales: Regards, |
This comment has been minimized.
This comment has been minimized.
great |
This comment has been minimized.
This comment has been minimized.
Thanks. |
This comment has been minimized.
This comment has been minimized.
Thanks for this. Most helpful. |
This comment has been minimized.
This comment has been minimized.
How to set pid file? I set it in the .conf file, but it should be set in the init script too. |
This comment has been minimized.
This comment has been minimized.
Well, if you don't have any special reasons to compile Redis from source and do all of this chkconfig initscripts, you may consider to use remi repository to install Redis without any extra effort except typing For more info: and |
This comment has been minimized.
This comment has been minimized.
tnx for useful script. |
This comment has been minimized.
This comment has been minimized.
The best fork from this gist (currently) is: https://gist.github.com/tahajahangir/155176867afed0ff80ad
|
This comment has been minimized.
This comment has been minimized.
I have redis v2.8.19-2 installed on my CentOS 6.5 server. # rpm -qa | grep redis
redis-2.8.19-2.el6.art.x86_64 I have just commented out below line from stop () function and assigned retval=1 stop() {
echo -n $"Stopping $name: "
#[ -x $shut ] && $shut
retval=1
if [ -f $pidfile ]
then
# shutdown haven't work, try old way
killproc -p $pidfile $name
retval=$?
else
success "$name shutdown"
fi
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} Now, it does not throws error in stop, start, status, or restart. Hope this helps someone. Regards, |
This comment has been minimized.
This comment has been minimized.
This script is not working for me. Anyone know what is going on? Starting redis-server: chown: invalid user: |
This comment has been minimized.
This comment has been minimized.
@tpaveyjr I used the https://gist.github.com/tahajahangir/155176867afed0ff80ad fork and had the same problem (on CentOS 6.6). Solved by adding |
This comment has been minimized.
This comment has been minimized.
This didn't quite work for me, so I tweaked it to use more generic/plain constructs: https://gist.github.com/ac-astuartkregor/5d11fe0e9f028087b66ac90423293263 |
This comment has been minimized.
How about stopping the Redis with the command __"shutdown" __ provided by Redis? will it be better?