Skip to content

Instantly share code, notes, and snippets.

@davidimoore
Last active August 29, 2015 14:06
Show Gist options
  • Save davidimoore/f880964aeac0723b87f5 to your computer and use it in GitHub Desktop.
Save davidimoore/f880964aeac0723b87f5 to your computer and use it in GitHub Desktop.
Thor script for restarting solr and indexing key value search terms
require 'thor/group'
class Startup < Thor::Group
no_tasks do
def confirm(method)
if $?.to_i == 0
puts "#{method} executed successfully"
end
end
end
desc "stops then starts solr, reindexes solr, indexes suggestions and starts web server"
def stop_solr
system 'sol=$(ps -ef | grep "[s]olr" | awk \'{print $2}\'); if [ -n "$sol" ]; then kill $sol;fi;'
confirm(__method__)
end
def start_solr
until system 'sol=$(ps -ef | grep "[s]olr" | awk \'{print $2}\')'
system 'bundle exec rake sunspot:solr:start'
sleep(3.0)
puts 'Solr is not yet started'
end
confirm(__method__)
end
def reindex_solr
system 'bundle exec rake sunspot:solr:start'
until system 'sol=$(ps -ef | grep "[s]olr" | awk \'{print $2}\')'
sleep(10.0)
puts 'Solr is not yet started'
end
sleep(5.0)
system 'bundle exec rake sunspot:reindex'
confirm(__method__)
end
def index_suggestions
system 'bundle exec rake search_suggestions:index'
confirm(__method__)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment