Capistrano is calling rake from /usr/bin/env but rake gem is installed into /usr/local/rvm/gems/ruby-2.1.0/gems/rake-10.1.1

705 views
Skip to first unread message

Douglas Magnenat

unread,
Jan 29, 2014, 6:13:00 AM1/29/14
to capis...@googlegroups.com
Versions:
Ruby 2.1
Capistrano 3.0.1
Rake 10.1.1/ Rails 3.2.16 / rvm 1.25.12

I'm using rvm on myserver to facilitate ruby installation, but I install and udate manually the gems with user rvm_admin.
rvm has been installed 'system wide'.
I don't use capistrano-rvm and I don't use capistrano-rails, as I manually update ruby, gems, assets, and migrations.


Platform:
Working on XUbuntu 12.04.4 LTS
Deploying to Debian Wheezy

Logs:
  • Please past logs (as completely as possible to a 3rd party pasting service such as pastie.org)
Files:
  • Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
  • deploy.rb
set :application, 'odpf'
set :repo_url, 'g...@github.com:myrepo/myapp.git'
set :branch, 'production_1.01'
set :deploy_to, '/var/www/odpf'
set :pty, false
set :scm, :git
set :format, :pretty


namespace :deploy do
  desc
'Restart application'
  task
:restart do
    on roles
(:app), in: :sequence, wait: 5 do
     
# Your restart mechanism here, for example:
     
# l'exemple correspond à ce qu'il faut pour restart passenger :
     
# http://www.modrails.com/documentation/Users%20guide%20Apache.html#_redeploying_restarting_the_ruby_on_rails_application
      execute
:mkdir, '-p', "#{release_path}/tmp"
      execute
:touch, release_path.join('tmp/restart.txt')
   
end
 
end


  after
:restart, :clear_cache do
    on roles
(:web), in: :groups, limit: 3, wait: 10 do
     
# Here we can do anything such as:
     
# Conformément à : http://guides.rubyonrails.org/v3.2.14/command_line.html#tmp
      within release_path
do
        execute
:rake, 'tmp:cache:clear'
     
end
   
end
 
end


 
# Create symlink to database.yml after publication
  before
'deploy:published', 'db_access:create_symlinks'


  after
:finishing, 'deploy:cleanup'
end
  • Stage files (production.rb, staging.rb)
set :stage, :production
server
'myserver.net', user: 'rvm_admin', roles: %w{web app db}

set :ssh_options, { forward_agent: true, port: 8888 }


When I perform a cap production deploy, It goes well untill the end of the output :

INFO [0a0dbcb0] Running /usr/bin/env rake tmp:cache:clear on phisa-odpf-vd.vserver.nimag.net
DEBUG
[0a0dbcb0] Command: cd /var/www/odpf/releases/20140129101515 && /usr/bin/env rake tmp:cache:clear
DEBUG
[0a0dbcb0] /usr/bin/env: rake
DEBUG
[0a0dbcb0] : Aucun fichier ou dossier de ce type
cap aborted
!
rake stdout
: Nothing written
rake stderr
: Nothing written
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.0.0/lib/sshkit/command.rb:94:in `exit_status='
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:125:in `
block (4 levels) in _execute'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'


Capistrano try to execute rake from /usr/bin/env

but my gem is installed here :

rvm_admin@myserver:/var/www/odpf/current$ bundle show rake
/usr/local/rvm/gems/ruby-2.1.0/gems/rake-10.1.1
rvm_admin@myserver
:/var/www/odpf/current$ which rake
/usr/local/rvm/gems/ruby-2.1.0/bin/rake

What am I doing wrong ?

Lee Hambley

unread,
Jan 29, 2014, 6:30:26 AM1/29/14
to capistrano
/usr/bin/env is the default place to look for commands.

When typing rake (for example) your shell will typically use /usr/bin/env to find the binary. We use /usr/bin/env as the default to make it clear that we're deferring responsibility of resolving which binary to use to the standard mechanisms. In your case, this resolution hasn't had the PATH modifications usually performed by rvm.sh applied, because it's not an interactive shell in Capistrano.

I might argue that this is a problem with the rvm/capistrano integration (which I have never used, and didn't contribute to), there's a larger question about why you are using rvm in production. (I'd argue that distribution package maintainers are doing the world a disservice in not providing modern Ruby packages)

The simple solution is to do something like this, to set the path to :rake:
SSHKit.config.command_map[:rake] = "./bin/rake"

--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/58a8122b-a09f-47b7-add5-6fe395d812dd%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Message has been deleted

Lee Hambley

unread,
Jan 29, 2014, 12:07:30 PM1/29/14
to capistrano
My go-to script for Debian looks something like this:

#!/bin/bash -e

echo '9e6386d53f5200a3e7069107405b93f7  ruby-2.1.0.tar.gz' > ruby-2.1.0.tar.gz.md5sum
md5sum -c ruby-2.1.0.tar.gz.md5sum

sudo apt-get install -y bison openssl libreadline6 libreadline6-dev zlib1g \
zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev \
ncurses-dev libcurl4-openssl-dev libopenssl-ruby apache2-prefork-dev \
libapr1-dev libaprutil1-dev libx11-dev libffi-dev tcl-dev tk-dev

tar -xf ruby-2.1.0.tar.gz
unlink ruby-2.1.0.tar.gz
cd ruby-2.1.0
./configure --enable-silent-rules
make V=0
make test
sudo make install

gem install bundler
On 29 January 2014 18:05, Douglas Magnenat <douglas....@gmail.com> wrote:
Thanks for your answer Lee.

Apart from my original question.
About ruby intallation, I was considering about not using RVM, but as the ruby installation is so unclear to me, and didnt found a decent tutorial to install Ruby on a server, I had to rely on RVM.

Morevoer, despite spending hours reading official sites and questioned on stackoverflow about how gemset works, Bunlder and Gems remain very obscure to me when. The most puzzeling thing is when you do a 
gem list
command, and you see different versions of the same gem installed, then you realized that gems can be installed everwhere, and you feel really lost.

So if you could provide me a good tutorial or procedure to build a running Ruby environnement onto a server, I would be glad to remove this RVM.

That would be great !

Good evening

--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.

Douglas Magnenat

unread,
Feb 1, 2014, 4:10:53 AM2/1/14
to capis...@googlegroups.com
I also got another answer on stackoverflow. I tried your solution and the one on Stackoverflow. Both do work.
So as I don't know if it is linked to this bug referenced on stackoverflow, so I post the link to the other answer (just in case)  : 

SSHKit.config.command_map[:rake] = "bundle exec rake tmp:cache:clear"

Le mercredi 29 janvier 2014 12:13:00 UTC+1, Douglas Magnenat a écrit :

Donovan Bray

unread,
Feb 1, 2014, 10:09:11 AM2/1/14
to capis...@googlegroups.com
I have a hard fast rule that you should never use rbenv, rvm or any other ruby switcher on production or staging boxes. Ruby switching is a developers tool. Use one and one only version of ruby on a remote box. If you have two apps that need to use different rubies, and you want to make them work on the same box. Invest the time required to make the code use the same version of ruby instead of futzing with a ruby switcher.  If you can't make them use the same version of ruby, in these days of cloud computing, put the apps on different servers. If you are so hard up for hardware then use something like LXC to provide that isolation.

rvm and rbenv are just examples of providing isolation. You can provide isolation by putting them on different servers or virtual servers and you will save yourself a lot of pain, and incidentally downtime. In production I want the fewest dependencies, and when you add a ruby switcher you are adding a very fickle, complicated, and in my experience unstable dependency.

That being said, try using the full path to bundle in your rake command.  There are also examples of adding to the path by overriding the call to the default shell.  I don't use cap3 yet so I can only speculate that the following may work in this one instance.  I can pretty much guarantee this won't be the last time using a ruby switcher is going to bite you.

SSHKit.config.command_map[:rake] = "/usr/local/rvm/gems/ruby-2.1.0/bin/bundle exec rake tmp:cache:clear"


--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.

Douglas Magnenat

unread,
Feb 1, 2014, 2:15:18 PM2/1/14
to capis...@googlegroups.com, donn...@donovanbray.com
Though I agree it is a bad idea to mix different rubies on the same server, I disagree not using RVM to install a solo ruby. I spent my weekend try to solve gems issues with Phusion Passenger :

1) Despite I said at the begining of my first post-question. I finally will use capistrano-rvm and capistrano-bundler.
Ruby and gems would give me far more headache if I wouldn't use RVM and bundler.
It doesn't exist proper tutorial on Internet to install ruby taking care of ruby locatin, access rights, path, environnement variables, gems locations, etc...
The complexity of ruby environnement appears to be one of the reasons why RVM has been developed.

2) Now without capistrano-bundler having for me generated this complexe parametered bundle command ( It s not just a "bundle install") I would have spent ages to understand what to do to perform a proper deployment : Capistrano and Capistrano-bundler take care of it for me.

3) As Phusion Passenger is no more installed as a gem but as a package (on debian) It also comes with an apt-get dependency : ruby package 1.9.3
Unfortunately when I installed my ruby version 2.1.0, I thought this was the only ruby version installed. This lead me to a pain.... troubelshooting why Phusion passenger was complaining not finding my gems.
After ours of fighting with gems, I was happy to find a dedicated section to RVM into Phusion Passenger guide : http://stackoverflow.com/questions/21477087/why-does-passenger-says-that-my-gem-json-cant-be-found-when-my-gem-list-show

To be short, Ruby and his Gems is so much a pain.... for me (and many people I guess) that I'm really happy to have helping tools such as RVM, Capistrano and capistrano-bundler to ease my life of developer. So that I can concentrate on coding my app.

I'm really gratefull to developers that took time to develop such tools ! Great thanks !


Le samedi 1 février 2014 16:09:11 UTC+1, dbray a écrit :
I have a hard fast rule that you should never use rben, rvm or any other ruby switcher on production or staging boxes. Ruby switching is a developers tool. Use one and one only version of ruby on a remote box. If you have two apps that need to use different rubies, and you want to make them work on the same box. Invest the time required to make the code use the same version of ruby instead of futzing with a ruby switcher.  If you can't make them use the same version of ruby, in these days of cloud computing, put the apps on different servers. If you are so hard up for hardware then use something like LXC to provide that isolation.

Donovan Bray

unread,
Feb 1, 2014, 2:44:29 PM2/1/14
to capis...@googlegroups.com
I've been working with ruby and gems since ruby 1.8.7. As I mentioned I haven't upgraded to Cap 3, all of my infrastructure is built with capistrano 2, and the cap-recipes gem at https://github.com/donnoman/cap-recipes


among many others.

I have not made the decision to upgrade cap-recipes to cap3.  I don't particularly like the cap3 dsl. and Cap3 removed some of the items that allows my recipes to work, like the missing :on hooks. The removal of method_missing to locate variables increases the level of effort to upgrade cap-recipes.

I'm considering forking cap2 and renaming it to be a different project to separate it from cap3.  I haven't made a final decision on it.   I'm going to finally fork cap-recipes to be it's own gem separate from it's parent fork, and I may try to upgrade one or two recipes to cap3 to determine the LOE and see if I can live with the dsl. If I can, then I'll upgrade cap-recipes to cap3.  If the baby is ugly, then I'll fork cap2.


--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages