独角兽不使用 rbenv 版本或 rails -v 版本

Unicorn not using rbenv version or rails -v version

刚刚通过 rbenv 在我的服务器上安装了新版本的 ruby。

rbenv versions returns:

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.3 以及 rbenv global 2.3.3,然后 gem list,我看到:

 'erubis (2.7.0)'

一目了然。也就是说——这个gem肯定是有的

所以我看看它是否对我的其他版本做了一些奇怪的事情。我改为 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 的捆绑安装不是一个选项 - 我需要仅在我的 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.

有点意见不合。

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