I am using Sunspot Solr and I am writing a Capistrano task to start/stop it.
namespace :sunspot do
task :start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:start"
end
end
However when I run this task, I get error of not finding Java:
*** [err :: example.com] /home/user/deploy/project/shared/bundle/ruby/1.9.1/gems/sunspot_solr-1.3.3/lib/sunspot/solr/java.rb:5:in ``': No such file or directory - java -version (Errno::ENOENT)
*** [err :: example.com] from /home/user/deploy/project/shared/bundle/ruby/1.9.1/gems/sunspot_solr-1.3.3/lib/sunspot/solr/java.rb:5:in `installed?'
*** [err :: example.com] from /home/user/deploy/project/shared/bundle/ruby/1.9.1/gems/sunspot_solr-1.3.3/lib/sunspot/solr/server.rb:200:in `ensure_java_installed'
*** [err :: example.com] from /home/user/deploy/project/shared/bundle/ruby/1.9.1/gems/sunspot_solr-1.3.3/lib/sunspot/solr/server.rb:27:in `initialize'
*** [err :: example.com] from /home/user/deploy/project/shared/bundle/ruby/1.9.1/gems/sunspot_solr-1.3.3/bin/sunspot-solr:16:in `new'
*** [err :: example.com] from /home/user/deploy/project/shared/bundle/ruby/1.9.1/gems/sunspot_solr-1.3.3/bin/sunspot-solr:16:in `<top (required)>'
*** [err :: example.com] from /home/user/deploy/project/shared/bundle/ruby/1.9.1/bin/sunspot-solr:23:in `load'
*** [err :: example.com] from /home/user/deploy/project/shared/bundle/ruby/1.9.1/bin/sunspot-solr:23:in `<main>'
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3@project' -c 'cd /home/user/deploy/project/current && RAILS_ENV=staging bundle exec rake sunspot:solr:start'" on example.com
Sunspot's Java checking code is here.
If I manually run cd /home/user/deploy/project/current && RAILS_ENV=staging bundle exec rake sunspot:solr:start
on the server it works as expected. I don't know why Java is not present if the command is called through Capistrano.
On my server, Java paths are loaded inside the `/etc/profile' script.
However Capistrano does not load that script.
According to this discussion, setting this in the Capistrano deploy.rb file will make sure its shell loads the profile script, which in term sets Java path for me.
default_run_options[:shell] = '/bin/bash --login'