21

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?

6 Answers 6

22

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.

4
  • This worked for me. Mar 25, 2019 at 11:59
  • 1
    At least for the new redis 7.0, this answer is no longer valid. Redis will stop and start 5 times in quick succession, then end up stopped. When the forking/pidfile older style method is used, starting Redis will hang for 90 seconds (by default), after which it will not start.
    – aphid
    Apr 6, 2023 at 12:00
  • @aphid exactly, yes it is doing that! did you find a fix?
    – Timmerz
    Sep 19, 2023 at 2:19
  • @Timmerz comment out TimeoutStartSec=infinity, or changeinfinity to 30 (or other value) so TimeoutStartSec=30
    – Roko
    Mar 31 at 18:40
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.

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.

3
  • 1
    The journal output already gives hints on what the problem may be: " NOTIFY_SOCKET not found" Do you have further info on this Redis problem?
    – AndreasM
    Mar 25, 2019 at 13:10
  • 1
    Yes journalctl -u service-name also gives output. Mar 25, 2019 at 13:29
  • journalctl -u redis gave info about the error in my case *** FATAL CONFIG FILE ERROR *** Reading the configuration file, at line 147 >>> 'supervised systemd #signal systemd' Bad directive or wrong number of arguments which was to remove the commented out part after systemd Apr 1, 2019 at 14:07
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
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
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
1
  • It is a partial answer and also an example. I think it can remain.
    – peterh
    Dec 29, 2023 at 0:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .