Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

debian - Cannot start redis from systemd

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?

question from:https://stackoverflow.com/questions/65906274/cannot-start-redis-from-systemd

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Alright, I realized that was due to a permission problem on redis.conf. When chown -R redis:redis /etc/redis/redis.conf the problem is gone.

Hope this can help others too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...