Skip to content

Instantly share code, notes, and snippets.

@drfeelngood
Created August 2, 2011 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drfeelngood/1120451 to your computer and use it in GitHub Desktop.
Save drfeelngood/1120451 to your computer and use it in GitHub Desktop.
redis-server service script
#!/bin/bash
# redis Advanced key-value store
#
# chkconfig: 2345
# description: Redis is an open source, advanced key-value store. It is often
# referred to as a data structure server since keys can contain
# strings, hashes, lists, sets and sorted sets.
# processname: redis-server
# pidfile: /var/run/redis.pid
# config: /etc/redis.conf
. /etc/init.d/functions # Source function library.
EXE=/usr/local/bin/redis-server
CLIEXE=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF=/etc/redis.conf
PORT=6379
prog="redis-server"
# Start daemon
start()
{
if [ -f $PIDFILE ]; then
ret=1
echo "$PIDFILE exists, process is already running or crashed."
action $"Starting $prog: " /bin/false
else
$EXE $CONF
ret=$?
if [ $ret -eq 0 ]; then
action $"Starting $prog: " /bin/true
else
action $"Starting $prog: " /bin/false
fi
fi
return $ret
}
# Stop daemon
stop()
{
if [ ! -f $PIDFILE ]; then
ret=1
echo "$PIDFILE does not exist."
action $"Stopping $prog: " /bin/false
else
PID=`cat "$PIDFILE" 2>/dev/null`
if [ -n $PID ]; then
$CLIEXE -p $PORT shutdown
ret=$?
if [ $ret -eq 0 ]; then
while [ -x /prod/${PID} ]; do
echo -n "."
sleep 1
done
action $"Stopping $prog: " /bin/true
else
ret=1
action $"Stopping $prog: " /bin/false
fi
else
ret=1
action $"Stopping $prod: " /bin/false
fi
fi
return $ret
}
# Main
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status redis-server
;;
*)
echo "Usage $0 (start|stop|restart|status)"
exit 1
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment