加入redis 开机启动
创建文件
/etc/init.d/redis
加入如下脚本,根据自己的安装目录进行调整
#!/bin/sh
# chkconfig: 2345 80 90
# description: Redis is a persistent key-value database
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/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
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
加入开机启动
# chkconfig --add redis //开启自启动
# chkconfig redis off //关闭自启动
# chkconfig --del redis //删除自启动
问题
有些脚本中缺少
# chkconfig: 2345 80 90
会导致开机启动加入失败,出现如下类似异常
[root@localhost bin]# chkconfig --add redis
服务 redis 不支持 chkconfig