I had to make these changes to the init.d start up and stop scripts - the server only seemed to create redis.pid not redis{port}.pid

Simple Redis init.d script conceived to work on Linux systems

as it does use of the /proc filesystem.

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

PIDFILE=/var/run/redis_${REDISPORT}.pid PIDFILE2=/var/run/redis.pid CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." touch $PIDFILE echo ${REDISPORT} > $PIDFILE $EXEC $CONF sleep 1 rm $PIDFILE2 fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE)

            echo "Stopping ... " $PID
            $CLIEXEC -p $REDISPORT shutdown
    rm $PIDFILE
            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

Comment From: ljluestc

#!/bin/sh
### BEGIN INIT INFO
# Provides:          redis-server
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Redis data structure server
# Description:       Redis data structure server. See https://redis.io
### END INIT INFO

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

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in
start)
    if [ -f $PIDFILE ]; then
        echo "$PIDFILE exists, process is already running or crashed"
    else
        echo "Starting Redis server..."
        $EXEC $CONF
        sleep 1
    fi
    ;;
stop)
    if [ ! -f $PIDFILE ]; then
        echo "$PIDFILE does not exist, process is not running"
    else
        PID=$(cat $PIDFILE)
        echo "Stopping Redis... PID: $PID"
        $CLIEXEC -p $REDISPORT shutdown
        while [ -x /proc/${PID} ]; do
            echo "Waiting for Redis to shutdown..."
            sleep 1
        done
        echo "Redis stopped"
        rm $PIDFILE
    fi
    ;;
*)
    echo "Usage: $0 {start|stop}"
    exit 1
    ;;
esac

exit 0

This script adheres to the standard init.d script format and includes the changes you mentioned:

It uses a specific PID file (/var/run/redis_${REDISPORT}.pid) based on the port to avoid conflicts. The $EXEC command to start Redis is invoked without creating a PID file, as Redis creates its own PID file. The PID file is removed in the "stop" section after Redis has successfully shut down.