Skip to content

Instantly share code, notes, and snippets.

@sldenazis
Last active January 1, 2016 05:39
Show Gist options
  • Save sldenazis/8099587 to your computer and use it in GitHub Desktop.
Save sldenazis/8099587 to your computer and use it in GitHub Desktop.
Simple redis init script for red hat 6.5.
#!/bin/bash
# Author: Santiago López Denazis
# License: GPL v.3+
# Description: Simple Redis init.d script conceived to work on RH 6.5
source /etc/rc.d/init.d/functions
[ -f /etc/sysconfig/redis ] && {
source /etc/sysconfig/redis
}
redis_cli=${CLIEXEC-/opt/redis-2.8.1/src/redis-cli}
redisport=${REDISPORT-6379}
conf=${CONF-/etc/redis/${redisport}.conf}
pidfile=${PIDFILE-/var/run/redis/${redisport}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/redis_${redisport}}
user=${USER_REDIS-redis}
redis_server=${REDIS_SERVER-/opt/redis-2.8.1/src/redis-server}
STOP_TIMEOUT=${STOP_TIMEOUT-10}
RETVAL=0
start() {
echo -n $"Starting ${redis_server}: "
daemon --pidfile=${pidfile} --user=${user} "${redis_server} ${conf} &> /var/log/redis.log &"
RETVAL=$?
echo
[ $RETVAL = 0 ] && {
touch ${lockfile}
## XXX: sorry for this
ps ax | grep ${redis_server} | grep -v grep | awk '{print $1}' > ${pidfile}
}
return $RETVAL
}
stop() {
echo -n $"Stopping ${redis_server}: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} ${redis_server}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop && start
;;
status)
status -p ${pidfile} ${redis_server}
;;
*)
echo "Usage: $0 {start|stop|restart|status}" >&2
;;
esac
@sldenazis
Copy link
Author

This works with 'daemon yes' option in redis.conf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment