我正在使用Sunspot Solr,我正在编写Capistrano任务来启动/停止它。
namespace :sunspot do
task :start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:start"
end
end
然而,当我运行此任务时,我收到错误,找不到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的Java检查代码为here。
如果我在服务器上手动运行cd /home/user/deploy/project/current && RAILS_ENV=staging bundle exec rake sunspot:solr:start
,它会按预期工作。如果通过Capistrano调用该命令,我不知道为什么Java不存在。
答案 0 :(得分:0)
在我的服务器上,Java路径被加载到`/ etc / profile'脚本中。
但是Capistrano没有加载该脚本。
根据this discussion,在Capistrano deploy.rb文件中设置它将确保其shell加载配置文件脚本,该脚本在术语中为我设置Java路径。
default_run_options[:shell] = '/bin/bash --login'