Question

My custom capistrano task "app:sample" fails with the following error message:

mnylen ilmo-on-rails $ cap app:sample
* executing `app:sample'
* executing "export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10"
servers: ["rails.cs.helsinki.fi"]
* establishing connection to gateway `melkinpaasi.cs.helsinki.fi'
* Creating gateway using melkinpaasi.cs.helsinki.fi
* establishing connection to `rails.cs.helsinki.fi' via gateway
Password: 
[rails.cs.helsinki.fi] executing command
*** [err :: rails.cs.helsinki.fi] Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again: http://rubygems.rubyforge.org
command finished
failed: "sh -c 'export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10'" on rails.cs.helsinki.fi

Am I missing something or doing something wrong? The task is:

namespace :app do
  desc "Run sample data on production2
  task :sample do
    run "export RAILS_ENV=production; cd #{current_path}; ruby script/coursegen 10"
  end
end

If I run the same command from the actual server, it works fine.

Was it helpful?

Solution 2

Okay, solved.

The problem was that there was two Ruby installations on the production server.

The .profile file under my home directory on the production server set the PATH environment variable to point to the correct Ruby version.

run command, it seems, doesn't source the .profile file and thus, running ruby script/coursegen 10 in the task used the wrong Ruby version, which was the reason for the weird error message about RubyGems version. This also explains why it worked when manually running the command from production servers shell.

My solution was to use full path to the Ruby executable in my run task, like this:

run "export RAILS_ENV=production; cd #{current_path}; /opt/ruby-enterprise-1.8.7-2009.10/bin/ruby script/coursegen 10"

Of course, this isn't pretty, but it works. If anyone has any prettier solutions, I'd be more than glad to use those instead. :)

OTHER TIPS

Cap is running the remote command as an unexpected user - and that user does not have the correct path to ruby and gem. Check your settings in your recipe for :user and :use_sudo. Carefully read the cap output to see what user is being connected. I see you are using a :gateway; there can be two users in this case. One to connect to the gateway, and another to actually run commands on the target server.

Seems like you should update your RubyGems on the remote server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top