Debian – Systemd: Redis server wont start when run as a service – too many levels of symbolic links

debianredissystemd

I have recently ran into the issue from the subject. I have installed Debian 9 as a webserver (with nginx, php7.0-fpm and some other stuff) and I want to use redis with my PHP installation. When installing it from the official repos, the package installs fine, but the systemd unit fails to start or enable. When I try to run the command from "ExecStart" from the unit file by hand, redis starts fine and is operational.

Here is the unit file (provided by the Debian package, I have made no modifications):

[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)

[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/var/run/redis/redis-server.pid
TimeoutStopSec=0
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

Here is the output from journalctl -xe after running "systemctl start redis":

-- Subject: Unit redis-server.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit redis-server.service has begun starting up.
Aug 16 10:39:05 hathor systemd[9337]: redis-server.service: Failed at step NAMESPACE spawning /bin/run-parts: Too many levels of symbolic links
-- Subject: Process /bin/run-parts could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- The process /bin/run-parts could not be executed and failed.
-- 
-- The error number returned by this process is 40.
Aug 16 10:39:05 hathor systemd[9340]: redis-server.service: Failed at step NAMESPACE spawning /usr/bin/redis-server: Too many levels of symbolic links
-- Subject: Process /usr/bin/redis-server could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- The process /usr/bin/redis-server could not be executed and failed.
-- 
-- The error number returned by this process is 40.
Aug 16 10:39:05 hathor systemd[1]: redis-server.service: Control process exited, code=exited status=226
Aug 16 10:39:05 hathor systemd[1]: Failed to start Advanced key-value store.
-- Subject: Unit redis-server.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit redis-server.service has failed.
-- 
-- The result is failed.
Aug 16 10:39:05 hathor systemd[1]: redis-server.service: Unit entered failed state.
Aug 16 10:39:05 hathor systemd[1]: redis-server.service: Failed with result 'exit-code'.

And here is the error message that "systemctl enable redis" gives, wich is the most cryptic to me:

root /lib/systemd/system $ systemctl enable redis
Failed to enable unit: Refusing to operate on linked unit file redis.service

root /lib/systemd/system $ systemctl enable redis-server
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable redis-server

The unit file is not a symlink, it is a regular file:

-rw-r--r--  1 root root 1.2K Aug 16 10:32 redis-server.service

No points in /etc/, /var/run are symlinks or mountpoins. Only one mount in /mnt/backup exist on this server. I should also mention that this server is a VPS on a OpenVZ host. Systemd version is 232, Debian is fully upgraded to the newest version of packages with kernel 3.16.6-042stab123.8.

Thanks in advance for any advice!
Cheers, Johny

Best Answer

The unit file is not a symlink, it is a regular file:

-rw-r--r-- 1 root root 1.2K Aug 16 10:32 redis-server.service

You are checking the wrong file. The error message is about the redis.service. Check whether it is a symlink or not.

By the way, the package file list does not mention the redis.service file. Is it there actually? Or maybe you have created it by yourself?

In any case, when systemd refuses to perform 'enable' on a symlink, enabling the unit file by path might work:

$ sudo systemctl enable /lib/systemd/system/redis-server.service