#!/usr/bin/env ruby require 'solr_wrapper' require 'optparse' options = {} collection_options = {} subtext = < OptionParser.new do |opts| opts.banner = "Usage: clean" end, 'dir' => OptionParser.new do |opts| opts.banner = "Usage: dir" end, } begin args.order! command = ARGV.shift if command raise "Bad subcommand: #{command}" unless subcommands[command] subcommands[command].order! end args.parse! rescue => error $stderr.puts "ERROR: #{error}\n" $stderr.puts args.help exit 1 end instance = SolrWrapper.instance(options) case command when 'clean' if instance.managed? && instance.started? $stderr.puts "Please stop solr before cleaning" exit 1 end $stderr.puts "cleaning #{instance.instance_dir}..." instance.remove_instance_dir! when 'dir' puts instance.instance_dir else $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 conn.wait rescue Interrupt Signal.trap("SIGTERM") {"IGNORE"} Signal.trap("SIGINT") {"IGNORE"} $stderr.puts "Solr is shutting down." end end end end