Can't initialize Redis as a systemd service (supervised systemd) on Ubuntu Server 20.04.2
On Ubuntu Server 20.04, Redis (5.0.7) doesn't start after setting supervised systemd
on /etc/redis/redis.conf
, but no error is printed when running it manually with /usr/bin/redis-server /etc/redis/redis.conf
.
Also, when running manually, its possible to find it listening on port 6379 with netstat -tulpn
.
To reproduce
As root:
- Update packages and install Redis with
apt update && apt install redis-server
- On
/etc/redis/redis.conf
, change the line withsupervised no
tosupervised systemd
- Try to restart Redis with
service redis-server restart
orsystemctl restart redis
The output of the above command is:
Job for redis-server.service failed because the control process exited with error code.
See "systemctl status redis-server.service" and "journalctl -xe" for details.
And the output of systemctl status redis-server.service
is:
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-02-03 12:15:56 -03; 28s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 3851 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=1/FAILURE)
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Feb 03 12:15:56 mywebsite.com systemd[1]: Stopped Advanced key-value store.
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Start request repeated too quickly.
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Failed with result 'exit-code'.
Feb 03 12:15:56 mywebsite.com systemd[1]: Failed to start Advanced key-value store.
No log is printed on /var/log/redis/redis-server.log
when trying to restart Redis service, but the text below is printed when running it manually:
4231:C 03 Feb 2021 12:27:52.053 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4231:C 03 Feb 2021 12:27:52.053 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=4231, just started
4231:C 03 Feb 2021 12:27:52.053 # Configuration loaded
4232:M 03 Feb 2021 12:27:52.063 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 4232
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
4232:M 03 Feb 2021 12:27:52.065 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4232:M 03 Feb 2021 12:27:52.065 # Server initialized
4232:M 03 Feb 2021 12:27:52.066 * Ready to accept connections
Software versions:
Redis server v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=636cde3b5c7a3923
Ubuntu 20.04.2 LTS - 64 bit
systemd 245 (245.4-4ubuntu3.4)
Solution 1:
It's pretty strange, but Ubuntu's installation of redis-server does not use redis's ability to communicate with systemd. On this platform you should leave redis.conf set as it shipped: supervised no
.
If you really want to enable this for some reason, you will have to customize the systemd unit, for example:
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl edit redis-server.service
In nano, you should add only this:
[Service]
Type=notify
Then tell systemd to load the changes.
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl daemon-reload
Now you need to edit redis.conf:
ubuntu@vmtest-ubuntu2004:~$ sudo nano /etc/redis/redis.conf
And make these changes:
daemonize no
supervised systemd
Now you can restart redis-server:
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl start redis-server
ubuntu@vmtest-ubuntu2004:~$ sudo systemctl status redis-server
* redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/redis-server.service.d
`-override.conf
Active: active (running) since Wed 2021-02-03 11:55:09 EST; 1min 8s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 1768 (redis-server)
Tasks: 4 (limit: 2318)
Memory: 1.8M
CGroup: /system.slice/redis-server.service
`-1768 /usr/bin/redis-server 127.0.0.1:6379
Feb 03 11:55:09 vmtest-ubuntu2004 systemd[1]: Starting Advanced key-value store...
Feb 03 11:55:09 vmtest-ubuntu2004 systemd[1]: Started Advanced key-value store.