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