地址已被使用 - bind(2)表示“0.0.0.0”端口3000(Errno :: EADDRINUSE)

时间:2016-02-03 16:45:49

标签: ruby-on-rails ruby-on-rails-4 localhost puma foreman

首先,我知道this error has already been listed here,但问题不同。

我有一个Rails 4应用程序,我曾经在Puma上运行。

然后,一位矿工的朋友在应用程序上工作,并建议我们使用Foreman。

所以,我曾经在终端使用rails s在本地运行应用程序。

现在,我应该使用foreman start

问题是,几乎每次我尝试启动应用程序时,都会出现以下错误:

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

我该如何解决这个问题?

- - - -

更新:我也在下面尝试了两件事,as recommended here

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

但没有ruby bin/rails server

那:

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)

但我不确定我应该怎么做。

每次我想在本地启动应用程序时,我是否应该重新启动计算机?

4 个答案:

答案 0 :(得分:1)

如果您使用的是Puma,请运行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]

然后杀死那些小精灵。

kill -9 4395 4661 4662

答案 1 :(得分:0)

我有同样的问题。 经过小规模调查后发现ntop

  

ntop - 在网络浏览器中显示网络使用情况

  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

答案 2 :(得分:0)

This code将自动为您修复该问题

此代码将自动为您修复问题

https://github.com/pailoro/rails_server_killer

用于修复Rails服务器上“地址已在使用中”问题的ruby脚本

使用以下命令在终端上运行:

ruby​​ rails_server_killer.rb

答案 3 :(得分:-1)

只需删除tmp / pids / server.pid 文件,然后启动服务器。