Skip to content

Instantly share code, notes, and snippets.

@v1nc3ntlaw
Created April 18, 2011 11:39
Show Gist options
  • Save v1nc3ntlaw/925168 to your computer and use it in GitHub Desktop.
Save v1nc3ntlaw/925168 to your computer and use it in GitHub Desktop.
redis_init_script
#!/bin/sh
REDIS_PORT=6379
REDIS_EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
REDIS_CONF=/etc/redis.conf
PIDFILE=/var/run/redis.pid
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo -e "$PIDFILE exists, process is already running or crashed\n"
else
echo -e "Starting Redis server..."
$REDIS_EXEC $REDIS_CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo -e "$PIDFILE does not exist, process is not running\n"
else
PID=$(cat $PIDFILE)
$REDIS_CLI -p $REDIS_PORT "shutdown"
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {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