Redis start and stop script

Environment: multi-instance environment, specify the port start-stop service

Scripting:

#! bin / SH
# call the function function
# This is redis start, stop, restart script
REDISPORT = $ 1
#redis of pid
EXEC = / usr / local / redis4 / bin / redis-Server
CONF = "/ etc / redis / $ REDISPORT .conf} { "
CLIEXEC = / usr / local / redis4 / bin / CLI-Redis
the PID #redis file location, it is necessary to modify
PIDFILE = / var / run / redis _ $ {REDISPORT} .pid
profile location #redis of $ {REDISPORT} need to modify the file name
Start () {
IF [-f $ PIDFILE]
the then
echo "$ PIDFILE EXISTS, iS already running or Crashed Process"
the else
echo "Starting the Redis Server ..."
$ $ CONF EXEC
Fi
}
STOP () {
IF [! -f $ PIDFILE]
the then
echo "$ Not PIDFILE does exist, IS Process 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(){
stop
start
if [ $? = 0 ];then
echo "重启成功....."
fi
}
case "$2" in
start)
start
;;
stop)
stop
;;

restart)
restart
;;
*)
echo "使用方法:sh 脚本名 端口 参数 {start|stop|start}"
esac

According to the startup script, copy the good will modify configuration files to a specified directory, operated by the root user:

mkdir /etc/redis

cp redis_6379.conf /etc/redis/6379.conf

Copy the startup script to the /etc/init.d directory, in this case the startup script named redisd

Empowerment: chmod 755 redisd

use:

service  redisd  6379 restart

 

Guess you like

Origin www.cnblogs.com/any-way/p/11599634.html