#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379 #端口号,这是默认的,如果你安装的时候不是默认端口号,则需要修改
REDISPATH=/usr/local/redis/bin #redis-server启动脚本的所在目录,你如果忘了可以用find / -name redis-server 或whereis redis-server找到
EXEC=${REDISPATH}/redis-server
CLIEXEC=${REDISPATH}/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid #在redis.conf中可找到该路径
CONF="/usr/local/redis/etc/redis.conf" #redis.conf的位置, 如果不和redis-server在同一目录要修改成你的redis.conf所在目录
SlCONF="/usr/local/redis/etc/sentinel.conf --sentinel"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF;
$EXEC $SlCONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a '123456' -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
注意:更新完脚本后要执行:systemctl daemon-reload,不然不生效