I am trying to set redis up to use a Unix Socket.
I am using the stock Debian installation /etc/redis/redis.conf
except with the following additions at the end of the file, based on this info:
# create a unix domain socket to listen on
unixsocket /run/project/redis.sock
# set permissions for the socket
unixsocketperm 775
#requirepass passwordtouse
# bind 127.0.0.1
daemonize yes
# maximum memory allowed for redis
maxmemory 128Mb
I am requesting it to create the unix socket in /run/project/redis.socket
:
# ll /run/project
total 4
drwxrwxrwx 2 michael www-data 100 Aug 29 16:32 .
drwxr-xr-x 21 root root 640 Aug 30 10:49 ..
I added user redis
to the group www-data
, and in desperation added redis
to group michael
.:
$ cat /etc/group | grep redis
www-data:x:33:michael,redis
michael:x:1000:www-data,redis
redis:x:119:
To me I think the permissions are fine:
$ sudo -u redis touch /run/project/foo
$ ll /run/project/foo
-rw-r--r-- 1 redis redis 0 Aug 30 11:13 /run/project/foo
However when I restart the redis server it fails:
$ systemctl restart redis-server.service
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.
$ systemctl status redis-server.service
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 Tue 2022-08-30 10:49:52 SAST; 3min 47s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 2465457 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no (code=exited, status=1/FAILURE)
Main PID: 2465457 (code=exited, status=1/FAILURE)
Status: "Redis is loading..."
CPU: 23ms
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Main process exited, code=exited, status=1/FAILURE
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 10:49:52 vps systemd[1]: Failed to start Advanced key-value store.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Aug 30 10:49:52 vps systemd[1]: Stopped Advanced key-value store.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Start request repeated too quickly.
Aug 30 10:49:52 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 10:49:52 vps systemd[1]: Failed to start Advanced key-value store.
This is the log file (apparently the warning about TimeoutStartSec / TimeoutStopSec is to be ignored, accordingly to my research.
2465442:C 30 Aug 2022 10:49:51.155 # WARNING supervised by systemd - you MUST set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit.
2465442:C 30 Aug 2022 10:49:51.158 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2465442:C 30 Aug 2022 10:49:51.158 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=2465442, just started
2465442:C 30 Aug 2022 10:49:51.158 # Configuration loaded
2465442:M 30 Aug 2022 10:49:51.158 # Opening Unix socket: bind: Read-only file system
$ journalctl -xeu redis.service
-- Journal begins at Mon 2021-08-16 08:09:33 SAST, ends at Tue 2022-08-30 10:59:15 SAST. --
-- No entries --
Using Debian. Installed redis
with sudo apt install redis
.
I tried this solution, but get this error:
$ sudo systemctl enable redis.service
Failed to enable unit: Refusing to operate on alias name or linked unit file: redis.service
UPDATE: File permission on log/config files:
$ ll /var/lib/redis/dump.rdb
-rw-rw---- 1 redis redis 93 Aug 29 14:53 /var/lib/redis/dump.rdb
$ ll /etc/redis/redis.conf
-rw-r----- 1 redis redis 86461 Aug 30 11:11 /etc/redis/redis.conf
$ ll /var/log/redis/redis-server.log
-rw-rw---- 1 redis adm 22476 Aug 30 11:22 /var/log/redis/redis-server.log
Update about stopping then reunning /usr/bin/redis-server
:
$ systemctl stop redis-server.service
$ systemctl status redis-server.service
● 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 Tue 2022-08-30 11:22:15 SAST; 1h 44min ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 2682 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no (code=exited, status=1/FAILURE)
Main PID: 2682 (code=exited, status=1/FAILURE)
Status: "Redis is loading..."
CPU: 24ms
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Main process exited, code=exited, status=1/FAILURE
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 11:22:15 vps systemd[1]: Failed to start Advanced key-value store.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Aug 30 11:22:15 vps systemd[1]: Stopped Advanced key-value store.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Start request repeated too quickly.
Aug 30 11:22:15 vps systemd[1]: redis-server.service: Failed with result 'exit-code'.
Aug 30 11:22:15 vps systemd[1]: Failed to start Advanced key-value store.
$ /usr/bin/redis-server /etc/redis/redis.conf
$
UPDATE: Tried purging and resintalling redis and it did not help. The installation is fine, if I start it with the default config ir runs:
# systemctl status redis-server.service
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-08-30 20:52:29 SAST; 44s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 26102 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 1133)
Memory: 7.4M
CPU: 90ms
CGroup: /system.slice/redis-server.service
└─26102 /usr/bin/redis-server 127.0.0.1:6379
Aug 30 20:52:29 vps systemd[1]: Starting Advanced key-value store...
Aug 30 20:52:29 vps systemd[1]: Started Advanced key-value store.
However soon as I add the following to use a unix socket, it stops working:
unixsocket /run/project/redis.sock
# set permissions for the socket
unixsocketperm 775
requirepass passwordtouse
# bind 127.0.0.1
daemonize yes
# maximum memory allowed for redis
maxmemory 128Mb