Skip to content

Instantly share code, notes, and snippets.

@mkocikowski
Last active January 22, 2024 05:35
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • 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:

@bzkdjc
Copy link

bzkdjc commented Jan 7, 2023

@mkocikowski,

As @jee1mr said, there is a typo. The setting in redis.conf is:

By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. daemonize no

and not:

demonize no

Find here (at Step 3) a somehow detailled way to achieve this task.

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