官方给的启动脚本是发布包里的utils/redis_init_script文件。下面的脚本只是在官方脚本的基础上加了一点注释,和chkconfig。而sentinel实际上也是redis-server,只是另一种启动模式而已,所以它的启动脚本基本和redis-server的基本一致,只改一下可执行文件和配置文件即可。
redis-server:
#!/bin/sh
#
# chkconfig: 2345 55 25
# description: Redis server daemon
#
# processname: redis_6379 #需要修改与$port相同
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6387 # 需要修改与$port相同
BINPATH=/usr/local/redis/bin
EXEC=${BINPATH}/redis-server
CLIEXEC=${BINPATH}/redis-cli
PIDFILE=/data/redis/run/redis_${REDISPORT}.pid # pid file created by redis server as configured in the configuation file below.
CONF="/data/redis/conf/redis-conf/redis_${REDISPORT}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis $REDISPORT ..."
$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
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit
esac
redis-sentinel:
#!/bin/sh
#
# chkconfig: 2345 55 25
# description: Redis server daemon
#
# processname: redis_6379 #需要修改与$port相同
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=26379 # 需要修改与$port相同
BINPATH=/usr/local/redis/bin
EXEC=${BINPATH}/redis-sentinel
CLIEXEC=${BINPATH}/redis-cli
PIDFILE=/data/redis/run/sentinel_${REDISPORT}.pid # pid file created by sentinel as configured in the configuation file below.
CONF="/data/redis/conf/redis-conf/sentinel_${REDISPORT}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis $REDISPORT ..."
$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
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit
esac