user3442206
user3442206

Reputation: 587

Unicorn crashing because of using wrong ruby version after deployment

I am having trouble launching my application in the server because of the following error:

/home/blabla/.rvm/gems/ruby-2.1.0/bin/ruby/2.1.0/bin/unicorn", "-E", "beta", "-c", "/var/www/testenvir/releases/20141117005244/config/unicorn.rb", "-D", {16=>#<Kgio::UNIXServer:fd 16>}] (in /var/www/testenvir/releases/20141121053734)

/home/blabla/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.6.3/lib/bundler/definition.rb:390:in `validate_ruby!': Your Ruby version is 2.1.0, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)

The error is self descritive, but i don't know how to fix it since i have in my Gemfile script:

ruby '2.0.0'

And in my capistrano deployment script:

set :rvm_ruby_string, 'ruby-2.0.0-p353'
set :bundle_dir, "/home/blabla/.rvm/gems/ruby-2.0.0-p353/bin"

In my server, i set my environment variables as following:

rvm use ruby-2.0.0-p353

And the output of env RAILS_ENV=testenvir bundle exec ruby -v is :

ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

I could verify by connecting through a new terminal that rvm listproduces :

=* ruby-2.0.0-p353 [ x86_64 ]
   ruby-2.1.0 [ x86_64 ]

Finally my crashing command is defined in the eye script that tries launching the following command:

bundle exec unicorn -E #{RAILS_ENV} -c #{working_dir}/config/unicorn.rb -D

I verified that #{working_directory} and #{RAILS_ENV} are correct, so i thought about hardcoding ( as a first step), the paths of bundleand unicorn, since they are the one taken from the 2.1.0 instead of the 2.0.0-p353 ( The error that i get in unicorn.log... ), but it didn't work ( crashed with another error...)

I also checked $PATH, $GEM_HOME, $GEM_PATH and $RUBY_VERSION, and they were all pointing to the version 2.0.0-p353. In fact, i did a printenv and looked for a potential variable with ruby-2.1.0 assigned to it, but i found none !

I checked all files of my application to wether i am assigning ruby-2.1.0 somewhere anyhow, but i didn't find any reference to that. All of them were set to ruby-2.0.0-p353.

My question is :

Is there another place that i am missing where should i specify my desired ruby version ? How should i set my ruby version in the server rather that what i did ?

Thanks!

UPDATE:

rvm current 
ruby-2.0.0-p353

rvm gemset list
gemsets for ruby-2.0.0-p353 (found in /home/deployer/.rvm/gems/ruby-2.0.0-p353)
=> (default)
   global

Upvotes: 2

Views: 1155

Answers (1)

Patteh
Patteh

Reputation: 93

A little late but could help others who are experiencing the same problem. I´m using rolling restart and what helped me was this comment which I have in my config/unicorn.rb file

    # If you roll off old code from your app servers (i.e. the way chef, capistrano, 
    # basically anyone does it) you need to make sure Unicorn is not looking for 
    # the Gemfile it was originally started with. It's really important that after 
    # change you stop/start unicorn after first redeploy.
    # After that the "before_exec" block will go in memory and 
    # wait for the next deploy!
    before_exec do |server|
      ENV['BUNDLE_GEMFILE'] = "#{root}/Gemfile"
    end

So then I ran

/etc/init.d/unicorn-myapp stop

/etc/init.d/unicorn-myapp start

and unicorn picked up the new ruby version.

Upvotes: 1

Related Questions