Commit 1bbb7864900690ab210e9167de7d98ee1b2de498
1 parent
7fc1e86f
Exists in
master
and in
29 other branches
Add solr:download task
Task solr:download downloads, unpacks and installs Solr+Jetty 3.1.0 inside acts_as_solr plugin. Also fix PID filename according to the standard. Downloading Solr is necessary cause it's too big to include with noosfero (~13mb) and is not available for Debian Lenny.
Showing
3 changed files
with
26 additions
and
11 deletions
Show diff stats
vendor/plugins/acts_as_solr/config/solr_environment.rb
@@ -5,11 +5,13 @@ SOLR_PATH = "#{File.dirname(File.expand_path(__FILE__))}/../solr" unless defined | @@ -5,11 +5,13 @@ SOLR_PATH = "#{File.dirname(File.expand_path(__FILE__))}/../solr" unless defined | ||
5 | 5 | ||
6 | SOLR_LOGS_PATH = "#{rails_root_dir}/log" unless defined? SOLR_LOGS_PATH | 6 | SOLR_LOGS_PATH = "#{rails_root_dir}/log" unless defined? SOLR_LOGS_PATH |
7 | SOLR_PIDS_PATH = "#{rails_root_dir}/tmp/pids" unless defined? SOLR_PIDS_PATH | 7 | SOLR_PIDS_PATH = "#{rails_root_dir}/tmp/pids" unless defined? SOLR_PIDS_PATH |
8 | +SOLR_PID_FILE="#{SOLR_PIDS_PATH}/solr.#{ENV['RAILS_ENV']}.pid" | ||
8 | SOLR_DATA_PATH = "#{rails_root_dir}/solr/#{ENV['RAILS_ENV']}" unless defined? SOLR_DATA_PATH | 9 | SOLR_DATA_PATH = "#{rails_root_dir}/solr/#{ENV['RAILS_ENV']}" unless defined? SOLR_DATA_PATH |
9 | 10 | ||
10 | unless defined? SOLR_PORT | 11 | unless defined? SOLR_PORT |
11 | config = YAML::load_file(rails_root_dir+'/config/solr.yml') | 12 | config = YAML::load_file(rails_root_dir+'/config/solr.yml') |
12 | 13 | ||
14 | + SOLR_HOST = ENV['HOST'] || URI.parse(config[ENV['RAILS_ENV']]['url']).host | ||
13 | SOLR_PORT = ENV['PORT'] || URI.parse(config[ENV['RAILS_ENV']]['url']).port | 15 | SOLR_PORT = ENV['PORT'] || URI.parse(config[ENV['RAILS_ENV']]['url']).port |
14 | end | 16 | end |
15 | 17 |
vendor/plugins/acts_as_solr/lib/solr/xml.rb
@@ -36,9 +36,8 @@ begin | @@ -36,9 +36,8 @@ begin | ||
36 | Solr::XML::Element = XML::Node | 36 | Solr::XML::Element = XML::Node |
37 | 37 | ||
38 | rescue LoadError => e # If we can't load either rubygems or libxml-ruby | 38 | rescue LoadError => e # If we can't load either rubygems or libxml-ruby |
39 | - puts "Requiring REXML" | ||
40 | # Just use REXML. | 39 | # Just use REXML. |
41 | require 'rexml/document' | 40 | require 'rexml/document' |
42 | Solr::XML::Element = REXML::Element | 41 | Solr::XML::Element = REXML::Element |
43 | 42 | ||
44 | -end | ||
45 | \ No newline at end of file | 43 | \ No newline at end of file |
44 | +end |
vendor/plugins/acts_as_solr/lib/tasks/solr.rake
@@ -5,6 +5,21 @@ require 'active_record' | @@ -5,6 +5,21 @@ require 'active_record' | ||
5 | 5 | ||
6 | namespace :solr do | 6 | namespace :solr do |
7 | 7 | ||
8 | + desc 'Download and install Solr+Jetty 3.1.0.' | ||
9 | + task :download do | ||
10 | + if (File.exists?(Rails.root + '/vendor/plugins/acts_as_solr/solr/start.jar')) | ||
11 | + puts 'Solr already downloaded.' | ||
12 | + else | ||
13 | + cd '/tmp' | ||
14 | + sh 'wget -c http://apache.mirrors.hoobly.com/lucene/solr/3.1.0/apache-solr-3.1.0.tgz' | ||
15 | + sh 'tar xzf apache-solr-3.1.0.tgz' | ||
16 | + cd 'apache-solr-3.1.0/example' | ||
17 | + cp_r ['../LICENSE.txt', '../NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'], Rails.root + '/vendor/plugins/acts_as_solr/solr', :verbose => true | ||
18 | + cd 'solr' | ||
19 | + cp_r ['README.txt', 'bin', 'solr.xml'], Rails.root + '/vendor/plugins/acts_as_solr/solr/solr', :verbose => true | ||
20 | + end | ||
21 | + end | ||
22 | + | ||
8 | desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' | 23 | desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' |
9 | task :start do | 24 | task :start do |
10 | require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" | 25 | require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" |
@@ -18,12 +33,12 @@ namespace :solr do | @@ -18,12 +33,12 @@ namespace :solr do | ||
18 | rescue Errno::ECONNREFUSED #not responding | 33 | rescue Errno::ECONNREFUSED #not responding |
19 | Dir.chdir(SOLR_PATH) do | 34 | Dir.chdir(SOLR_PATH) do |
20 | pid = fork do | 35 | pid = fork do |
21 | - #STDERR.close | ||
22 | - exec "java #{SOLR_JVM_OPTIONS} -Dsolr.data.dir=#{SOLR_DATA_PATH} -Djetty.logs=#{SOLR_LOGS_PATH} -Djetty.port=#{SOLR_PORT} -jar start.jar" | 36 | + STDERR.close |
37 | + exec "java #{SOLR_JVM_OPTIONS} -Dsolr.data.dir=#{SOLR_DATA_PATH} -Djetty.logs=#{SOLR_LOGS_PATH} -Djetty.host=#{SOLR_HOST} -Djetty.port=#{SOLR_PORT} -jar start.jar" | ||
23 | end | 38 | end |
24 | sleep(5) | 39 | sleep(5) |
25 | - File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid} | ||
26 | - puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}." | 40 | + File.open(SOLR_PID_FILE, "w"){ |f| f << pid} |
41 | + puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_HOST}:#{SOLR_PORT}, pid: #{pid}." | ||
27 | end | 42 | end |
28 | end | 43 | end |
29 | end | 44 | end |
@@ -32,17 +47,16 @@ namespace :solr do | @@ -32,17 +47,16 @@ namespace :solr do | ||
32 | task :stop do | 47 | task :stop do |
33 | require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" | 48 | require "#{File.dirname(__FILE__)}/../../config/solr_environment.rb" |
34 | fork do | 49 | fork do |
35 | - file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid" | ||
36 | - if File.exists?(file_path) | ||
37 | - File.open(file_path, "r") do |f| | 50 | + if File.exists?(SOLR_PID_FILE) |
51 | + File.open(SOLR_PID_FILE, "r") do |f| | ||
38 | pid = f.readline | 52 | pid = f.readline |
39 | Process.kill('TERM', pid.to_i) | 53 | Process.kill('TERM', pid.to_i) |
40 | end | 54 | end |
41 | - File.unlink(file_path) | 55 | + File.unlink(SOLR_PID_FILE) |
42 | Rake::Task["solr:destroy_index"].invoke if ENV['RAILS_ENV'] == 'test' | 56 | Rake::Task["solr:destroy_index"].invoke if ENV['RAILS_ENV'] == 'test' |
43 | puts "Solr shutdown successfully." | 57 | puts "Solr shutdown successfully." |
44 | else | 58 | else |
45 | - puts "PID file not found at #{file_path}. Either Solr is not running or no PID file was written." | 59 | + puts "PID file not found at #{SOLR_PID_FILE}. Either Solr is not running or no PID file was written." |
46 | end | 60 | end |
47 | end | 61 | end |
48 | end | 62 | end |