Skip to content

Instantly share code, notes, and snippets.

@stephenkey
Forked from muscardinus/sunspot.cap
Last active September 2, 2015 16:30
Show Gist options
  • Select an option

  • Save stephenkey/d2e162ed9a3a9c35e0fe to your computer and use it in GitHub Desktop.

Select an option

Save stephenkey/d2e162ed9a3a9c35e0fe to your computer and use it in GitHub Desktop.

Revisions

  1. @muscardinus muscardinus revised this gist Feb 8, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions sunspot.cap
    Original file line number Diff line number Diff line change
    @@ -52,3 +52,4 @@ namespace :solr do
    end

    end

  2. @muscardinus muscardinus created this gist Feb 8, 2014.
    54 changes: 54 additions & 0 deletions sunspot.cap
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    namespace :deploy do
    before :updated, :setup_solr_data_dir do
    on roles(:app) do
    unless test "[ -d #{shared_path}/solr/data ]"
    execute :mkdir, "-p #{shared_path}/solr/data"
    end
    end
    end
    end

    namespace :solr do

    %w[start stop].each do |command|
    desc "#{command} solr"
    task command do
    on roles(:app) do
    solr_pid = "#{shared_path}/pids/sunspot-solr.pid"
    if command == "start" or (test "[ -f #{solr_pid} ]" and test "kill -0 $( cat #{solr_pid} )")
    within current_path do
    with rails_env: fetch(:rails_env, 'production') do
    execute :bundle, 'exec', 'sunspot-solr', command, "--port=8983 --data-directory=#{shared_path}/solr/data --pid-dir=#{shared_path}/pids"
    end
    end
    end
    end
    end
    end

    desc "restart solr"
    task :restart do
    invoke 'solr:stop'
    invoke 'solr:start'
    end

    after 'deploy:finished', 'solr:restart'

    desc "reindex the whole solr database"
    task :reindex do
    invoke 'solr:stop'
    on roles(:app) do
    execute :rm, "-rf #{shared_path}/solr/data"
    end
    invoke 'solr:start'
    on roles(:app) do
    within current_path do
    with rails_env: fetch(:rails_env, 'production') do
    info "Reindexing Solr database"
    execute :bundle, 'exec', :rake, 'sunspot:solr:reindex[,,true]'
    end
    end
    end
    end

    end