namespace :solrsrv do desc 'start solr' task :start do cfg = solr_server_config command = %w(bundle exec solrsrv) command << "--pid-file #{cfg[:pid_file]}" command << "--data-dir #{cfg[:data_dir]}" if cfg[:log_dir] FileUtils.mkdir_p(cfg[:log_dir]) command << "--log-dir #{cfg[:log_dir]}" end command << "--port #{cfg[:port]}" sh "#{command.join(' ')} &> #{Rails.root}/log/solr_#{Rails.env}.log &" end desc 'Stop solr' task :stop do cfg = solr_server_config pid_file = cfg[:pid_file] if pid_file && File.exists?(pid_file) pid = File.read(pid_file) puts 'stopping solr' %x(kill #{pid}) File.unlink(pid_file) else puts 'solr is not running' end end end def solr_server_config configuration_file = File.join(Rails.root, 'config/solrsrv.yml') if File.exists? configuration_file config = YAML.load_file(configuration_file)[Rails.env].symbolize_keys %w(log_dir data_dir pid_file).map(&:to_sym).each do |entry| config[entry] = File.expand_path(config[entry]) if config[entry] end else config = { :port => { 'development' => 8981, 'test' => 8982, 'production' => 8983 }[Rails.env], :log_dir => "#{Rails.root}/log/solr/#{Rails.env}", :data_dir => "#{Rails.root}/tmp/solr_data/#{Rails.env}", :pid_file => "#{Rails.root}/tmp/pids/solr_#{Rails.env}.pid" } end return config end