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(*indexes) ⇒ Object
-
#initialize(configuration, path) ⇒ Controller
constructor
A new instance of Controller.
- #pid ⇒ Object
- #running? ⇒ Boolean
- #sphinx_version ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(configuration, path) ⇒ Controller
Returns a new instance of Controller.
5 6 7 8 9 10 11 12 |
# File 'lib/riddle/controller.rb', line 5 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.
3 4 5 |
# File 'lib/riddle/controller.rb', line 3 def bin_path @bin_path end |
#indexer_binary_name ⇒ Object
Returns the value of attribute indexer_binary_name.
3 4 5 |
# File 'lib/riddle/controller.rb', line 3 def indexer_binary_name @indexer_binary_name end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/riddle/controller.rb', line 3 def path @path end |
#searchd_binary_name ⇒ Object
Returns the value of attribute searchd_binary_name.
3 4 5 |
# File 'lib/riddle/controller.rb', line 3 def searchd_binary_name @searchd_binary_name end |
Instance Method Details
#index(*indexes) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/riddle/controller.rb', line 20 def index(*indexes) = indexes.last.is_a?(Hash) ? indexes.pop : {} indexes << '--all' if indexes.empty? cmd = "#{indexer} --config \"#{@path}\" #{indexes.join(' ')}" cmd << " --rotate" if running? [:verbose] ? system(cmd) : `#{cmd}` end |
#pid ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/riddle/controller.rb', line 63 def pid if File.exists?(@configuration.searchd.pid_file) File.read(@configuration.searchd.pid_file)[/\d+/] else nil end end |
#running? ⇒ Boolean
71 72 73 74 75 |
# File 'lib/riddle/controller.rb', line 71 def running? !!pid && !!Process.kill(0, pid.to_i) rescue false end |
#sphinx_version ⇒ Object
14 15 16 17 18 |
# File 'lib/riddle/controller.rb', line 14 def sphinx_version `#{indexer} 2>&1`[/^Sphinx (\d+\.\d+(\.\d+|(\-id64)?\-beta))/, 1] rescue nil end |
#start ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/riddle/controller.rb', line 29 def start return if running? cmd = "#{searchd} --pidfile --config \"#{@path}\"" if RUBY_PLATFORM =~ /mswin/ system("start /B #{cmd} 1> NUL 2>&1") else `#{cmd}` end sleep(1) unless running? puts "Failed to start searchd daemon. Check #{@configuration.searchd.log}." end end |
#stop ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/riddle/controller.rb', line 47 def stop return true unless running? stop_flag = 'stopwait' stop_flag = 'stop' if Riddle.loaded_version.split('.').first == '0' cmd = %(#{searchd} --pidfile --config "#{@path}" --#{stop_flag}) if RUBY_PLATFORM =~ /mswin/ system("start /B #{cmd} 1> NUL 2>&1") else `#{cmd}` end ensure return !running? end |