linux中service配置之redis

#section 1
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#
# redis    This is the init script for starting up the Redis server
#
# chkconfig: 2345 85 15
# description: Starts and stops the redis daemon that handles \
#              all redis session requests.
# processname: redis-server
# pidfile: /var/run/redis.pid
### BEGIN INIT INFO
# Provides: redis
# Required-Start: $local_fs $syslog
# Required-Stop:
# Default-Start:  3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: redis session server
# Description: Starts and stops the redis session daemon that handles
#              all session requests.
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
#section 2
        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
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
 
 

本文出自 “但行好事莫问前程” 博客,谢绝转载!

你可能感兴趣的:(redis,service,职场,休闲)