前面发表过一篇Redis安装部署的文章,在这里沉醉寒风再给大家附上Redis SysV开机自启动脚本以备不时之需,请各位看官往下看:

Redis SysV开机自启动脚本

[root@localhost ~]# vi /etc/init.d/resdis
#!/bin/sh
#
# Redis - Startup script for redis
# chkconfig: - 85 15
# description: Redis Server
# Processname: redis
# Config: /etc/redis/redis.conf
# Pidfile: /var/run/redis.pid
# Author:沉醉寒风
# Email:liaoronghui@vip.qq.com
# Blog:http://www.liaoronghui.com
# Version:version 1.0

# Source function library.
. /etc/rc.d/init.d/functions

binfile=/usr/local/redis/bin/redis-server
config=/etc/redis/redis.conf
lock=/var/lock/subsys/redis
pidfile=/var/run/redis.pid
prog=redis
RETVAL=0

start() {
    [ -x $binfile ] || exit 5
    [ -f $config ] || exit 6
    if [ -e $pidfile ];then
        status $prog
        exit 1
    fi
    echo -n $"Starting $prog: "
    daemon "$binfile $config &>/dev/null"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lock $pidfile
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f $lock $pidfile
    return $RETAVAL
}
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
status)
    status $prog
    ;;
*)
    echo $"Usage: $0 {start|stop|status|restart}"
    RETVAL=1
esac
exit $RETVAL

设置开机自启动

[root@localhost ~]# chmod 755 /etc/init.d/redis         #给脚本赋予执行权限
[root@localhost ~]# chkconfig --add redis               #加入到chkconfig管理
[root@localhost ~]# chkconfig redis on                  #设置开机自启动