Class: Supernova::Solr::CLI
- Inherits:
-
Object
- Object
- Supernova::Solr::CLI
- Defined in:
- lib/supernova/solr/cli.rb
Constant Summary collapse
- SOLR_URL =
"http://localhost:8983/solr"- SOLR_VERSION =
"3.5.0"
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #commit ⇒ Object
- #core ⇒ Object
- #core_name ⇒ Object
- #create ⇒ Object
- #execute ⇒ Object
- #get_solr_pid ⇒ Object
- #handle_response(response) ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #optimize ⇒ Object
- #opts ⇒ Object
- #server ⇒ Object
- #server_status ⇒ Object
- #solr_bin_path ⇒ Object
- #solr_home ⇒ Object
- #solr_pid ⇒ Object
- #solr_url ⇒ Object
- #start ⇒ Object
- #start_solr_cmd ⇒ Object
- #stop ⇒ Object
- #unload ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 |
# File 'lib/supernova/solr/cli.rb', line 12 def initialize(args) self. = {} opts.parse(args) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/supernova/solr/cli.rb', line 10 def end |
Instance Method Details
#commit ⇒ Object
91 92 93 |
# File 'lib/supernova/solr/cli.rb', line 91 def commit handle_response core.commit end |
#core ⇒ Object
75 76 77 |
# File 'lib/supernova/solr/cli.rb', line 75 def core Supernova::Solr::Core.new(solr_url, core_name) end |
#core_name ⇒ Object
166 167 168 |
# File 'lib/supernova/solr/cli.rb', line 166 def core_name [:core] end |
#create ⇒ Object
103 104 105 |
# File 'lib/supernova/solr/cli.rb', line 103 def create handle_response core.create([:data], [:instance]) end |
#execute ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/supernova/solr/cli.rb', line 83 def execute if action = [:action] send(action) else puts opts end end |
#get_solr_pid ⇒ Object
147 148 149 150 151 152 |
# File 'lib/supernova/solr/cli.rb', line 147 def get_solr_pid cmd = %(ps ax | grep "\\-Dsolr" | grep -v "grep" | grep -v " cd ") if pid_s = `#{cmd}`[/^(\d+)/, 1] pid_s.to_i end end |
#handle_response(response) ⇒ Object
135 136 137 |
# File 'lib/supernova/solr/cli.rb', line 135 def handle_response(response) puts response.to_json end |
#list ⇒ Object
107 108 109 110 111 |
# File 'lib/supernova/solr/cli.rb', line 107 def list server.core_names.sort.each do |name| puts name end end |
#optimize ⇒ Object
95 96 97 |
# File 'lib/supernova/solr/cli.rb', line 95 def optimize handle_response core.optimize end |
#opts ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/supernova/solr/cli.rb', line 17 def opts OptionParser.new do |o| o.on("--core CORE", String) do |core_name| self.[:core] = core_name end o.on("--server SERVER", String) do |server_name| self.[:server] = server_name end o.separator "" o.separator "Server ACTIONS" o.on("--start-server", "Start SOLR server") do |solr_bin| self.[:action] = :start end o.on("--server-status", "SOLR server status") do |solr_bin| self.[:action] = :server_status end o.on("--stop-server", "Stop SOLR server") do |solr_bin| self.[:action] = :stop end o.separator "" o.separator "Core ACTIONS" o.on("--list-cores", "List Cores") do self.[:action] = :list end o.on("--create", "Create Core") do self.[:action] = :create end o.on("--commit", "Commit Core") do self.[:action] = :commit end o.on("--optimize", "Optimize Core") do self.[:action] = :optimize end o.on("--unload", "Unload Core") do self.[:action] = :unload end o.separator "" o.separator "OPTIONS" o.on("--solr-bin SOLR_BIN", "Path to SOLR jarfile") do |solr_bin| self.[:solr_bin] = solr_bin end end end |
#server ⇒ Object
79 80 81 |
# File 'lib/supernova/solr/cli.rb', line 79 def server Supernova::Solr::Server.new(solr_url) end |
#server_status ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/supernova/solr/cli.rb', line 118 def server_status if solr_pid puts "SOLR running with pid #{solr_pid}" else puts "SOLR NOT running" end end |
#solr_bin_path ⇒ Object
158 159 160 |
# File 'lib/supernova/solr/cli.rb', line 158 def solr_bin_path [:solr_bin] || "/usr/local/Cellar/solr/#{SOLR_VERSION}/libexec/example/start.jar" end |
#solr_home ⇒ Object
154 155 156 |
# File 'lib/supernova/solr/cli.rb', line 154 def solr_home "/opt/solr" end |
#solr_pid ⇒ Object
143 144 145 |
# File 'lib/supernova/solr/cli.rb', line 143 def solr_pid @solr_pid ||= get_solr_pid end |
#solr_url ⇒ Object
162 163 164 |
# File 'lib/supernova/solr/cli.rb', line 162 def solr_url [:server] || SOLR_URL end |
#start ⇒ Object
113 114 115 116 |
# File 'lib/supernova/solr/cli.rb', line 113 def start puts "starting SOLR" exec start_solr_cmd end |
#start_solr_cmd ⇒ Object
139 140 141 |
# File 'lib/supernova/solr/cli.rb', line 139 def start_solr_cmd "cd #{File.dirname(solr_bin_path)} && /usr/bin/env java -Dsolr.solr.home=#{solr_home} -jar #{File.basename(solr_bin_path)} > /opt/solr/solr.log 2>&1 &" end |
#stop ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/supernova/solr/cli.rb', line 126 def stop if solr_pid system("kill #{solr_pid}") puts "solr killed" else puts "solr not running" end end |
#unload ⇒ Object
99 100 101 |
# File 'lib/supernova/solr/cli.rb', line 99 def unload handle_response core end |