CentOS下的Redis启动脚本

来源:互联网 发布:淘宝店主在哪里进货 编辑:程序博客网 时间:2024/05/29 21:29
这是一个Shell脚本,用于管理Redis进程(启动,停止,重启),如果你在使用Redis,这个脚本可供参考。
标签:Redis CentOS

代码片段(1)[全屏查看所有代码]

1. [代码][Shell/批处理]代码     跳至 [1] [全屏预览]

view source
print?
001#!/bin/sh
002#
003# redis - this script starts and stops the redis-server daemon
004#
005# chkconfig:   - 85 15
006# description:  Redis is a persistent key-value database
007# processname: redis-server
008# config:      /etc/redis/redis.conf
009# config:      /etc/sysconfig/redis
010# pidfile:     /var/run/redis.pid
011 
012# Source function library.
013. /etc/rc.d/init.d/functions
014 
015# Source networking configuration.
016. /etc/sysconfig/network
017 
018# Check that networking is up.
019"$NETWORKING" "no" ] && exit 0
020 
021redis="/usr/local/sbin/redis-server"
022prog=$(basename $redis)
023 
024REDIS_CONF_FILE="/etc/redis/redis.conf"
025 
026[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
027 
028lockfile=/var/lock/subsys/redis
029 
030start() {
031    [ -x $redis ] || exit 5
032    [ -f $REDIS_CONF_FILE ] || exit 6
033    echo -n $"Starting $prog: "
034    daemon $redis $REDIS_CONF_FILE
035    retval=$?
036    echo
037    [ $retval -eq 0 ] && touch $lockfile
038    return $retval
039}
040 
041stop() {
042    echo -n $"Stopping $prog: "
043    killproc $prog -QUIT
044    retval=$?
045    echo
046    [ $retval -eq 0 ] && rm -f $lockfile
047    return $retval
048}
049 
050restart() {
051    stop
052    start
053}
054 
055reload() {
056    echo -n $"Reloading $prog: "
057    killproc $redis -HUP
058    RETVAL=$?
059    echo
060}
061 
062force_reload() {
063    restart
064}
065 
066rh_status() {
067    status $prog
068}
069 
070rh_status_q() {
071    rh_status >/dev/null 2>&1
072}
073 
074case "$1" in
075    start)
076        rh_status_q && exit 0
077        $1
078        ;;
079    stop)
080        rh_status_q || exit 0
081        $1
082        ;;
083    restart|configtest)
084        $1
085        ;;
086    reload)
087        rh_status_q || exit 7
088        $1
089        ;;
090    force-reload)
091        force_reload
092        ;;
093    status)
094        rh_status
095        ;;
096    condrestart|try-restart)
097        rh_status_q || exit 0
098        ;;
099    *)
100        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
101        exit 2
102esac