Created
May 3, 2013 10:01
-
-
Save cec/5508303 to your computer and use it in GitHub Desktop.
Capistrano Tasks to setup and interact with SolR and SunSpot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
# Ask whether to reindex before restarting Passenger | |
task :restart, :roles => :app, :except => {:no_release => true} do | |
solr.reindex if 'y' == Capistrano::CLI.ui.ask("\n\n Should I reindex all models? (anything but y will cancel)") | |
run "touch #{File.join(current_path, 'tmp', 'restart.txt')}" | |
end | |
desc 'create shared data and pid dirs for Solr' | |
task :setup_solr_shared_dirs do | |
# conf dir is not shared as different versions need different configs | |
%w(data pids).each do |path| | |
run "mkdir -p #{shared_path}/solr/#{path}" | |
end | |
end | |
desc 'substituses current_path/solr/data and pids with symlinks to the shared dirs' | |
task :link_to_solr_shared_dirs do | |
%w(solr/data solr/pids).each do |solr_path| | |
run "rm -fr #{current_path}/#{solr_path}" #removing might not be necessary with proper .gitignore setup | |
run "ln -s #{shared_path}/#{solr_path} #{current_path}/#{solr_path}" | |
end | |
end | |
end | |
after 'deploy:setup', 'deploy:setup_solr_shared_dirs' | |
# rm and symlinks every time we finished uploading code and symlinking to the new release | |
after 'deploy:update', 'deploy:link_to_solr_shared_dirs' | |
# Tasks to interact with Solr and SunSpot | |
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 rake sunspot:solr:start" | |
end | |
desc "stop solr" | |
task :stop, :roles => :app, :except => { :no_release => true } do | |
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:stop" | |
end | |
desc "stop solr, remove data, start solr, reindex all records" | |
task :hard_reindex, :roles => :app do | |
stop | |
run "rm -rf #{shared_path}/solr/data/*" | |
start | |
reindex | |
end | |
desc "simple reindex" #note the yes | reindex to avoid the nil.chomp error | |
task :reindex, roles: :app do | |
run "cd #{current_path} && yes | RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:reindex" | |
end | |
end |
My setup task is not being executed, should I add this in config/deploy.rb? how?
I had to change this part:
run "mkdir #{current_path}/solr"
%w(solr/data solr/pids).each do |solr_path|
run "rm -fr #{current_path}/#{solr_path}" #removing might not be necessary with proper .gitignore setup
Also, to because shared folders were not being created I used:
before 'deploy:update', 'deploy:setup_solr_shared_dirs'
I am having this:
Error - RSolr::Error::Http - 500 Internal Server Error - retrying...
when reindexing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
seems nice, I will try this.