#!/usr/bin/env ruby require 'solr_wrapper' require 'optparse' options = {} collection_options = {} OptionParser.new do |opts| opts.banner = "Usage: solr_wrapper [options]" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| options[:verbose] = v end opts.on("--config", "Load configuration from a file") do |v| options[:config] = v end opts.on("--version VERSION", "Specify a Solr version to download (default: #{SolrWrapper.default_solr_version})") do |v| options[:version] = v end opts.on("-pPORT", "--port PORT", "Specify the port Solr should run at (default: 8983)") do |p| if p == 'random' options[:port] = nil else options[:port] = p end end opts.on("-c", "--cloud", "Run solr in cloud mode") do |c| options[:cloud] = c end opts.on("-dPATH", "--download_path PATH", "Download/use solr at the given path") do |d| options[:download_path] = d end opts.on("-iDIR", "--instance_directory DIR", "Install/use solr at the given directory") do |d| options[:instance_dir] = d end opts.on("-lDIR", "--lib_directory DIR", "Grab extra libs from this directory") do |d| options[:extra_lib_dir] = d end opts.on("-nNAME", "--collection_name NAME", "Create a default solr collection with the given name") do |c| collection_options[:name] = c end opts.on("-dDIR", "--collection_config DIR", "Create a default solr collection with the files from the given directory") do |d| collection_options[:dir] = d end opts.on("--no-checksum", "Skip running checksum validation on the downloaded file") do |d| options[:ignore_md5sum] = true end end.parse! # default to verbose options[:verbose] = true if options[:verbose].nil? default_configuration_paths = ['.solr_wrapper', '~/.solr_wrapper'] default_configuration_paths.each do |p| path = File.expand_path('.solr_wrapper') options[:config] ||= path if File.exist? path end if options[:config] require 'erb' require 'yaml' config = YAML.load(ERB.new(IO.read(options[:config])).result(binding)) collection_config = config.delete(:collection) || {} options = config.merge(options) collection_options = collection_config.merge(collection_options) end instance = SolrWrapper.default_instance(options) $stderr.print "Starting Solr #{instance.version} on port #{instance.port} ... " instance.wrap do |conn| conn.with_collection(collection_options) do $stderr.puts "http://#{instance.host}:#{instance.port}/solr/" begin while conn.status sleep 1 end rescue Interrupt $stderr.puts "Solr is shutting down." end end end