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
6### BEGIN INIT INFO
7# Provides:     redis_6379
8# Default-Start:        2 3 4 5
9# Default-Stop:         0 1 6
10# Short-Description:    Redis data structure server
11# Description:          Redis data structure server. See https://redis.io
12### END INIT INFO
13
14REDISPORT=6379
15EXEC=/usr/local/bin/redis-server
16CLIEXEC=/usr/local/bin/redis-cli
17
18PIDFILE=/var/run/redis_${REDISPORT}.pid
19CONF="/etc/redis/${REDISPORT}.conf"
20
21case "$1" in
22    start)
23        if [ -f $PIDFILE ]
24        then
25                echo "$PIDFILE exists, process is already running or crashed"
26        else
27                echo "Starting Redis server..."
28                $EXEC $CONF
29        fi
30        ;;
31    stop)
32        if [ ! -f $PIDFILE ]
33        then
34                echo "$PIDFILE does not exist, process is not running"
35        else
36                PID=$(cat $PIDFILE)
37                echo "Stopping ..."
38                $CLIEXEC -p $REDISPORT shutdown
39                while [ -x /proc/${PID} ]
40                do
41                    echo "Waiting for Redis to shutdown ..."
42                    sleep 1
43                done
44                echo "Redis stopped"
45        fi
46        ;;
47    *)
48        echo "Please use start or stop as first argument"
49        ;;
50esac
51