【问题标题】:Unicorn not using rbenv version or rails -v version独角兽不使用 rbenv 版本或 rails -v 版本
【发布时间】:2017-09-22 19:45:50
【问题描述】:

刚刚通过 rbenv 将新版本的 ruby​​ 安装到我的服务器上。

rbenv versions 返回:

system
2.2.3
* 2.3.3 (set by /opt/pesto/current/config/.ruby-version)

我正在尝试重新启动我的独角兽服务 (sudo service unicorn restart):

Couldn't restart.

无奈之下,我尝试开始(sudo service unicorn start):

Could not find erubis-2.7.0 in any of the sources
Run `bundle install` to install missing gems.

我已经运行了捆绑安装。当我做rbenv local 2.3.3rbenv global 2.3.3,然后gem list,我看到了:

 'erubis (2.7.0)'

一目了然。也就是说——这颗宝石肯定是有的。

所以我看到它是否对我的其他版本做了一些奇怪的事情。我改为rbenv global 2.2.3rbenv local 2.2.3 并做了:

gem install erubis -v 2.7.0

这样做之后,现在错误是抱怨另一个不同的 gem,它也可以在我的 2.3.3 gem 列表中找到......所以我得出结论,它肯定只查看 2.2.3 gem 列表,因为将 gem 添加到 2.2.3 解决了这个问题。

只为 2.2.3 运行 bundle install 不是一个选项 - 我需要仅在我的 2.3.3 发行版中可用的依赖项。我真正想要的是 unicorn 仅参考 2.3.3 中可用的内容,而不再关注 2.2.3 以及那里可用的 gem。

这是我的 unicorn.rb:

app_path = File.expand_path(File.dirname(__FILE__) + '/..')
# Set the working application directory
# working_directory "/path/to/your/app"
working_directory app_path

before_exec do |server|
  ENV['BUNDLE_GEMFILE'] = "#{root}/Gemfile"
end


# Set the location of the unicorn pid file. This should match what we 
 put in the
# unicorn init script later.
pid (ENV['UNICORN_PID_PATH'] || "#{app_path}/tmp/") + 'unicorn.pid'

# You should define your stderr and stdout here. If you don't, stderr 
defaults
# to /dev/null and you'll lose any error logging when in daemon mode.
stderr_path(app_path + '/log/unicorn.log') unless ENV['RAILS_ENV'] == 
'development'
stdout_path(app_path + '/log/unicorn.log') unless ENV['RAILS_ENV'] == 
'development'

# Unicorn socket
listen('127.0.0.1:3000', backlog: 64, :tcp_nopush => true) if 
ENV['RAILS_ENV'] == 'development'
list en(app_path + '/tmp/unicorn.sock', backlog: 64) unless 
ENV['RAILS_ENV'] == 'development'
listen(8080, :tcp_nopush => true) unless ENV['RAILS_ENV'] == 
'development'

# Number of processes
# worker_processes 4
worker_processes (ENV['RAILS_ENV'] == 'production' ? 16 : 1)

# Time-out
timeout 300

# Load the app up before forking.
preload_app true

# Garbage collection settings.
 GC.respond_to?(:copy_on_write_friendly=) &&
  GC.copy_on_write_friendly = true

# If using ActiveRecord, disconnect (from the database) before 
forking.
before_fork do |server, worker|
   defined?(ActiveRecord::Base) &&
     ActiveRecord::Base.connection.disconnect!
end

# After forking, restore your ActiveRecord connection.
after_fork do |server, worker|
  defined?(ActiveRecord::Base) &&
    ActiveRecord::Base.establish_connection
end

我没有看到它所指的 ruby​​ 版本在此配置文件中引用的位置。因此,我在弄清楚如何让独角兽使用我的新红宝石方面有点矛盾。

【问题讨论】:

    标签: ruby-on-rails ruby bundler unicorn


    【解决方案1】:

    unicorn 使用的 rails 版本可以在 /etc/init.d/unicorn 中进行编辑。我改变了它,它起作用了。

    【讨论】:

      猜你喜欢
      • 2014-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 2012-02-11
      • 2012-06-12
      相关资源
      最近更新 更多