Class: Chef::Solr::Application::Solr
- Inherits:
-
Application
- Object
- Application
- Chef::Solr::Application::Solr
- Defined in:
- lib/chef/solr/application/solr.rb
Instance Attribute Summary collapse
-
#logfile ⇒ Object
Returns the value of attribute logfile.
Instance Method Summary collapse
- #assert_solr_installed! ⇒ Object
- #assert_valid_schema! ⇒ Object
- #check_value_of_main_index_max_field_length ⇒ Object
- #close_and_reopen_log_file ⇒ Object
- #config_document ⇒ Object
-
#initialize ⇒ Solr
constructor
A new instance of Solr.
- #run_application ⇒ Object
- #schema_attributes ⇒ Object
- #schema_document ⇒ Object
- #schema_file_path ⇒ Object
- #setup_application ⇒ Object
- #solr_config_file_path ⇒ Object
- #solr_data_dir_exist? ⇒ Boolean
- #solr_home_exist? ⇒ Boolean
- #solr_jetty_home_exist? ⇒ Boolean
- #solr_main_index_elements ⇒ Object
- #solr_main_index_max_field_length ⇒ Object
- #solr_schema_name ⇒ Object
- #solr_schema_version ⇒ Object
- #valid_schema_name? ⇒ Boolean
- #valid_schema_version? ⇒ Boolean
Constructor Details
#initialize ⇒ Solr
Returns a new instance of Solr.
117 118 119 |
# File 'lib/chef/solr/application/solr.rb', line 117 def initialize super end |
Instance Attribute Details
#logfile ⇒ Object
Returns the value of attribute logfile.
31 32 33 |
# File 'lib/chef/solr/application/solr.rb', line 31 def logfile @logfile end |
Instance Method Details
#assert_solr_installed! ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/chef/solr/application/solr.rb', line 204 def assert_solr_installed! unless solr_home_exist? && solr_data_dir_exist? && solr_jetty_home_exist? Chef::Log.fatal "Chef Solr is not installed or solr_home_path, solr_data_path, and solr_jetty_path are misconfigured." Chef::Log.fatal "Your current configuration is:" Chef::Log.fatal "solr_home_path: #{Chef::Config[:solr_home_path]}" Chef::Log.fatal "solr_data_path: #{Chef::Config[:solr_data_path]}" Chef::Log.fatal "solr_jetty_path: #{Chef::Config[:solr_jetty_path]}" Chef::Log.fatal "You can install Chef Solr using the chef-solr-installer script." exit 1 end end |
#assert_valid_schema! ⇒ Object
216 217 218 219 220 221 222 223 |
# File 'lib/chef/solr/application/solr.rb', line 216 def assert_valid_schema! unless valid_schema_name? && valid_schema_version? Chef::Log.fatal "Your Chef Solr installation needs to be upgraded." Chef::Log.fatal "Expected schema version #{Chef::Solr::SCHEMA_VERSION} but version #{solr_schema_version} is installed." Chef::Log.fatal "Use chef-solr-installer to upgrade your Solr install after backing up your data." exit 1 end end |
#check_value_of_main_index_max_field_length ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/chef/solr/application/solr.rb', line 180 def check_value_of_main_index_max_field_length if solr_main_index_max_field_length unless solr_main_index_max_field_length > 10000 = "The maxFieldLimit for the mainIndex is set to #{solr_main_index_max_field_length}. " << "It's recommended to increase this value (in #{solr_config_file_path})." Chef::Log.warn end else Chef::Log.warn "Unable to determine the maxFieldLimit for the mainIndex (in #{solr_config_file_path})" end end |
#close_and_reopen_log_file ⇒ Object
265 266 267 268 269 270 |
# File 'lib/chef/solr/application/solr.rb', line 265 def close_and_reopen_log_file Chef::Log.close STDOUT.reopen(@logfile) STDERR.reopen(@logfile) end |
#config_document ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/chef/solr/application/solr.rb', line 137 def config_document @config_document ||=begin File.open(solr_config_file_path, 'r') do |xmlsux| REXML::Document.new(xmlsux) end end end |
#run_application ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/chef/solr/application/solr.rb', line 244 def run_application if Chef::Config[:daemonize] Chef::Daemon.daemonize("chef-solr") end Dir.chdir(Chef::Config[:solr_jetty_path]) do command = "java -Xmx#{Chef::Config[:solr_heap_size]} -Xms#{Chef::Config[:solr_heap_size]}" command << " -Dsolr.data.dir=#{Chef::Config[:solr_data_path]}" command << " -Dsolr.solr.home=#{Chef::Config[:solr_home_path]}" command << " #{Chef::Config[:solr_java_opts]}" if Chef::Config[:solr_java_opts] command << " -jar #{File.join(Chef::Config[:solr_jetty_path], 'start.jar')}" Chef::Log.info("Starting Solr with #{command}") # Opened earlier before we dropped privileges, don't need it anymore close_and_reopen_log_file if @logfile Kernel.exec(command) end end |
#schema_attributes ⇒ Object
145 146 147 |
# File 'lib/chef/solr/application/solr.rb', line 145 def schema_attributes @schema_attributes ||= REXML::XPath.first(schema_document, '/schema').attributes end |
#schema_document ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/chef/solr/application/solr.rb', line 129 def schema_document @schema_document ||= begin File.open(schema_file_path, 'r') do |xmlsux| REXML::Document.new(xmlsux) end end end |
#schema_file_path ⇒ Object
121 122 123 |
# File 'lib/chef/solr/application/solr.rb', line 121 def schema_file_path @schema_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'schema.xml') end |
#setup_application ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/chef/solr/application/solr.rb', line 225 def setup_application assert_solr_installed! assert_valid_schema! check_value_of_main_index_max_field_length # Need to redirect stdout and stderr so Java process inherits them. # If -L wasn't specified, Chef::Config[:log_location] will be an IO # object, otherwise it will be a String. # # Open this as a privileged user and hang onto it if Chef::Config[:log_location].kind_of?(String) @logfile = File.new(Chef::Config[:log_location], "a") end Chef::Log.level = Chef::Config[:log_level] Chef::Daemon.change_privilege end |
#solr_config_file_path ⇒ Object
125 126 127 |
# File 'lib/chef/solr/application/solr.rb', line 125 def solr_config_file_path @solr_config_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'solrconfig.xml') end |
#solr_data_dir_exist? ⇒ Boolean
196 197 198 |
# File 'lib/chef/solr/application/solr.rb', line 196 def solr_data_dir_exist? File.directory?(Chef::Config[:solr_data_path]) end |
#solr_home_exist? ⇒ Boolean
192 193 194 |
# File 'lib/chef/solr/application/solr.rb', line 192 def solr_home_exist? File.directory?(Chef::Config[:solr_home_path]) end |
#solr_jetty_home_exist? ⇒ Boolean
200 201 202 |
# File 'lib/chef/solr/application/solr.rb', line 200 def solr_jetty_home_exist? File.directory?(Chef::Config[:solr_jetty_path]) end |
#solr_main_index_elements ⇒ Object
149 150 151 152 |
# File 'lib/chef/solr/application/solr.rb', line 149 def solr_main_index_elements location = '/config/mainIndex/' @solr_main_index_elements ||= REXML::XPath.first(config_document, location).elements end |
#solr_main_index_max_field_length ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/chef/solr/application/solr.rb', line 162 def solr_main_index_max_field_length @solr_main_index_max_field_length ||=begin field_length_el = solr_main_index_elements.select do |el| el.name == 'maxFieldLength' end field_length_el.empty? ? nil : field_length_el.first.text.to_i end end |
#solr_schema_name ⇒ Object
154 155 156 |
# File 'lib/chef/solr/application/solr.rb', line 154 def solr_schema_name schema_attributes["name"] end |
#solr_schema_version ⇒ Object
158 159 160 |
# File 'lib/chef/solr/application/solr.rb', line 158 def solr_schema_version schema_attributes["version"] end |
#valid_schema_name? ⇒ Boolean
172 173 174 |
# File 'lib/chef/solr/application/solr.rb', line 172 def valid_schema_name? solr_schema_name == Chef::Solr::SCHEMA_NAME end |
#valid_schema_version? ⇒ Boolean
176 177 178 |
# File 'lib/chef/solr/application/solr.rb', line 176 def valid_schema_version? solr_schema_version == Chef::Solr::SCHEMA_VERSION end |