I'm using a system wide Ruby install on my server, and trying to deploy to a RVM gemset (like rvm use 1.9.2#gemset_name)
When I run my Cap file, Cap pukes and says a Ruby is not installed.
However, in reality that Ruby is installed. (The deploying user is part of the rvm group and can rvm use on the command line manually.)
What might I be doing wrong?
Relevant parts of Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require "bundler/capistrano"
require "rvm/capistrano"
require "erb"
set(:rvm_type) { :system }
set(:ruby_version) { '1.9.2' }
set(:rvm_ruby_string) { "#{ruby_version}##{application}" }
set(:rvm_path) { "/usr/local/rvm" }
#set(:rvm_bin_path) { "#{rvm_path}/bin" }
before "deploy:setup", "rvm:debug_gemset"
before "deploy:setup", "bundle:install_gem"
namespace :rvm do
desc "Creates gemset for application"
task :debug_gemset do
disable_rvm_shell do
run "/usr/local/rvm/bin/rvm list rubies" do |ch, stream, data|
if stream == :err
logger.debug "capured output on STDERR: #{data}"
else # stream == :out
logger.debug "capured output on STDOUT: #{data}"
end
end
end
end
end
# We need this so that we can install rvm first!
def disable_rvm_shell(&block)
default_shell = self[:default_shell]
self[:default_shell] = nil
yield
self[:default_shell] = default_shell
end
Cap output
* executing `deploy:setup'
triggering before callbacks for `deploy:setup'
* executing `rvm:debug_gemset'
* executing "/usr/local/rvm/bin/rvm list rubies" # <----- ran outside of rvm-shell
servers: ["XX.XXX.XXX.XXX"]
Password:
[XX.XXX.XXX.XXX] executing command
* capured output on STDOUT:
* capured output on STDOUT: rvm rubies
* capured output on STDOUT:
* ruby-1.8.7-p352 [ x86_64 ]
* capured output on STDOUT:
* ree-1.8.7-2011.03 [ x86_64 ]
* capured output on STDOUT:
* ruby-1.9.2-p290 [ x86_64 ]
*
Ok, awesome: 1.9.2 is installed. (This is to be expected - I installed 1.8.7, REE and 1.9.2 manually!)
But that's not all Capistrano says...
command finished
* executing `bundle:install_gem'
* executing "gem install bundler"
servers: ["XX.XXX.XXX.XXX"]
[XX.XXX.XXX.XXX] executing command
** [out ::XX.XXX.XXX.XXX] WARN: ruby ruby-1.9.2-p290 is not installed.
That last line claims that 1.9.2 not installed?!!
** [out ::XX.XXX.XXX.XXX] To install do: 'rvm install ruby-1.9.2-p290'
*** [err ::XX.XXX.XXX.XXX] ERROR: Gemset 'MY_APP' does not exist, rvm gemset create 'MY_APP' first.
*** [err ::XX.XXX.XXX.XXX] Error: RVM was unable to use '1.9.2#MY_APP'
command finished
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2#MY_APP' -c 'gem install bundler'" on XX.XXX.XXX.XXX
Debugging with cap shell
Jim Gay asks, "what about debugging with cap shell?"
rvm/capinstrano runs commands through rvm-shell, which immediately goes looking for the version and gemset essentially before the command can be executed. (Thus the disable_rvm_shell defined earlier that we used for doing the initial rvm list rubies.
For example:
cap> which rvm
[establishing connection(s) to XX.XXX.XXX.XX]
Password:
** [out :: XX.XXX.XXX.XX] WARN: ruby ruby-1.9.2-p290 is not installed.
** [out :: XX.XXX.XXX.XX] To install do: 'rvm install ruby-1.9.2-p290'
*** [err :: XX.XXX.XXX.XX] ERROR: Gemset 'MY_APP' does not exist, rvm gemset create 'MY_APP' first.
*** [err :: XX.XXX.XXX.XX] Error: RVM was unable to use '1.9.2#MY_APP'
error: failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2#MY_APP' -c 'which rvm'" on XX.XXX.XXX.XX
Conclusion
I'm obviously doing something wrong, but what?
Setting 1.9.2 to be the default Ruby is not an option, as I'm also going to host a 1.8.7 app on this box (ideally). This is why I'm using RVM at the system level to begin with).
I also made sure that the deploy user is in the RVM group, per the RVM documentation.
This WARN about not installed ruby is a misleading msg, it should say could not find ruby#gemset pair. If you would use this command on server:
rvm use 1.9.2#MY_APP
You would see the messages in reverse order - first error that the gemset can not be found, to solve it please go to server and run:
rvm --create use 1.9.2#MY_APP
Which will create a gemset for you, if you need any more help with it please contact IRC channel #rvm on FreeNode servers.
ok, so i just had this bomb with a patch version of ruby different.
server was running: ruby-1.8.7-p371
and the deploy (cap / rvm-capistrano, not sure which exactly) wanted rvm install ruby-1.8.7-p374.
I tried the gemset suggestion in #mpapis which was progress, but it was then that i noticed it asked me to p374.
so if in doubt, install the latest minor version of ruby.
Related
I have deployed application using Capistrano 3. I keep on getting following error.
`require': cannot load such file -- bundler/setup (LoadError)
Here is the cron tab list
PATH=/home/deploy/magnificent/shared/bundle/ruby/2.2.0/bin:/usr/local/rvm/gems/ruby-2.2.2/bin:/usr/local/rvm/gems/ruby-2.2.2#global/bin:/usr/local/rvm/rubies/ruby-2.2.2/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
* * * * * /bin/bash -l -c 'cd /home/deploy/magnificent/releases/20150830045359 && bin/rails runner -e production '\''Document.process_pending'\'' >> log/cron_standard.log 2>> log/cron_error.log'
and schedule.rb
env :PATH, ENV['PATH']
set :output, { error: 'log/cron_error.log', standard: 'log/cron_standard.log'}
every 1.minutes do
runner 'Document.process_pending'
end
Please note here that all the gems are installed in default gemset
Please note here that all the gems are installed in default gemset
I had 3 gemsets available in production. Rails is using default one where all required gems are installed.
As can be seen in the crontab list, crontab is also looking path in global gemset directory as well.
So I just selected global gemset and install bundler
$ rvm gemset use global
$ gem install bundler
These steps fixed the issue.
This worked for me:
rvm cron setup
I am using CentOS. Here is my output:
# which rvm
/usr/local/rvm/bin/rvm
# rvm ruby-1.9.3-p392#gemset
# /usr/local/rvm/bin/rvm ruby-1.9.3-p392#gemset
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.
As you can see if I am using just rvm everything is working. But capistrano using full path in commands like this
[46f28bd9] Command: cd /var/www/app/releases/20140718172057 && /usr/local/rvm/bin/rvm ruby-1.9.3-p392#gemset do bundle install --binstubs /var/www/app/shared/bin --path /var/www/app/shared/bundle --without development test --deployment --verbose
So it just fails and all gems being installed on default ruby instead of ruby-1.9.3-p392#gemset
Thanks for any suggestions.
My assumptions:
you are using Capistrano v3
have already included require 'capistrano/rvm' in your Capfile
when you cd into your project directory you have something like .ruby-version and .ruby-gemset setting up RVM for you.
You might want to try something like this
within fetch(:current_path) do
with rails_env: fetch(:rails_env) do
execute :bundle, "install"
end
end
The way Tasks work in v3 is different: https://github.com/capistrano/capistrano#tasks
tl;dr: execute(:bundle, :install) and execute('bundle install') don't behave identically!
I'm deploying to a VPS using capistrano, based on the guide at RailsCasts.
http://railscasts.com/episodes/335-deploying-to-a-vps?view=asciicast
It's failing on the deploy:cold command, with a conflict with Ruby. I actually can't see what the problem is, as when I shell into the same user the Ruby version looks correct.
$ cap shell
cap> which ruby
[establishing connection(s) to 192.xxx.xxx.xxx]
** [out :: 192.xxx.xxx.xxx] /home/deployer/.rbenv/shims/ruby
cap> ruby -v
** [out :: 192.xxx.xxx.xxx ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
This is the error:
command finished in 655ms
* 2013-07-01 16:40:39 executing `bundle:install'
* executing "cd /home/deployer/rails/assay/releases/20130701144038 && bundle install -- gemfile /home/deployer/rails/assay/releases/20130701144038/Gemfile --path /home/deployer/rails/assay/shared/bundle --deployment --quiet --without development test"
servers: ["192.xxx.xxx.xxx"]
[192.xxx.xxx.xxx] executing command
** [out :: 192.xxx.xxx.xxx] rbenv: version `1.9.3' is not installed
command finished in 662ms
*** [deploy:update_code] rolling back
My question is: how can I debug this? When I read the deploy.rb file I can't see where it even references the Ruby version. Pretty frustrating, I am about ready to ftp the repo up, which is not ideal obviously.
Well I finally got to the bottom of the issue - a mismatch between ruby versions use by Capistrano and what was actually on the server.
To debug Capistrano run it like this:
cap deploy:cold -d
That was you can step through the commands and access the temporary directories on the remote server before they are deleted.
I just had similar issue, the reason was .ruby-version file pointing at 1.9.3 (file was generated by rails-composer), while there was 1.9.3-p392 installed via rbenv on remote machine.
Debug info of capistrano can be shown by tail -f log/capistrano.log.
I'm trying to deploy my app for the first time on a ubuntu server.
I keep hitting this error:
2013-03-24 15:13:36 executing `deploy:run_migrations'
* executing "rvm gemset use vapin"
servers: ["111.111.111.11"]
[111.111.111.11] executing command
** [out :: 111.111.111.11]
** [out :: 111.111.111.11]
** [out :: 111.111.111.11] RVM is not a function, selecting rubies with 'rvm use ...' will not work.
** [out :: 111.111.111.11]
** [out :: 111.111.111.11]
** [out :: 111.111.111.11]
** [out :: 111.111.111.11] You need to change your terminal emulator preferences to allow login shell.
** [out :: 111.111.111.11]
** [out :: 111.111.111.11] Sometimes it is required to use `/bin/bash --login` as the command.
** [out :: 111.111.111.11]
** [out :: 111.111.111.11] Please visit https://rvm.io/integration/gnome-terminal/ for a example.
Here's some of my deploy.rb file:
require 'bundler/capistrano'
require 'rvm/capistrano'
# set the ruby version
#set :rvm_ruby_string, 'ruby-1.9.3-p392'
#set :rvm_type, :system
# set the rvm gemset to use
set :rvm_gemset, 'vapin'
...
task :install do
run "rvm gemset use #{rvm_gemset}"
run "cd #{current_path} && bundle install --without=test"
end
RVM is installed on my server.
$ which rvm
/usr/local/rvm/bin/rvm
$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby
Any help is appreciated. I've been googling this one for days.
EDIT
I've uninstalled my multiuser installation of RVM and reinstalled the single user version.
I added this line to my deploy.rb script:
set :default_shell, "/bin/bash --login" # required for rvm scripts to work properly
and now i do not get the "RVM is not a function...." error.
The problem is that when bundle install runs, the gems are not installed in my rvm gemset.
In my deploy.rb file, setting this line:
set :bundle_dir, "/usr/local/rvm/gems/ruby-1.9.3-p392"
before this line:
require 'bundler/capistrano'
seemed to help bundler know where to install the gems. Not sure why this is needed. I've never needed it before.
Don't use rvm1/capistrano3 or rvm/capistrano; don't set :pty.
Change ~/.rvmrc for the runner user, on the server, to this — note that it has to come before the line where it kills itself when not running interactively:
# get rvm for non-interactive shells (eg capistrano) too
source /etc/profile.d/rvm.sh
export BASH_ENV=$HOME/.bashrc
export rvm_is_not_a_shell_function=0
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
I've just been struggling with this issue. Tried everything listed above, nothing worked. Deploying from osx, to ubuntu.
Finally, on ubuntu, "su-ed" as my deploy user, I did "rvm get head" (where I had been using "rvm get stable"). (I have it setup in a single-user environment, with rvm under "/home/deploy/.rvm".)
Like magic, it started working! Phew. So I guess maybe there's some fix in the latest rvm, that isn't in stable yet?
Maybe you need to add the RVM bin directory to your $PATH for scripting:
PATH=$PATH:$HOME/.rvm/bin
Although it seems you've answered your own question, I'll throw my hat in the ring as well...
I had a similar issue with the whole RVM is not a function error when trying to create a Rails template, and got around it by getting the rvm environment instance on a specific Ruby version, and then setting the gemset/running bundle install directly on it. In your case, it may be something like:
require 'bundler/capistrano'
require 'rvm/capistrano'
# set the ruby version
set :rvm_ruby_string, 'ruby-1.9.3-p392'
# set the rvm gemset to use
set :rvm_gemset, 'vapin'
...
task :install do
require 'rvm'
env = RVM::Environment.new(rvm_ruby_string)
# If you need to create a new app-specific gemset
# env.gemset_create(rvm_gemset)
env.gemset_use!(rvm_gemset)
# If you need to install bundler in a new gemset
# env.system("gem", "install", "bundler")
env.system("bundle", "install", "--without=test")
end
Obviously, the above code is not tested, but I created similar code that I've had success with in this Rails template file that will hopefully serve as some reference to you if the above code completely fails.
EDIT:
The issue here was that I used RVM on my local machine and rbenv on the server. This is highly not recommended, if you're managing several ruby installation (or upgrading your ruby version but do not want to change the system's) use either RVM or rbenv on all environments!
/EDIT
So I'll start with a bit history:
I'm in the process of upgrading our rails2 website to rails3. Most of the things are working properly by now, except Capistrano's deploy script.
The current setup I have is:
RVM (1.14.1) installed locally
ruby-1.9.3-p194 (set to the project's folder)
Capistrano v2.12.0 (upgraded from 2.6.0, but it doesn't work on 2.6.0 as well) installed as an RVM gem
rvm-capistrano (1.2.2), added to the Gemfile (after doing some reading online and on SO)
rbenv (with ruby 1.9.3p194 used globally) installed on the server
(by now if you see anything that doesn't make sense, please let me know)
Nothing changed in the deploy script, yet when I try to deploy to my testing server (let's call it beta) I get this error:
* executing `deploy:restart'
* executing "cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers"
servers: ["208.0..."]
[208.0...] executing command
*** [err :: 208.0...] rake aborted!
*** [err :: 208.0...] no such file to load -- bundler/setup
*** [err :: 208.0...] /home/foo/bar/releases/20120630161947/Rakefile:5
*** [err :: 208.0...] (See full trace by running task with --trace)
** [out :: 208.0...] (in /home/foo/bar/releases/20120630161947)
command finished in 1183ms
failed: "sh -c 'cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers'" on 208.0...
The relevant part on deploy.rb looks like this:
task :restart do
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} queue:restart_workers"
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} db:migrate"
run "touch #{deploy_to}/current/tmp/restart.txt"
end
Needless to say, rake RAILS_ENV=beta queue:restart_workers' works perfectly when run manually on the server. Also, the application gets deployed (the code was copied from git, it's just the last part of the deploy fails).
Lastly, the error didn't change since before I installed rvm-capistrano and added to the Gemfile, so I'm not even sure it's related to rvm, I'm just guessing from looking online.
Thanks
In order to work correctly, rbenv must override all the ruby and gem-related executables with the shims it provides.
Usually this is done with a startup script (this is why it works when you login to your server) but Capistrano logs in without shell and thus does not run those scripts.
You must add the following to your deploy.rb :
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
and do not use anything rvm related on your server, rbenv and rvm really do not like each other
PS : a little more explanation on this topic : http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/