Skip to content

Instantly share code, notes, and snippets.

@srounet
Created May 4, 2011 10:11
Show Gist options
  • Save srounet/955029 to your computer and use it in GitHub Desktop.
Save srounet/955029 to your computer and use it in GitHub Desktop.
init.d script for redis
#!/bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server Persistent key-value db
# Description: redis-server Persistent key-value db
### END INIT INFO
CONFIGFILE=/opt/redis/redis.conf
LISTENING_PORT=6379
DAEMON=/opt/redis/redis-server
DESC=redis-server
LOGFILE=/var/log/redis.log
NAME=redis-server
PATH=/opt/redis/bin:$PATH
PIDFILE=/var/run/redis.pid
REDIS_CLI=/opt/redis/redis-cli
RUNAS=redis:nibbler
test -x $DAEMON || exit 0
#set -e
case "$1" in
start)
echo -n "Starting $DESC: "
touch $LOGFILE
chown redis:nibbler $LOGFILE
exec start-stop-daemon --start --pidfile $PIDFILE --chuid $RUNAS --exec $DAEMON -- $CONFIGFILE
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
$REDIS_CLI -p $LISTENING_PORT SHUTDOWN
echo "$NAME."
;;
restart|force-reload)
${0} stop
${1} start
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment