【问题标题】:Rails on development mode without Puma没有 Puma 的 Rails 开发模式
【发布时间】:2016-08-13 23:24:46
【问题描述】:

在我为生产模式安装 Puma 之后,它不应该在我的本地机器上运行,但是 Puma 正在开发模式下启动并在没有错误的情况下停止。

$ rails server
=> Booting Puma
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[8707] Puma starting in cluster mode...
[8707] * Version 3.1.0 (ruby 2.3.0-p0), codename: El Niño Winter Wonderland
[8707] * Min threads: 1, max threads: 6
[8707] * Environment: development
[8707] * Process workers: 1
[8707] * Phased restart available
[8707] * Listening on tcp://localhost:3000
[8707] Use Ctrl-C to stop

看起来是捆绑程序问题: github.com/puma/puma/issues/983

【问题讨论】:

  • 尝试在您的 gemfile #gem 'puma', '~> 3.4' 中禁用 puma gem,看看是否有任何改变。
  • 谢谢mrvncaragay!仅当我从生产中删除 puma 时才有效,但我确实需要在生产模式下使用 puma
  • 轻松修复。在生产模式下取消注释。开发模式下的评论:)

标签: ruby-on-rails bundle puma


【解决方案1】:

这不是一个真正的解决方案,但对于那些将服务器用于 Puma 的生产模式并希望使用 WEBrick 在本地机器开发模式下工作的人来说,这是一个很好的解决方案。这个解决方案基于 mrvncaragay 的想法

1。 将Gemfile 拆分为 3 个文件:

Gemfile_base
Gemfile_development
Gemfile_production

在 Gemfile_base 中包括所有未测试、开发和生产的 gems。没有理由包含 source 'https://rubygems.org' 或 Gemfile_development 或 Gemfile_production 文件。 在 Gemfile_development 中只包括测试和开发gems 在 Gemfile_production 中只包含生产 gems

2。 将Gemfile中的所有行替换为:

source 'https://rubygems.org'

gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
#gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
gemfiles.each do |gemfile|
  instance_eval File.read(gemfile)
end

3。 部署到生产服务器

4。 将 Gemfile 添加到 .gitignore 文件中

#bundle Puma in development mode bad wordaround
Gemfile

5。 从源代码管理中取消跟踪 Gemfile

git rm --cached Gemfile

6。 将生产服务器中 Gemfile 的提交行更改为:

source 'https://rubygems.org'

gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
#gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
gemfiles.each do |gemfile|
  instance_eval File.read(gemfile)
end

到:

source 'https://rubygems.org'

#gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
gemfiles.each do |gemfile|
  instance_eval File.read(gemfile)
end

【讨论】:

  • 你为什么要这样做而不是使用捆绑器的组功能?
  • @FrederickCheung 因为group 在生产模式下根本无法与puma 一起工作(Check this)。无论如何,这不是我可以在我的系统中实施的解决方案,而是试图以某种方式重新发明轮子。在更好的选择(或错误修复)到来之前,我将继续在开发中使用 puma。
猜你喜欢
  • 2018-01-22
  • 1970-01-01
  • 2013-04-18
  • 2017-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-08
  • 2014-07-14
相关资源
最近更新 更多