Port that is not used when using the port

I try to start the next Sinatra application and get an error message telling me that I cannot start the server because the port is already in use or because I do not have root privileges. I never had this problem before starting the Sinatra app. A few days ago I upgraded to Mountain Lion for my mac and wonder if this could be causing the problem. I also use RVM. Can anyone suggest an offer ...

require "sinatra" class MyApp < Sinatra::Base get '/' do "Hello from MyApp" end end == Sinatra/1.3.3 has taken the stage on 4567 for development with backup from Thin >> Thin web server (v1.5.0 codename Knife) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:4567, CTRL+C to stop /Users/me/.rvm/gems/ ruby-1.9.2-p290@global /gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) 

Update: I can still run the rails server on my machine, so I think the problem is with Sinatra. In addition, I was able to run Sinatra applications that were discontinued a few days ago when I started playing with this Rack Tutorial , which I was tasked with explicitly setting up the port. I am wondering if this has changed.

 >> Rack::Handler::WEBrick.run my_rack_proc, :Port => 9876 [2011-10-24 11:32:21] INFO WEBrick 1.3.1 [2011-10-24 11:32:21] INFO ruby 1.9.2 (2011-07-09) [i386-mingw32] [2011-10-24 11:32:21] INFO WEBrick::HTTPServer#start: pid=480 port=9876 
+6
source share
2 answers

Note: I used to have a different answer. I replaced it with a new, more focused answer, but I left the old answer below for those who are still looking for it.

New answer:

This error is caused by the fact that the last time you had a server, you closed the terminal without killing the server. I think this is called "headless running," like a chicken with a head chopped off. Therefore, even if no one is watching them, the server is still running and occupying the “space” called port 9393. When you try to start a new server, there is already one start. It looks like a parking space: since there is already a car there, you cannot part with a new one in the same place.

This is how I reproduced the error. I loaded the Sinatra server, closed the terminal without killing the server, opened a new terminal and tried to load another server.

Taras-MacBook-Air:SurveyDBCGroupProject tlroys$ shotgun == Shotgun/Thin on http://127.0.0.1:9393/ Thin web server (v1.6.1 codename Death Proof) Maximum connections set to 1024 Listening on 127.0.0.1:9393, CTRL+C to stop /Users/tlroys/.rvm/gems/ruby-1.9.3-p484/gems/eventmachine-1.0.3/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) #deleted stack trace

What will you do if the car is parked in your place? You can call the tow truck and inform the driver of the license plate number of the car and ask them to remove it.

To find out the license plate number of a car, run the following set of commands that I found in the stack overflow

ps aux | grep ruby

This finds the process identifier as well as the license plate number of the "car" occupying the "parking space". Note: the server occupying my "place" is actually a server written using the ruby ​​programming language: sort of like some Chevorlets cars. I can tell the person who recognized the license plate number to look at the chevrolet and he will find a suitable car while there are no other cars around. Since this "zombie server" is the only ruby ​​process running on my computer, telling grep to find the ruby ​​will give you the correct ID / license number. If I wanted to be more specific, I could say

ps aux | grep shotgun

and get the same result.

- The result should look like this: there should be two things in the list.

27235 ?? S 0:00.72 /Users/tlroys/.rvm/gems/ruby-1.9.3-p484/bin/shotgun 27393 s000 S+ 0:00.00 grep ruby

The first is the real “zombie server” you are looking for. Secondly, it is funny because you are looking for all processes that contain the word ruby, and therefore it finds a process that searches for all processes containing the word ruby. Haha

Kill the first process. using the following command. Be sure to change the numbers to the actual process ID:

kill -9 27235

You will need to change 27235 to the actual process id that you see, but you get this idea. A tow truck came running, pulled the car to a landfill and left free space for me.

Old answer:

I had exactly the same problem, and as far as I can tell, this is because the ruby ​​process was launched on the port, on which I launched the Sinatra applications. Below is the error (with deleting the stack trace for brevity) and the commands that I ran to find out what was going wrong and fix it.

In short, I tried to run the Sinatra application, and he said that the port is in use or requires root privileges. Then I used the lonf Tin Man command (see above) to find out which ports are in use.

This showed that ruby ​​works on port 9393. I killed it with killall. I again tried to run the Sinatra application. It worked.

 Taras-MacBook-Air:sinatra_sandbox tlroys$ bundle exec shotgun config.ru The source :rubygems is deprecated because HTTP requests are insecure. Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not. == Shotgun/Thin on http://127.0.0.1:9393/ >> Thin web server (v1.5.0 codename Knife) >> Maximum connections set to 1024 >> Listening on 127.0.0.1:9393, CTRL+C to stop /Users/tlroys/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) Taras-MacBook-Air:sinatra_sandbox tlroys$ lsof -i TCP | grep LISTEN ruby 59176 tlroys 9u IPv4 0xffffff8012fbdc00 0t0 TCP localhost:9393 (LISTEN) Taras-MacBook-Air:sinatra_sandbox tlroys$ killall ruby Taras-MacBook-Air:sinatra_sandbox tlroys$ bundle exec shotgun config.ru The source :rubygems is deprecated because HTTP requests are insecure. Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not. Shotgun/Thin on http://127.0.0.1:9393/ Thin web server (v1.5.0 codename Knife) Maximum connections set to 1024 Listening on 127.0.0.1:9393, CTRL+C to stop 
+13
source

The limitation that only root has the ability to open "well-known port # s" has nothing to do with Ruby - this is the OS. It is also, in general, a good thing.

Look at " cannot start the sinatra process - eventmachine 'no acceptor' ".

There are two sentences in the link:

  • The configuration problem that he encountered may well fix your problem.
  • If nothing else, the link also shows you how to change port # (to some other - and possibly higher) number.
+1
source

Source: https://habr.com/ru/post/926614/


All Articles