Permalink
Browse files

Modified rake task and settings to support specifying where to put je…

…tty log files and where to look for solr config files
  • Loading branch information...
oxtralite committed Jun 17, 2009
1 parent cfb6545 commit 8f63811dec8abacb187ba0297b0d87d523216cda
Showing with 18 additions and 8 deletions.
  1. +3 −0 config/solr_environment.rb
  2. +15 −8 lib/acts_as_solr/tasks/solr.rake
  3. 0 solr/logs/.empty-dir-for-git
@@ -15,6 +15,9 @@
unless defined? SOLR_DATA_PATH
SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || "#{RAILS_ROOT}/solr/#{ENV['RAILS_ENV']}"
end
+unless defined? SOLR_CONFIG_PATH
+ SOLR_CONFIG_PATH = ENV["SOLR_CONFIG_PATH"] || SOLR_PATH
+end
unless defined? SOLR_PORT
config = YAML::load_file(RAILS_ROOT+'/config/solr.yml')
@@ -1,7 +1,7 @@
namespace :solr do
desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
- task :start do
+ task :start => :environment do
require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
FileUtils.mkdir_p(SOLR_LOGS_PATH)
FileUtils.mkdir_p(SOLR_DATA_PATH)
@@ -13,21 +13,28 @@ namespace :solr do
rescue Net::HTTPServerException #responding
puts "Port #{SOLR_PORT} in use" and return
- rescue Errno::ECONNREFUSED #not responding
+ rescue Errno::ECONNREFUSED, Errno::EBADF #not responding
Dir.chdir(SOLR_PATH) do
- pid = fork do
- #STDERR.close
- exec "java #{SOLR_JVM_OPTIONS} -Dsolr.data.dir=#{SOLR_DATA_PATH} -Djetty.logs=#{SOLR_LOGS_PATH} -Djetty.port=#{SOLR_PORT} -jar start.jar"
+ cmd = "java #{SOLR_JVM_OPTIONS} -Djetty.logs=\"#{SOLR_LOGS_PATH}\" -Dsolr.solr.home=\"#{SOLR_CONFIG_PATH}\" -Dsolr.data.dir=\"#{SOLR_DATA_PATH}\" -Djetty.port=#{SOLR_PORT} -jar start.jar"
+ puts "Executing: " + cmd
+ windows = RUBY_PLATFORM =~ /(win|w)32$/
+ if windows
+ exec cmd
+ else
+ pid = fork do
+ #STDERR.close
+ exec cmd
+ end
end
sleep(5)
- File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid}
+ File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid} if windows
puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}."
end
end
end
desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
- task :stop do
+ task :stop=> :environment do
require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
fork do
file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid"
@@ -46,7 +53,7 @@ namespace :solr do
end
desc 'Remove Solr index'
- task :destroy_index do
+ task :destroy_index => :environment do
require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
raise "In production mode. I'm not going to delete the index, sorry." if ENV['RAILS_ENV'] == "production"
if File.exists?("#{SOLR_DATA_PATH}")
No changes.

0 comments on commit 8f63811

Please sign in to comment.