How to stop a redis server that was started with --daemonize yes - node.js

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$

There are three options for your question from my test.
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
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
Kill the redis-server process directly:
ps -ef | grep redis-server
kill -9 (pid)

Try following command to find the redis-server instances that are running and then try killing the exact instance with kill command.
ps -aef | grep redis

Related

How can we check if our mongodb is running on EC2 linux server?

I have installed and started the MongoDB on EC2 Linux instance. How can I verify whether it is running or not?
1 way I got to know how to verify whether it is started or not is:
By checking the contents of the file at /var/log/mongodb/mongod.log for a line reading: [initandlisten] waiting for connections on port which I have not got.
What can be more ways to check?
You can check whether using a third party tool such as Mongoclient to check if you're able to connect your database. Or use one of the below methods:
Check processes that are working on:
ps -efl | grep mongo
ps -efl returns a list of processes that are being worked on your system right now, and you can use a pipe and grep to select only processes you wish, in this situation mongo.
This should return something like:
1 S sandsto+ 6997 6992 0 80 0 - 193376 - May22 ? 00:13:27 /bin/mongod --fork --bind_ip 127.0.0.1 --port 6081 --dbpath /var/mongo --logpath /var/log/mongo.log --pidfilepath /var/pid/mongo.pid --auth --nohttpinterface --noprealloc --nopreallocj --smallfiles --replSet ssrs --oplogSize 16
0 S sercan 8857 8827 0 80 0 - 85041 - May22 ? 00:20:58 mongod --storageEngine=wiredTiger
0 S sercan 29511 29471 2 80 0 - 67236 futex_ 13:41 pts/21 00:00:00 ./mongod --dbpath /home/sercan/mongo_data/
0 S sercan 29547 29529 0 80 0 - 3907 pipe_w 13:41 pts/22 00:00:00 grep --color=auto mongo
You can see there's a script ./mongod here that's working right now.
Either you can check ports that are being used by the system with command:
netstat -an | grep 27017
netstat -an returns all the allocated ports currently in the system and if you know your mongodb's port you can easily grep it from here. And this will return:
unix 2 [ ACC ] STREAM LISTENING 4184968 /tmp/mongodb-27017.sock
If you see LISTENING here, it means it's currently working.
But best way is adding mongodb to a system service manager such as supervisord, therefore you can simply check if your mongod is running with a single command:
sudo supervisorctl status
p.s. supervisor is just an example, there're a lot of process managers in linux that you can use, even mongodb documents have explanations about them.
You could check with this command
systemctl status mongod
and then you would see either of these results
1,
If it is inactive rung this command
systemctl start mongod
2,

Failed to restart redis-server.service: Unit redis-server.service not found

Tried to start redis-server but got:
26195:C 27 Aug 17:05:11.684 # Warning: no config file specified, using
the default config. In order to specify a config file use redis-server
/path/to/redis.conf
26195:M 27 Aug 17:05:11.684 * Increased maximum number of open files
to 10032 (it was originally set to 1024).
26195:M 27 Aug 17:05:11.685 # Creating Server TCP listening socket
*:6379: bind: Address already in use
Ran lsof -wni tcp:3000 and killed the local host and tried restarting redis-server again and got the same above error.
Tried: ps -aux | grep redis (output below), then sudo kill -9 6379
nick4896 12238 0.0 0.1 41432 9048 ? Sl Aug26 0:14
redis-server *:6379
nick4896 26304 0.0 0.0 21300 984 pts/21 S+ 17:08 0:00 grep
--color=auto redis
And ran sudo service redis-server restart, and got:
Failed to restart redis-server.service: Unit redis-server.service not
found.
Any ideas?
The problem is that symlink redis-server.service to redis.service was deleted.
Command
sudo systemctl enable redis-server
creates the symlink:
Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.
Came across this, I would suggest systemctl daemon-reload
Not an answer, but to complete Igor Kavzov's answer, this is the code to enter at the terminal:
sudo ln /lib/systemd/system/redis.service /etc/systemd/system/redis-server.service

