Rails 服务器在启动时立即退出

Posted

技术标签:

【中文标题】Rails 服务器在启动时立即退出【英文标题】:Rails server quits right when it starts 【发布时间】:2017-03-12 08:59:18 【问题描述】:

我遇到这个问题有一段时间了,但没有找到解决办法。我正在 Rails 中构建一个论坛应用程序。我刚刚将引导程序和引导程序 gem 添加到我的项目中。我去运行服务器,它以一个巨大的错误退出。这里是。 Julies-MacBook-Air:railsnew juliechopourian$ rails server => Booting Puma => Rails 5.0.0.1 application starting in development on http://localhost:3000 => Runrails server -hfor more startup options Puma starting in single mode... * Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://localhost:3000 Exiting /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:266:ininitialize':地址已在使用中 - bind(2) for "::1" 端口 3000 (Errno::EADDRINUSE) 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:266:in new' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:266:inadd_tcp_listener' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:260:in block in add_tcp_listener' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:259:ineach' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:259:in add_tcp_listener' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:102:inblock 解析' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:85:in each' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:85:inparse' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/runner.rb:133:in load_and_bind' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/single.rb:85:inrun' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/launcher.rb:172:in run' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/rack/handler/puma.rb:51:inrun' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/server.rb:296:in start' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/server.rb:79:instart' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:90:in block in server' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:intap ' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in server' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:inrun_command ! 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in <top (required)>' from /Users/juliechopourian/treehouse/rails_app/railsnew/bin/rails:9:inrequire' 来自 /Users/juliechopourian/treehouse/rails_app/railsnew/bin/rails:9:in <top (required)>' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client/rails.rb:28:inload' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in call' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client/command.rb:7:incall ' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client.rb:30:in run' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/bin/spring:49:in' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in load' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in' 来自 /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from /Users/juliechopourian/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' 来自 /Users/juliechopourian/treehouse/rails_app/railsnew/bin/spring:13:in <top (required)>' from bin/rails:3:inload' 来自 bin/rails:3:in <main>' Julies-MacBook-Air:railsnew juliechopourian$

我认为这可能与美洲狮宝石有关,但我真的不知道。任何帮助将不胜感激。如果我需要发布更多我的项目,请告诉我。

【问题讨论】:

EADDRINUSE 有时您可能会忘记终止最后一个终端会话,反查或在浏览器中关注 localhost:3000 看看会发生什么 【参考方案1】:

导轨 5

ps辅助| grep 3000

如果 Rails 应用程序仍在运行

用户 3454 0.6 5.6 1708124 220676 pts/5 Sl+ 20:18 0:20 puma 3.6.0 (tcp://localhost:3000)

杀死 -9 3454

rails s -p 3001

【讨论】:

我跑了 ps aux | grep 3000 在终端中。我得到了这个... 59714 99.5 0.1 2668560 2812 ?? R Fri11AM 55:21.24 puma 3.6.0 (tcp://localhost:3000) [railsnew] ------ 62810 0.0 0.0 2442020 872 s000 S+ 1:09PM 0:00.00 grep 3000 杀死 59714 或重启电脑 ;) digitalocean.com/community/tutorials/… 对不起杀死-9 59714【参考方案2】:

观看此Address already in use - bind(2) for "::1" port 3000 (Errno::EADDRINUSE)

端口 3000 上已经有东西在监听。请确保您没有其他 ruby​​ 进程监听该端口。类似的东西

ps aux | grep ruby

【讨论】:

以上是关于Rails 服务器在启动时立即退出的主要内容,如果未能解决你的问题,请参考以下文章

Rails:每次使用控制台更改代码时重新启动服务器

ignite客户端找不到服务端的时候如何设置退出

在 ruby​​ on rails 中启动服务器时出错

Windows 服务(托管 WCF 服务)在启动时立即停止

GDBSERVER 在启动时退出

Python中的Gstreamer立即退出,但在命令行上很好