6

I have a Sinatra app that I run as a daemon, using Apache port-forwarding to mediate between port 80 and port 7655. This has been working fine in the past. Today, not so well. I cannot figure out why.

Problem: sudo ruby my_process.rb returns:

/var/lib/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)

Tried: updating all system packages, updating all gems. No help (except for the more clear error message from eventmachine).

When I run sudo lsof -i :7655 I get nothing back. When I run sudo ps aux I don't see any Ruby processes at all. Which I find highly irregular, given the nature of the error message!

So is there something I'm missing in finding out why the port is unavailable?


Also:

Tried changing ports, nothing. I wonder if it is related to "localhost"? When I ping localhost I get all dropped packets. That doesn't seem normal.

mlibby
  • 6,567
  • 1
  • 32
  • 41

2 Answers2

3

Turns out these two lines in the main Sinatra script provided the most information:

set bind: "localhost"
set port: 7655

The problem was with localhost. The loopback interface was not properly configured. ifconfig showed the lo interface, but it hadn't been assigned the IP 127.0.0.1. To resolve, ran the following commands in the shell (on an Ubuntu Linux system):

ifdown lo
ifup lo
mlibby
  • 6,567
  • 1
  • 32
  • 41
  • can you provide a bit more detail about this answer. Where did you put "ifdown lo" and "ifup lo" if that's the solution. I can't figure out what to do... – BrainLikeADullPencil Dec 27 '12 at 06:11
  • @BrainLikeADullPencil: "ifdown" AND "ifup" are Linux/MacOS commands to start and stop the "loopback" ("software") network adapter. They should *not* be necessary for your [question](http://stackoverflow.com/questions/14049765/port-in-use-when-not-using-a-port). The key thing is to change the "bind" address in your Sinatra script, and see if it helps the "port in use" error you're currently getting for port#4567. – paulsm4 Dec 28 '12 at 03:51
  • @paulsm4 thanks, but i've never had to set a bind address before, and setting it now isn't working. I updated the OP with a little more information which may explain the source of the problem even if I cant' see the solution. – BrainLikeADullPencil Dec 28 '12 at 04:21
0

When you close term sometime you forget to stop [CTRL+C] the actual server, just run the following command to kill all ruby process like sinatra, and run-it again

killall ruby

You can see your actual ruby process by running

ps -ef | grep ruby
Rztprog
  • 13
  • 6