Kill all process which uses specified port on Ubuntu 14.04

What's the reason the process is still alive?
List of node process running and what I tried:
root#111:/home/ubuntu# ps -e -o pid,ppid,stat,cmd | grep node
3150 1 Ss sudo /usr/bin/node /home/ubuntu/chatapp/bin/www
3152 3150 Sl /usr/bin/node /home/ubuntu/chatapp/bin/www
4407 1558 S+ grep --color=auto node
root#111:/home/ubuntu# kill -9 3150
root#111:/home/ubuntu# kill -9 3152
root#111:/home/ubuntu# ps -e -o pid,ppid,stat,cmd | grep node
4665 1 Ss sudo /usr/bin/node /home/ubuntu/chatapp/bin/www
4667 4665 Sl /usr/bin/node /home/ubuntu/chatapp/bin/www
4680 1558 S+ grep --color=auto node
Try with:
$ sudo kill -9 18200
Note the added flag '-9', which forces the murder...
From linus signal(7) man page:
...
SIGKILL 9 Term Kill signal
...
You killed process id 18200
You state node is still running, but that's process id 31261, not the one you killed...
Is the remaining process (parent pid = 1) a child proces that's been orphaned by killing 18200?

Can't stop/restart Apache2 service

Trying to stop Apache2 service, but get PID error:
#service apache2 stop
[FAIL] Stopping web server: apache2 failed!
[....] There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Plea[warnview the situation by hand. ... (warning).
Trying to kill, those processes:
#kill -9 $(ps aux | grep apache2 | awk '{print $2}')
but they get re-spawned again:
#ps aux | grep apache2
root 19279 0.0 0.0 4080 348 ? Ss 05:10 0:00 runsv apache2
root 19280 0.0 0.0 4316 648 ? S 05:10 0:00 /bin/sh /usr/sbin/apache2ctl -D FOREGROUND
root 19282 0.0 0.0 91344 5424 ? S 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
www-data 19284 0.0 0.0 380500 2812 ? Sl 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
www-data 19285 0.0 0.0 380500 2812 ? Sl 05:10 0:00 /usr/sbin/apache2 -D FOREGROUND
And though the processes are running i can't connect to the server on port 80. /var/log/apache2/error.log.1 has no new messages when i do the kill -9.
Before I tried to restart everything worked perfectly.
Running on Debian: Linux adara 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
UPD:
also tried apache2ctl:
#/usr/sbin/apache2ctl -k stop
AH00526: Syntax error on line 76 of /etc/apache2/apache2.conf:
PidFile takes one argument, A file for logging the server process ID
Action '-k stop' failed.
The Apache error log may have more information.
but there is no pid file in /var/run/apache2
I'm new to linux, looks like it has to do something with startup scripts, but can't figure out what exactly.
Below is the command to find out the process running on port 80
lsof -i tcp:80
Kill the process with PID.Restart the system once to check if their is any start up script executing and using the Port 80 which is preventing you to start your service.
For start up scripts you can check
/etc/init.d/ or /etc/rc.local or crontab - e
You can try Apache official documentation for stop/restart operations.
link

Is tftpd-hpa not a process in Linux?

I installed tftpd-hpa and tftp in Ubuntu 12.04 LTS.
when I check the status of tftpd-hpa with service command, it shows running.
zlf#ubuntu:~$ service tftpd-hpa status
tftpd-hpa start/running
But when I check its process, there is no running PID to show.
zlf#ubuntu:~$ ps -ef |grep ftp
zlf 5607 5397 0 15:02 pts/1 00:00:00 grep --color=auto ftp
zlf#ubuntu:~$ ps -ef |grep hpa
zlf 5609 5397 0 15:02 pts/1 00:00:00 grep --color=auto hpa
what happened? Is tftpd-hpa not a process or other reason?
By the way, I test tftpd-hpa by localhost, it doesn't work.
zlf#ubuntu:~$ tftp localhost
tftp> get test
Transfer timed out.
TFTP requests are probably handled by inetd/xinetd.

Resources