Skip to content

Instantly share code, notes, and snippets.

@doitian
Created February 11, 2012 02:17
Show Gist options
  • Select an option

  • Save doitian/1795439 to your computer and use it in GitHub Desktop.

Select an option

Save doitian/1795439 to your computer and use it in GitHub Desktop.
sunspot solr in capistrano
namespace :deploy do
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"
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"
end
desc "reindex the whole database"
task :reindex, :roles => :app do
stop
run "rm -rf #{shared_path}/solr/data"
start
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake sunspot:solr:reindex"
end
end
after 'deploy:setup', 'deploy:setup_solr_data_dir'
@lassebunk

Copy link
Copy Markdown

Thanks! Helped me a lot!

@claudiuchis

Copy link
Copy Markdown

I spent couple of days trying to set up solr with Capistrano, so that I wouldn't have to reindex the database after every build.
Your recipe helped me achieve my goal. Now the deployment time has been reduced to 8 seconds.
Thank you!

@coderxin

coderxin commented Feb 2, 2013

Copy link
Copy Markdown

Thanks a lot!

@lulalala

Copy link
Copy Markdown

May I ask why sunspot-solr start instead of rake sunspot:solr:start?

@thekindofme

Copy link
Copy Markdown

Just wanted to say thanks!

@terenceponce

Copy link
Copy Markdown

This is a god-send. Thank you for this!

@pablomarti

Copy link
Copy Markdown

Great! It works but I have a problem, when I execute cap solr:reindex it throws a message: "Are you sure you want to drop your indexes and completely reindex? (y/n)", but when I enter "yes" or "y" nothing happens and the terminal keeps waiting, how do you manage this situation? (also thinking in Cron for reindex)

@moxorama

Copy link
Copy Markdown

I'm using "yes" command

yes | bundle exec rake sunspot:solr:reindex"

@cec

cec commented May 3, 2013

Copy link
Copy Markdown

This solution does not work for me, as starting solr in this way does not use the schema.xml file in the app's root, but the one in the sunspot_solr gem dir.

I noticed this as I had a custom analyzer and after moving to this solution, I was not getting expected results anymore.

You can find my solution at https://gist.github.com/cec/5508303

@mshappe

mshappe commented May 25, 2013

Copy link
Copy Markdown

👍

@n8gard

n8gard commented Jul 8, 2013

Copy link
Copy Markdown

This is great. One thing I am unclear about: do/can you run more than one instance of Sunspot/Solr? If I have capistrano deploy to multiple servers (in EC2, for example) with :web and :app roles, will each server maintain and provide an index? Or do I define a new role, mapped to only one server that runs Sunspot/Solr?

@mookie-

mookie- commented Aug 6, 2013

Copy link
Copy Markdown

Hi, thanks for sharing this. I'm also interested how to use Sunspot/Solr with multiple servers. It would be great if someone could answer njnorrgard questions.

@hminaya

hminaya commented Aug 14, 2013

Copy link
Copy Markdown

thanks, it helped me out.

@bradens

bradens commented Oct 15, 2013

Copy link
Copy Markdown

I'm also interested in a multiple server solr setup, anyone know?

@muscardinus

Copy link
Copy Markdown

Thank you!

For anyone who moved to Capistrano 3, I made an updated version: https://gist.github.com/muscardinus/8884801

@uetchy

uetchy commented Apr 22, 2014

Copy link
Copy Markdown

Thanks a lot!!

@tamvm

tamvm commented May 25, 2014

Copy link
Copy Markdown

Anyone has same solution for mina (http://nadarei.co/mina/)? Thanks

@richardrails

Copy link
Copy Markdown

any solution for Mina?

@lalitlogical

Copy link
Copy Markdown

Thanks, but this solution does not work for me.

I have below version for Sunspot, etc.

sunspot_solr 2.2.7
sunspot 2.2.7
sunspot_rails 2.2.7

For Capistrano 3, I have made an updated version: https://gist.github.com/lalitlogical/4c8c047b95fe45da6ae19d1b59411783

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment