Search code examples
ruby-on-railssolrcapistranosunspot

Capistrano: RSolr::Error::Http - 404 Not Found when reindexing Solr


I have not found any concrete examples that could possibly help address my problem. I previously had the sunspot gem working with Capistrano before my update to Rails 4 and Ruby 2. Any help sorting this error out would be greatly appreciated.

Gemfile:

gem 'sunspot_rails', :github => 'hsbt/sunspot', :branch => 'enabled-rails4'
gem 'sunspot_solr', :github => 'hsbt/sunspot', :branch => 'enabled-rails4'

.gitignore

solr/pids
solr/default

config/deploy.rb

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  desc "Migrate Database"
  task :migrate_db do
    run "cd #{current_path} && rake db:migrate RAILS_ENV=production"
    run "touch #{current_path}/tmp/restart.txt"
  end

  desc "Create Solr Directory"
  task :setup_solr_data_dir do
    run "mkdir -p #{shared_path}/solr/data"
  end
end

namespace :solr do
  desc "start solr"
  task :start, :roles => :app, :except => { :no_release => true } do
    run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr start --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids > /dev/null 2>&1 || true"
  end
  desc "stop solr"
  task :stop, :roles => :app, :except => { :no_release => true } do
    run ("cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec sunspot-solr stop --port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids > /dev/null 2>&1 || true")
  end
  desc "reindex the whole database"
  task :reindex, :roles => :app do
    stop
    run "rm -rf #{shared_path}/solr/data"
    start
    run "cd #{current_path} && yes | RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:reindex"
  end
end

after "deploy", "deploy:cleanup", "deploy:migrate_db",'deploy:setup_solr_data_dir', 'solr:start', 'solr:reindex'

Error Message:

  * 2013-06-24 12:19:20 executing `solr:start'
  * executing "cd /home/username/apps/MyApplication/current && RAILS_ENV=production bundle exec sunspot-solr start --port=8983 --data-directory=/home/username/apps/MyApplication/shared/solr/data --pid-dir=/home/username/apps/MyApplication/shared/pids > /dev/null 2>&1 || true"
    servers: ["0.0.0.0"]
    [0.0.0.0] executing command
    command finished in 1349ms
  * executing "cd /home/username/apps/MyApplication/current && yes | RAILS_ENV=production bundle exec rake sunspot:solr:reindex"
    servers: ["0.0.0.0"]
    [0.0.0.0] executing command
 ** [out :: 0.0.0.0] *Note: the reindex task will remove your current indexes and start from scratch.
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] If you have a large dataset, reindexing can take a very long time, possibly weeks.
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] This is not encouraged if you have anywhere near or over 1 million rows.
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] Are you sure you want to drop your indexes and completely reindex? (y/n)
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] D, [2013-06-24T12:18:59.139035 #2262] DEBUG -- :   SOLR Request (12.2ms)  [ path=#<RSolr::Client:0x00000007003988> parameters={data: <?xml version="1.0" encoding="UTF-8"?><delete><query>type:Project</query></delete>, headers: {"Content-Type"=>"text/xml"}, method: post, params: {:wt=>:ruby}, query: wt=ruby, path: update, uri: http://localhost:8983/solr/default/update?wt=ruby, open_timeout: , read_timeout: , retry_503: , retry_after_limit: } ]
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] rake aborted!
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] RSolr::Error::Http - 404 Not Found
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] Error:     NOT_FOUND
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] 
 ** [out :: 0.0.0.0] Request Data: 

Solution

  • Looks like your Solr server does not respond to the endpoint you expect. Your URL seems to be: localhost:8983/solr/default (with the handler being /update under that).

    Is there Solr endpoint there? Can you access it manually?

    If not, I would recommend changing your start commands to log to a file instead of /dev/null and seeing what exceptions you get.