Redis Daemon not creating a PID file

jsmartt picture jsmartt · Aug 26, 2014 · Viewed 45.4k times · Source

The Redis startup script is supposed to create a pid file at startup, but I've confirmed all the settings I can find, and no pid file is ever created.

I installed redis by:

$ yum install redis
$ chkconfig redis on
$ service redis start

In my config file (/etc/redis.conf) I checked to make sure these were enabled:

daemonize yes
pidfile /var/run/redis/redis.pid

And in the startup script (/etc/init.d/redis) there is:

exec="/usr/sbin/$name"
pidfile="/var/run/redis/redis.pid"
REDIS_CONFIG="/etc/redis.conf"

[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis

lockfile=/var/lock/subsys/redis

start() {
    [ -f $REDIS_CONFIG ] || exit 6
    [ -x $exec ] || exit 5
    echo -n $"Starting $name: "
    daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $name: "
    killproc -p $pidfile $name
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

These are the settings that came by default with the install. Any idea why no pid file is created? I need to use it for Monit. (The system is RHEL 6.4 btw)

Answer

jgrocha picture jgrocha · Nov 5, 2018

On my Ubuntu 18.04, I was getting the same error.

Error reported by redis (on /var/log/redis/redis-server.log):

 # Creating Server TCP listening socket ::1:6379: bind: Cannot assign requested address

This is because I've disabled IPv6 on this host and redis-server package (version 5:4.0.9-1) for Ubuntu comes with:

bind 127.0.0.1 ::1

Editing /etc/redis/redis.conf and removing the ::1 address solves the problem. Example:

bind 127.0.0.1

Edit: As pointed out in the comments (thanks to @nicholas-vasilaki and @tommyalvarez), by default redis only allows connections from localhost. Commenting all the line, using:

# bind 127.0.0.1 ::1

works, but makes redis listen from the network (not only from localhost).

More details can be found in redis configuration file.