Thursday, March 17, 2022

[SOLVED] How to stop a redis server that was started with --daemonize yes

Issue

I'm trying to kill a redis server that was started with --daemonize yes

I feel like this should be easy, but I am unable to successfully kill it based on standard methods. I'm using Redis 3.2 installed via these instructions: https://www.hugeserver.com/kb/install-redis-debian-ubuntu/

$ redis-server --daemonize yes 
1550:C 13 Mar 05:54:55.436 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1550:C 13 Mar 05:54:55.437 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1550, just started
1550:C 13 Mar 05:54:55.437 # Configuration loaded
$ kill 1550
-bash: kill: (1550) - No such process
$ kill -9 1550
-bash: kill: (1550) - No such process
$ killall redis-server
redis-server(1181): Operation not permitted
redis-server: no process found
$ /etc/init.d/redis-server stop
[....] Stopping redis-server (via systemctl): redis-server.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'redis-server.service'.
Authenticating as: Ubuntu (ubuntu)
Password: 

Why should I need to enter a password to stop it? I never set a password when i started it. And why doesn't kill work? Even if I sudo it, it just restarts again after.

-------------------EDIT-------------------

Additional information. Using the kill command on the process ID doesn't work. I have to use sudo kill but then it comes back with another processid as if something restarts it. I just killed it 3 times and it's back again with a 4th processid –

---------- Solution thanks to @Kevin Law ----------

I needed to kill the daemonized service and then kill the process. Not just one or the other...

ubuntu@ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu    2381     1  0 18:39 ?        00:00:00 redis-server *:6379
ubuntu    2386  1358  0 18:39 pts/0    00:00:00 grep --color=auto redis-server
ubuntu@ip-MyIPAddress:~/Relayer$ sudo service redis-server stop
ubuntu@ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu    2381     1  0 18:39 ?        00:00:00 redis-server *:6379
ubuntu    2418  1358  0 18:39 pts/0    00:00:00 grep --color=auto redis-server
ubuntu@ip-MyIPAddress:~/Relayer$ kill 2381
ubuntu@ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu    2420  1358  0 18:39 pts/0    00:00:00 grep --color=auto redis-server
ubuntu@ip-MyIPAddress:~/Relayer$ 

Solution

There are three options for your question from my test.

  1. Stop redis by stoping redis service. This is the recommend way in most cases.
sudo systemctl stop redis-server

or

sudo service redis-server stop
  1. connect to this redis-server and shutdown it by redis-cli.
redis-cli

after connected to redis, issue shutdown to turn off redis-server

shutdown
  1. Kill the redis-server process directly:
ps -ef | grep redis-server
kill -9 (pid)


Answered By - Kevin Law
Answer Checked By - Terry (WPSolving Volunteer)