How to Kill Vapor Server - ios

I'm trying to build a very simple service using Vapor. It depends on websockets, and I establish a connection between an iOS device in simulator and vapor running on localhost.
When I want to make changes to the server, I restart and sometimes get [ ERROR ] bind(descriptor:ptr:bytes:): Address already in use (errno: 48)
I don't know how to find and kill this process, which is a socket running on 8080. I have to restart to get out of it, and I feel like throwing the computer out the window after a few repetitions (question about that already asked in mentalHealthOverflow.com).
How can I find and kill this process? Stopping the simulator device doesn't do it.

The fix is actually pretty easy. Go to your terminal and run lsof -i :<port>, so in your case, lsof -i :8080. You will get an output of all the processes that are running on that port.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Run 48904 calebkleveter 31u IPv4 0x97c38af35a1b4785 0t0 TCP localhost:Run (LISTEN)
You can then run the kill command, passing in the PID from the output you got:
kill 48904
You can now run your Vapor service.

Oneliner that I use:
lsof -i :8080 -sTCP:LISTEN | awk 'NR > 1 {print $2}' | xargs kill -15
Which basically just sends PID of the Vapor process (running on the port 8080) to the kill command as argument

Related

rails: port is in use or requires root privileges

I am getting this error when attempting to start up a rails 4.1.1 server:
Listening on 0.0.0.0:3000, CTRL+C to stop
Exiting
/Users/darrenburgess/.rvm/gems/ruby-2.1.2#myflix/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
I have tried the following commands to find and kill the process, however none of them reveal any servers running on 3000
ps ax | grep rails
ps ax | grep ruby
lsof -i TCP | grep LISTEN
lsof -i :3000
These, from my research on stack overflow, seem to be all of the available methods for discovering running ports.
In a rails 5 application I am getting the following similar error:
Listening on tcp://0.0.0.0:3000
Exiting
/Users/darrenburgess/.rvm/gems/ruby-2.3.1/gems/puma-3.7.0/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
Note that I can start rails servers on other ports.
This error persists even after machine reboot. Seems I have exhausted all avenues for finding and killing ports in use. What other things can I try?
UPDATE:
#hjpotter92 suggests running:
netstat -lntp | grep 3000
This however does not work as an option is required for the p argument. According to man netstat the list of protocols is found in etc/protocols.
I looked in that file and found that tcp is a listed protocol. However, this command does not return any output:
netstat -lntp tcp | grep 3000
Nor does this command return anything either:
netstat -lnt | grep 3000
You can try scanning the port like this lsof -i :3000 and then kill the process using sudo kill -9 <PID>.
Well, it turns out the answer to this is fairly obscure. The Node instance of FileMaker server 16 is running on port 3000. I was running a FileMaker server on the my Rails development machine.
This command helped to discover that:
sudo lsof -P -i :3000
Result
node 562 fmserver 20u IPv6 0x3ef1908b38776fe5 0t0 TCP *:3000 (LISTEN)
I could kill that process, however elected instead to disable the Node instance (The FileMaker REST/Data API).
Documentation here shows that FileMaker 16 is using that port.
http://help.filemaker.com/app/answers/detail/a_id/16319

Address already in use - bind(2) when starting server in Cloud9 IDE

When starting the server in Cloud9, rails s -p $PORT -b $IP, I get an error and the server fails to start.
Address already in use - bind(2)
Following this post, Rails server says port already used, how to kill that process?,
I ran lsof -wni tcp:8080 (8080 because of cloud9)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 18415 ubuntu 9u IPv4 698526934 0t0 TCP *:http-alt (LISTEN)
Then,
kill -18415 PID
But this results in an error,
bash: kill: 18415: invalid signal specification
Can anyone advise how to fix this error on Cloud9?
You're killing it with the wrong way.
You need to use:
kill -9 18415
9 - signal 'kill'
18415 - process id
Also you can kill all ruby processes like this:
killall -9 ruby
But use it only when you know what you're doing.

MQTT-over-Websockets Error: listen EADDRINUSE

Following this doc
https://github.com/mcollina/mosca/wiki/MQTT-over-Websockets
I set up the broker in my localhost like
var settings = {
http: {
port: 1884,
bundle: true,
static: './'
}
};
//here we start mosca
var server = new mosca.Server(settings);
but when I run
node broker
I've got this ugly error
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1146:14)
at listen (net.js:1172:10)
at net.js:1270:9
at dns.js:85:18
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
to check if I've got other process
ps -ax | grep node
5266 pts/2 R+ 0:00 grep --colour=auto node
kill -9 5266
bash: kill: (5266) - No such process
Do you what's the problem ?
UPDATE
Thanks to #hardillb and #ralight
I worked it out with
sudo lsof -i TCP:1883
if there is mosquitto simple
run
sudo service mosquitto stop
This shows the current sockets that are listening on your machine:
sudo netstat -ltn
You would expect to see something like the below if something is listening.
tcp 0 0 0.0.0.0:1884 0.0.0.0:* LISTEN
If LISTEN is replaced with TIME_WAIT, then it is possible there is a bug in mosca which doesn't allow it to reuse a listening socket that hasn't timed out. I think that is unlikely though.
To find the process using the port, you can use lsof:
sudo lsof -i TCP:1884
This will give an output something like the example below that I got by running sudo lsof -i TCP:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 3878 root 3u IPv4 4505 0t0 TCP *:ssh (LISTEN)
It might not be a node process that is holding the socket
Try running sudo lsof -i :1884 to see what process it might me.
Also have you tried changing the port number to something other than 1884 to see if it works.

process won't die after being killed with `kill` command

I'm trying to run rails server to start a local server but got this error
...
WARN TCPServer Error: Address already in use - bind(2)
Exiting
...
So I went and looked for the process that was occupying the port and killed it.
The server still wouldn't start.
And as it turned out, lsof still showed the process (even after it had been killed):
$ lsof -P | grep ':3000'
ruby 52944 user 7u IPv4 0xffffff800bdafbd8 0t0 TCP *:3000 (LISTEN)
$ kill 52944 <<<<<<< pid 52944 should have died here!
$ lsof -P | grep ':3000'
ruby 52944 user 7u IPv4 0xffffff800bdafbd8 0t0 TCP *:3000 (LISTEN)
Any idea how to really kill the process?
(This is on OSX)
Use
kill -9 <id>
to kill stubborn processes :-)

Rails server command problem

I have a macbook pro os 10.6.6. When running rails server and load http://0.0.0.0:3000 the page tries to load for awhile then gives a "connection has timed out error". Has anyone had this problem before?
Thanks!
You're probably hitting another computer in your local network. See ↓.
Try http://localhost:3000/.
You can also try your actual IP address which you'll find in System Preferences > Network.
Make sure webrick is running. You should see a ruby process when you execute the following command.
ps aux | grep rails
Make sure webrick is listening on your localhost.
sudo lsof -i -P | grep -i "listen"
You should see something like
ruby 5710 username 7u IPv4 0x12d3b680 0t0 TCP *:3000 (LISTEN)
as the output. If you don't see it webrick is not running.
You can try running a different web server ie: ./script/server webrick instead of the default mongrel

Resources