Skip to content

Instantly share code, notes, and snippets.

@ali-sheiba
Last active July 22, 2016 04:53
Show Gist options
  • Save ali-sheiba/fc31d3ecdfee14abdaddff28e3d07d04 to your computer and use it in GitHub Desktop.
Save ali-sheiba/fc31d3ecdfee14abdaddff28e3d07d04 to your computer and use it in GitHub Desktop.
Reindex Solr Sunspot while deploying ROR Application using Capistrano
# add those lines to deploy.rb
# inspired from : https://gist.github.com/doitian/1795439
# solr tasks
namespace :solr do
desc "start solr sunspot server"
task :start do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "sunspot:solr:start"
end
end
end
end
desc "stop solr sunspot server"
task :stop do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "sunspot:solr:stop"
# execute "rm -rf #{shared_path}/solr/data"
end
end
end
end
desc "reindex the whole database"
task :reindex do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, "sunspot:solr:reindex"
end
end
end
end
desc "start & reindex and stop solr and start again ( for manual use )"
task :restart do
on roles(:app), in: :sequence, wait: 3 do
%w[stop start reindex].each { |tast| invoke "solr:#{stop}" }
end
end
# automatically stop, start and reindex while deploying
before 'deploy:starting', 'solr:stop'
after 'deploy:finished', 'solr:start'
after 'deploy:finished', 'solr:reindex'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment