xref: /redis-3.2.3/utils/redis_init_script (revision 55937b79)
1a69a0c9cSantirez#!/bin/sh
2b0d68504Santirez#
3b0d68504Santirez# Simple Redis init.d script conceived to work on Linux systems
4b0d68504Santirez# as it does use of the /proc filesystem.
5a69a0c9cSantirez
6a69a0c9cSantirezREDISPORT=6379
7a69a0c9cSantirezEXEC=/usr/local/bin/redis-server
8b0d68504SantirezCLIEXEC=/usr/local/bin/redis-cli
9a69a0c9cSantirez
10a69a0c9cSantirezPIDFILE=/var/run/redis_${REDISPORT}.pid
11a69a0c9cSantirezCONF="/etc/redis/${REDISPORT}.conf"
12a69a0c9cSantirez
13a69a0c9cSantirezcase "$1" in
14a69a0c9cSantirez    start)
15a69a0c9cSantirez        if [ -f $PIDFILE ]
16a69a0c9cSantirez        then
17b0d68504Santirez                echo "$PIDFILE exists, process is already running or crashed"
18a69a0c9cSantirez        else
19b0d68504Santirez                echo "Starting Redis server..."
20a69a0c9cSantirez                $EXEC $CONF
21a69a0c9cSantirez        fi
22a69a0c9cSantirez        ;;
23a69a0c9cSantirez    stop)
24a69a0c9cSantirez        if [ ! -f $PIDFILE ]
25a69a0c9cSantirez        then
26b0d68504Santirez                echo "$PIDFILE does not exist, process is not running"
27a69a0c9cSantirez        else
28a69a0c9cSantirez                PID=$(cat $PIDFILE)
29b0d68504Santirez                echo "Stopping ..."
30b0d68504Santirez                $CLIEXEC -p $REDISPORT shutdown
31*55937b79Santirez                while [ -x /proc/${PID} ]
32a69a0c9cSantirez                do
33a69a0c9cSantirez                    echo "Waiting for Redis to shutdown ..."
34a69a0c9cSantirez                    sleep 1
35a69a0c9cSantirez                done
36a69a0c9cSantirez                echo "Redis stopped"
37a69a0c9cSantirez        fi
38a69a0c9cSantirez        ;;
39b0d68504Santirez    *)
40b0d68504Santirez        echo "Please use start or stop as first argument"
41b0d68504Santirez        ;;
42a69a0c9cSantirezesac
43