Skip to content

Instantly share code, notes, and snippets.

@zacharydanger
Created May 9, 2012 14:59
Show Gist options
  • Save zacharydanger/2645140 to your computer and use it in GitHub Desktop.
Save zacharydanger/2645140 to your computer and use it in GitHub Desktop.
/etc/init.d/redis-server
#!/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: God
### END INIT INFO
NAME=redis-server
DESC=redis-server
REDIS_CONFIG=/etc/redis/redis.conf
REDIS_SERVER_BIN=/usr/local/bin/redis-server
REDIS_CLI_BIN=/usr/local/bin/redis-cli
set -e
# Make sure the binary and the config file are present before proceeding
test -x $REDIS_SERVER_BIN || exit 0
# Create this file and put in a variable called REDIS_CONFIG, pointing to
# your Redis configuration file
[ $REDIS_CONFIG ] || exit 0
# . /lib/lsb/init-functions
RETVAL=0
case "$1" in
start)
echo -n "Starting $DESC: "
$REDIS_SERVER_BIN $REDIS_CONFIG
RETVAL=$?
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
$REDIS_CLI_BIN shutdown
RETVAL=$?
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
$REDIS_CLI_BIN shutdown
$REDIS_SERVER_BIN $REDIS_CONFIG
RETVAL=$?
echo "$NAME."
;;
status)
$REDIS_CLI_BIN info
RETVAL=$?
;;
*)
echo "Usage: redis-server {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment