Skip to content

Instantly share code, notes, and snippets.

@pedro108
Forked from doitian/solr_cap.rb
Last active December 22, 2015 09:18
Show Gist options
  • Save pedro108/6450620 to your computer and use it in GitHub Desktop.
Save pedro108/6450620 to your computer and use it in GitHub Desktop.
namespace :deploy do
task :setup_solr, roles: :app do
run "mkdir -p #{shared_path}/solr/data"
put File.read('config/sunspot.yml'), "#{shared_path}/config/sunspot.yml"
end
end
namespace :solr do
def solr_config
sunspot_yaml = YAML::load(File.read('config/sunspot.yml'))
sunspot_yaml[rails_env]['solr']
end
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=#{solr_config['port']} --solr-home=#{shared_path}/solr --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=#{solr_config['port']} --solr-home=#{shared_path}/solr --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} yes | bundle exec rake sunspot:solr:reindex"
end
end
after 'deploy:setup', 'deploy:setup_solr'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment