Created
January 12, 2014 05:52
-
-
Save jamiesun/8381445 to your computer and use it in GitHub Desktop.
redis service script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Simple Redis init.d script conceived to work on Linux systems | |
# as it does use of the /proc filesystem. | |
# | |
# redis This is the init script for starting up the Redis server | |
# | |
# chkconfig: 2345 85 15 | |
# description: Starts and stops the redis daemon that handles \ | |
# all redis session requests. | |
# processname: redis-server | |
# pidfile: /var/run/redis.pid | |
### BEGIN INIT INFO | |
# Provides: redis | |
# Required-Start: $local_fs $syslog | |
# Required-Stop: | |
# Default-Start: 3 4 5 | |
# Default-Stop: 0 1 2 6 | |
# Short-Description: redis session server | |
# Description: Starts and stops the redis session daemon that handles | |
# all session requests. | |
### END INIT INFO | |
REDISPORT=6379 | |
EXEC=/usr/local/bin/redis-server | |
CLIEXEC=/usr/local/bin/redis-cli | |
PIDFILE=/var/run/redis.pid | |
CONF="/etc/redis.conf" | |
case "$1" in | |
start) | |
if [ -f $PIDFILE ] | |
then | |
echo "$PIDFILE exists, process is already running or crashed" | |
else | |
echo "Starting Redis server..." | |
$EXEC $CONF | |
fi | |
;; | |
stop) | |
if [ ! -f $PIDFILE ] | |
then | |
echo "$PIDFILE does not exist, process is not running" | |
else | |
PID=$(cat $PIDFILE) | |
echo "Stopping ..." | |
$CLIEXEC -p $REDISPORT shutdown | |
while [ -x /proc/${PID} ] | |
do | |
echo "Waiting for Redis to shutdown ..." | |
sleep 1 | |
done | |
echo "Redis stopped" | |
fi | |
;; | |
*) | |
echo "Please use start or stop as first argument" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment