Created
August 14, 2012 16:55
-
-
Save joegoggins/3350836 to your computer and use it in GitHub Desktop.
Sunspot/Solr/Torquebox service wrapper until https://issues.jboss.org/browse/TORQUE-467 is done. Note: this approach is cheezy and crude, but works...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SunspotSolrWrapperService | |
def initialize(opts={}) | |
end | |
def start | |
puts "SunspotSolrWrapperService#start" | |
kill_all_solr_processes | |
launch_command = "nohup env RAILS_ENV=#{Rails.env} #{solr_process_to_launch} >> #{start_stop_log_file} 2>&1 &" | |
puts "executing: #{launch_command}" | |
system(launch_command) | |
puts "SunspotSolrWrapperService#start (return)" | |
end | |
def stop | |
puts "SunspotSolrWrapperService#stop" | |
kill_all_solr_processes | |
puts "SunspotSolrWrapperService#stop (return)" | |
end | |
protected | |
def kill_all_solr_processes | |
puts "killing all solr processes" | |
self.process_ids_that_match_launch_script_regex.each do |pid| | |
Process.kill('TERM', pid.to_i) | |
end | |
end | |
def solr_process_to_launch | |
'bundle exec rake sunspot:solr:run' | |
end | |
def start_stop_log_file | |
File.join(Rails.root,"solr_start_stop.log") | |
end | |
def process_ids_that_match_launch_script_regex | |
`ps aux | grep solr | grep -v grep | awk '{print $2}'`.split("\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment