3

First of all, I know this error has already been listed here, but the question was different.

I have a Rails 4 app, that I used to run on Puma.

Then, a friend of mines worked on the app, and recommended that we use Foreman instead.

So, I used to run the app locally with rails s in Terminal.

Now, I am supposed to do it with foreman start.

The problem is, almost every time I try to launch the app, I get the following error:

foreman start
08:42:28 web.1  | started with pid 3398
08:42:28 web.1  | [3398] Puma starting in cluster mode...
08:42:28 web.1  | [3398] * Version 2.13.4 (ruby 2.2.1-p85), codename: A Midsummer Code's Dream
08:42:28 web.1  | [3398] * Min threads: 5, max threads: 5
08:42:28 web.1  | [3398] * Environment: development
08:42:28 web.1  | [3398] * Process workers: 2
08:42:28 web.1  | [3398] * Preloading application
08:42:31 web.1  | [3398] * Listening on tcp://0.0.0.0:3000
08:42:31 web.1  | /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:231:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:231:in `new'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:231:in `add_tcp_listener'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:98:in `block in parse'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:84:in `each'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:84:in `parse'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/runner.rb:119:in `load_and_bind'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/cluster.rb:304:in `run'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/cli.rb:215:in `run'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/bin/puma:10:in `<top (required)>'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/puma:23:in `load'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/puma:23:in `<main>'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
08:42:31 web.1  | exited with code 1
08:42:31 system | sending SIGTERM to all processes

How can I fix this?

—————

UPDATE: I also tried both things below, as recommended here:

ps aux | grep rails
3547   0,0  0,0  2434840    752 s000  S+    8:48     0:00.00 grep rails

But there is no ruby bin/rails server

and that:

lsof -wni tcp:3000
COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    808  TXC    8u  IPv4 0x4f6da234a6116dab      0t0  TCP *:hbci (LISTEN)
ruby    809  TXC    8u  IPv4 0x4f6da234a6116dab      0t0  TCP *:hbci (LISTEN)
ruby    810  TXC    8u  IPv4 0x4f6da234a6116dab      0t0  TCP *:hbci (LISTEN)

but I am not sure of what I am supposed to do with this.

Am I supposed to restart my computer every time I want to launch the app locally?

Community
  • 1
  • 1
Thibaud Clement
  • 5,371
  • 6
  • 42
  • 89

4 Answers4

5

If you are using Puma, run ps aux | grep puma

PID   TT  STAT      TIME COMMAND
4662   0.0  0.1  4601556   8820   ??  S    10:48am   1:10.37 puma: cluster worker 1: 4395 [my-app]
4661   0.0  0.1  4882676  10300   ??  S    10:48am   2:14.49 puma: cluster worker 0: 4395 [my-app]
4395   ??  S      0:16.88 puma 3.12.1 (tcp://0.0.0.0:3000) [my-app]

Then kill those pids.

kill -9 4395 4661 4662

Hari Honor
  • 8,520
  • 6
  • 45
  • 50
  • 1
    Or even quicker `pkill -9 -f puma` (`-f` matches against the full entry rather than just the process name. might not be needed) – Hari Honor Mar 15 '21 at 16:06
0

I have the same issue. After small investigation was found ntop

ntop - display network usage in web browser

  1. netstat -tulpn

    tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN -

  2. nmap 127.0.0.1

    3000/tcp open ppp

0

This code will automate the process of fixing it for you

This code will automate the process of fixing it for you

https://github.com/pailoro/rails_server_killer

a ruby script to fix the problem "Address already in use" on a rails server

run it on terminal with:

ruby rails_server_killer.rb

-1

Just remove tmp/pids/server.pid file and then launch your server.

Snm Maurya
  • 923
  • 8
  • 11