/
rake_interface.rb
89 lines (72 loc) · 2.11 KB
/
rake_interface.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class ThinkingSphinx::RakeInterface
def clear_all
[
configuration.indices_location,
configuration.searchd.binlog_path
].each do |path|
FileUtils.rm_r(path) if File.exists?(path)
end
end
def clear_real_time
indices = configuration.indices.select { |index| index.type == 'rt' }
indices.each do |index|
index.render
Dir["#{index.path}.*"].each { |path| FileUtils.rm path }
end
path = configuration.searchd.binlog_path
FileUtils.rm_r(path) if File.exists?(path)
end
def configure
puts "Generating configuration to #{configuration.configuration_file}"
configuration.render_to_file
end
def generate
indices = configuration.indices.select { |index| index.type == 'rt' }
indices.each do |index|
ThinkingSphinx::RealTime::Populator.populate index
end
end
def index(reconfigure = true, verbose = true)
configure if reconfigure
FileUtils.mkdir_p configuration.indices_location
ThinkingSphinx.before_index_hooks.each { |hook| hook.call }
controller.index :verbose => verbose
end
def prepare
configuration.preload_indices
configuration.render
FileUtils.mkdir_p configuration.indices_location
end
def start
raise RuntimeError, 'searchd is already running' if controller.running?
FileUtils.mkdir_p configuration.indices_location
controller.start
if controller.running?
puts "Started searchd successfully (pid: #{controller.pid})."
else
puts "Failed to start searchd. Check the log files for more information."
end
end
def status
if controller.running?
puts "The Sphinx daemon searchd is currently running."
else
puts "The Sphinx daemon searchd is not currently running."
end
end
def stop
unless controller.running?
puts 'searchd is not currently running.' and return
end
pid = controller.pid
until controller.stop do
sleep(0.5)
end
puts "Stopped searchd daemon (pid: #{pid})."
end
private
delegate :controller, :to => :configuration
def configuration
ThinkingSphinx::Configuration.instance
end
end