25

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?

munHunger
  • 423

6 Answers6

23

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.

Michael Hampton
  • 252,907
14

As I cannot add a comment due to lack of reputation, please take this as a comment to Michael Hampston's answer.

When modifying the systemd service file, use the command systemctl edit redis-server to create an override. In the resulting edit window, type the following:

[Service]
Type=notify

Save and exit then finish the installation apt install -f.

If you modify the service in /lib/systemd/system, you'll lose those edits on next update.

See: modify systemd unit file without altering upstream unit file

PS: This question saved me from having to scratch my head for too long as I just encountered the issue.

AnthonyK
  • 240
0
# 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
#                        requires "expect stop" in your upstart job config
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#                        on startup, and updating Redis status on a regular
#                        basis.
#   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 pings back to your supervisor.
#
# The default is "no". To run under upstart/systemd, you can simply uncomment
# the line below:
#
supervised systemd

under supervised systemd option you would be able to start redis as systemd. But for proper functioning of systemd for redis. For this you need to set the daemonize value to yes.

daemonize yes

Followed by proper systemd service

[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
Wants=network-online.target
After=network-online.target

[Service] User=redis Group=redis TimeoutSec=1200 ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf ExecStop=/usr/local/bin/redis-cli shutdown LimitNOFILE=10032 NoNewPrivileges=yes Type=forking TimeoutStartSec=infinity TimeoutStopSec=infinity UMask=0077 Restart=always

[Install] WantedBy=multi-user.target

Birat
  • 1
0

On a more modern system, this worked for me instead:

Add these 3 lines to the service file /lib/systemd/system/redis-server.service under the [service] section:

RuntimeDirectory=redis
Type=forking
PIDFile=/var/run/redis/redis-server.pid

And add this to /etc/redis/redis.conf

pidfile /var/run/redis/redis-server.pid
supervised systemd
daemonize yes
aphid
  • 179
  • 1
  • 10
0

On Redis 7.2, this redis.service file works for me:

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

[Service] Type=forking ExecStart=/usr/local/bin/redis-server /etc/redis/6379.conf --supervised systemd ExecStop=/usr/local/bin/redis-cli shutdown Restart=always

[Install] WantedBy=multi-user.target

mchan
  • 1
0

One of the way to debug this is copy ExecStart line and execute on terminal you will get the error frequently. So it will give you more hints to debug and solve.

I have done the same and got exact error and got it solved.

AndreasM
  • 1,113
Viraj Wadate
  • 131
  • 4