On a Debian 10 machine, I can start redis-server by just typing redis-server
. However I’d like to run it as a daemon.
I can see in /etc/systemd/system
that it is symlinked like this:
lrwxrwxrwx 1 root root 40 Sep 12 2019 redis.service -> /lib/systemd/system/redis-server.service
and in /lib/systemd/system/redis-server.service
I have:
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)
[Service]
#Type=forking
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/var/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
ExecStartPre=-/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d
ExecStartPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-up.d
ExecStop=-/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d
ExecStop=/bin/kill -s TERM $MAINPID
ExecStopPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-down.d
UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWriteDirectories=-/var/lib/redis
ReadWriteDirectories=-/var/log/redis
ReadWriteDirectories=-/var/run/redis
CapabilityBoundingSet=~CAP_SYS_PTRACE
# redis-server writes its own config file when in cluster mode so we allow
# writing there (NB. ProtectSystem=true over ProtectSystem=full)
ProtectSystem=true
ReadWriteDirectories=-/etc/redis
[Install]
WantedBy=multi-user.target
Alias=redis.service
However when I kill redis-server
which is running fine from terminal and try to start the service using systemctl start redis
I get this error:
● 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 2021-01-26 11:03:50 CST; 10s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 29998 ExecStopPost=/bin/run-parts --verbose /etc/redis/redis-server.post-down.d (code=exited, status=0/SUCCESS)
Process: 29995 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=1/FAILURE)
Process: 29992 ExecStop=/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d (code=exited, status=0/SUCCESS)
Process: 29989 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=1/FAILURE)
Process: 29986 ExecStartPre=/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d (code=exited, status=0/SUCCESS)
Main PID: 29989 (code=exited, status=1/FAILURE)
CPU: 22ms
Jan 26 11:03:49 front systemd[1]: redis-server.service: Unit entered failed state.
Jan 26 11:03:49 front systemd[1]: redis-server.service: Failed with result 'exit-code'.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Service hold-off time over, scheduling restart.
Jan 26 11:03:50 front systemd[1]: Stopped Advanced key-value store.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Start request repeated too quickly.
Jan 26 11:03:50 front systemd[1]: Failed to start Advanced key-value store.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Unit entered failed state.
Jan 26 11:03:50 front systemd[1]: redis-server.service: Failed with result 'exit-code'.
What could be wrong here and how can I fix this?
2
Answers
Alright, I realized that was due to a permission problem on
redis.conf
. Whenchown -R redis:redis /etc/redis/redis.conf
the problem is gone.Hope this can help others too.
I had to change redis user and group to
root
, at the service to make it work it was set toredis
and wasn’t working