0

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.

lulalala
  • 17,572
  • 15
  • 110
  • 169
  • Do you run command manually and via capistrano as same user? – Mikita Belahlazau Feb 21 '13 at 08:42
  • Did you check if #{rails_env} is correct. 'staging' ? – Nishant Feb 27 '13 at 12:13
  • @NikitaBeloglazov Yes the same user (sorry for late reply) – lulalala Mar 01 '13 at 08:14
  • @Nishant yes it is correct as staging/production – lulalala Mar 01 '13 at 08:29
  • Do you know where path to java is specified? I usually add it to `.bashrc`. I don't know if capistrano read `.bashrc` and load `PATH` from it. Check [this](http://stackoverflow.com/questions/7602548/capistrano-can-i-set-an-environment-variable-for-the-whole-cap-session) question: you may need to specify path to java in some more specific place. – Mikita Belahlazau Mar 01 '13 at 08:44
  • @NikitaBeloglazov Thanks. I found out it is not in path. But my .bashrc did not declare java path either. – lulalala Jun 18 '13 at 08:42

1 Answers1

0

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'

lulalala
  • 17,572
  • 15
  • 110
  • 169