Skip to content

Instantly share code, notes, and snippets.

@mkocikowski
Last active June 27, 2025 06:58
Show Gist options
  • Save mkocikowski/aeca878d58d313e902bb to your computer and use it in GitHub Desktop.
Save mkocikowski/aeca878d58d313e902bb to your computer and use it in GitHub Desktop.
Setting up Redis to run as a daemon under systemd

This can be used to daemonize anything that would normally run in the foreground; I picked Redis. Put this in /etc/systemd/system/redis.service:

[Unit]
Description=Redis
After=syslog.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
RestartSec=5s
Restart=on-success

[Install]
WantedBy=multi-user.target

Make sure that redis.conf has demonize no (the default; systemd will take care of 'daemonizing'). The Restart=on-success in the service file means that the daemon will be auto-restarted only when it exited cleanly (so that 'bad' problems are not masked; see doc). Then run:

sudo systemctl enable /etc/systemd/system/redis.service
sudo systemctl start redis.service

Links:

@kleajmp
Copy link

kleajmp commented Jun 17, 2024

I was so glad I found this "redis.service" script as the official documentation is still giving instructions to start redis with "init.d"
But after I kept on getting errors when I started the service (status=203/EXEC).
When I started redis-server manually with the command it worked...

Now the problem was the given path in the startup command in the script above:

  • In my case it was NOT: ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
  • But the correct path is: ExecStart=/usr/sbin/redis-server /etc/redis/redis.conf

@richtier
Copy link

richtier commented Oct 5, 2024

note redis version 7 is shipped with redis-server.service, which is enabled during install

@randolf
Copy link

randolf commented Jun 27, 2025

note redis version 7 is shipped with redis-server.service, which is enabled during install

Unfortunately, Redis version 8's redis-server.service file doesn't work under Debian 12 (or Debian 13):

systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
systemd[1]: redis-server.service: Start request repeated too quickly.
systemd[1]: redis-server.service: Failed with result 'exit-code'.
systemd[1]: Failed to start redis-server.service - Advanced key-value store.

Starting Redis manually at the command line with redis-server works, but this isn't helpful for automation since the same command in redis-server.service also still fails with the same errors as noted immediately above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment