redis 启动停止脚本

redis 启动停止脚本,该redis需要密码登录,如没有密码,去掉stop函数里的 -a 

#!/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=24679
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.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 -a "2018" -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

关于“redis pid文件怎么生成”这个问题,我认为:redis.conf配置参数: 
  1)daemonize on|yes 
  redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes时,启用守护进程 
  2)pidfile /var/run/redis_24679.pid 
  redis以守护进程方式运行时,系统默认会把pid写入/var/run/redis.pid,可以通过pidfile指定pid文件 
  3)port 24679
  redis默认监听24679端口,可以通过port指定redis要监听的端口。

猜你喜欢

转载自www.cnblogs.com/xzlive/p/9651045.html