Class: Riddle::Controller
- Inherits:
-
Object
- Object
- Riddle::Controller
- Defined in:
- lib/riddle/controller.rb
Instance Attribute Summary collapse
-
#bin_path ⇒ Object
Returns the value of attribute bin_path.
-
#indexer_binary_name ⇒ Object
Returns the value of attribute indexer_binary_name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#searchd_binary_name ⇒ Object
Returns the value of attribute searchd_binary_name.
Instance Method Summary collapse
- #index(*indices) ⇒ Object
-
#initialize(configuration, path) ⇒ Controller
constructor
A new instance of Controller.
- #pid ⇒ Object
- #rotate ⇒ Object
- #running? ⇒ Boolean
- #sphinx_version ⇒ Object
- #start(options = {}) ⇒ Object
- #stop(options = {}) ⇒ Object
Constructor Details
#initialize(configuration, path) ⇒ Controller
Returns a new instance of Controller.
7 8 9 10 11 12 13 14 |
# File 'lib/riddle/controller.rb', line 7 def initialize(configuration, path) @configuration = configuration @path = path @bin_path = '' @searchd_binary_name = 'searchd' @indexer_binary_name = 'indexer' end |
Instance Attribute Details
#bin_path ⇒ Object
Returns the value of attribute bin_path.
5 6 7 |
# File 'lib/riddle/controller.rb', line 5 def bin_path @bin_path end |
#indexer_binary_name ⇒ Object
Returns the value of attribute indexer_binary_name.
5 6 7 |
# File 'lib/riddle/controller.rb', line 5 def indexer_binary_name @indexer_binary_name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/riddle/controller.rb', line 5 def path @path end |
#searchd_binary_name ⇒ Object
Returns the value of attribute searchd_binary_name.
5 6 7 |
# File 'lib/riddle/controller.rb', line 5 def searchd_binary_name @searchd_binary_name end |
Instance Method Details
#index(*indices) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/riddle/controller.rb', line 22 def index(*indices) = indices.last.is_a?(Hash) ? indices.pop : {} indices << '--all' if indices.empty? command = "#{indexer} --config \"#{@path}\" #{indices.join(' ')}" command << " --rotate" if running? Riddle::ExecuteCommand.call command, [:verbose] end |
#pid ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/riddle/controller.rb', line 58 def pid if File.exists?(configuration.searchd.pid_file) File.read(configuration.searchd.pid_file)[/\d+/] else nil end end |
#rotate ⇒ Object
66 67 68 |
# File 'lib/riddle/controller.rb', line 66 def rotate pid && Process.kill(:HUP, pid.to_i) end |
#running? ⇒ Boolean
70 71 72 73 74 |
# File 'lib/riddle/controller.rb', line 70 def running? !!pid && !!Process.kill(0, pid.to_i) rescue false end |
#sphinx_version ⇒ Object
16 17 18 19 20 |
# File 'lib/riddle/controller.rb', line 16 def sphinx_version `#{indexer} 2>&1`[/Sphinx (\d+\.\d+(\.\d+|(?:-dev|(\-id64)?\-beta)))/, 1] rescue nil end |
#start(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/riddle/controller.rb', line 32 def start( = {}) return if running? check_for_configuration_file command = "#{searchd} --pidfile --config \"#{@path}\"" command << " --nodetach" if [:nodetach] exec(command) if [:nodetach] # Code does not get here if nodetach is true. Riddle::ExecuteCommand.call command, [:verbose] end |
#stop(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/riddle/controller.rb', line 45 def stop( = {}) return true unless running? check_for_configuration_file stop_flag = 'stopwait' stop_flag = 'stop' if Riddle.loaded_version.split('.').first == '0' command = %(#{searchd} --pidfile --config "#{@path}" --#{stop_flag}) result = Riddle::ExecuteCommand.call command, [:verbose] result.successful = !running? result end |