Redis – Troubleshooting Redis Not Starting with systemctl

redissystemctlsystemdUbuntu

I have installed redis on an ubuntu 16.04 machine and if I run /usr/local/bin/redis-server /etc/redis/cluster/7000/redis.conf it starts up and I can connect to it without issues.

However I want to start it using systemctl start redis, so I have created the following file at /etc/systemd/system/redis7000.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/cluster/7000/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

and the redis config has supervised systemd set

which I think looks good, but I get the following errors:

Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: Started Redis In-Memory Data Store.
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=21661, just started
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # Configuration loaded
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # systemd supervision requested, but NOTIFY_SOCKET not found
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Main process exited, code=exited, status=1/FAILURE
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Unit entered failed state.
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Failed with result 'exit-code'.
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: redis7000.service: Service hold-off time over, scheduling restart.
Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: Stopped Redis In-Memory Data Store.

And I am not even sure what this means, so could someone guide me in the right direction?

Best Answer

To run redis under systemd, you need to set supervised systemd.

See the configuration file:

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised no

Needs to be changed to:

supervised systemd

You can also pass this on the command line, which overrides the setting in redis.conf. Red Hat based systems do this. This also allows for running the same redis instance manually or from systemd without changing the config file.

ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd

In addition, you also need to tell systemd that redis will be operating in this mode by setting Type=notify in the [Service] section.