Class: Indexotron::Runner
- Inherits:
-
Object
- Object
- Indexotron::Runner
- Defined in:
- lib/indexotron/runner.rb
Constant Summary collapse
- NDXO_DIR =
File.(ENV['NDXO_DIR'] || "~/indexotron/")
- ES_VERSION =
"elasticsearch-0.9.0"
Class Method Summary collapse
- .configure ⇒ Object
- .download(url, location, force = false) ⇒ Object
- .help ⇒ Object
- .install ⇒ Object
- .pid ⇒ Object
- .run(command) ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
- .sys(command) ⇒ Object
Class Method Details
.configure ⇒ Object
23 24 |
# File 'lib/indexotron/runner.rb', line 23 def configure end |
.download(url, location, force = false) ⇒ Object
57 58 59 |
# File 'lib/indexotron/runner.rb', line 57 def download(url, location, force = false) sys "curl -L #{url} -o #{location}" if force || !File.exists?(location) end |
.help ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/indexotron/runner.rb', line 65 def help puts <<-MSG Indexotron is a gem to help index and search web site. ------------------------------------------------------- ndxo <command> Commands: * install: installs to NDXO_DIR or ~/indexotron (elasticsearch.com) * start: starts an elastic search instance * stop: stops all elastic search instances * pid: prints pids for all instances * help: prints this help MSG end |
.install ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/indexotron/runner.rb', line 26 def install FileUtils.mkdir_p(NDXO_DIR) location = File.join NDXO_DIR, "#{ES_VERSION}.zip" download "http://github.com/downloads/elasticsearch/elasticsearch/#{ES_VERSION}.zip", location sys "cd #{NDXO_DIR} && unzip #{location}" end |
.pid ⇒ Object
44 45 46 |
# File 'lib/indexotron/runner.rb', line 44 def pid @pid ||= `ps -ef | grep [e]lastic | awk '{print $2}'`.split("\n").join(" ") end |
.run(command) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/indexotron/runner.rb', line 7 def run(command) configure case(command) when /^install$/ install when /^start$/ start when /^stop$/ stop when /^pid$/ puts pid else help end end |
.start ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/indexotron/runner.rb', line 34 def start location = File.join NDXO_DIR, ES_VERSION if File.exists? location sys "cd #{location} && bin/elasticsearch > output 2>&1" puts "Started elastic search (#{pid})" else puts "elastic search does not exist at #{location}. Try 'ndxo install'" end end |
.stop ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/indexotron/runner.rb', line 48 def stop if pid.empty? puts "No elastic search is started" else puts "Stopping elastic search (#{pid})" sys "kill -9 #{pid}" end end |
.sys(command) ⇒ Object
61 62 63 |
# File 'lib/indexotron/runner.rb', line 61 def sys(command) `#{command}` end |