Parent

Chef::Solr::Application::Solr

Attributes

logfile[RW]

Public Class Methods

new() click to toggle source
# File lib/chef/solr/application/solr.rb, line 117
def initialize
  super
end

Public Instance Methods

assert_solr_installed!() click to toggle source
# 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!() click to toggle source
# 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() click to toggle source
# 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
      message  = "The maxFieldLimit for the mainIndex is set to #{solr_main_index_max_field_length}.  "
      message << "It's recommended to increase this value (in #{solr_config_file_path})."
      Chef::Log.warn message
    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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/chef/solr/application/solr.rb, line 145
def schema_attributes
  @schema_attributes ||= REXML::XPath.first(schema_document, '/schema').attributes
end
schema_document() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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?() click to toggle source
# 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?() click to toggle source
# 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?() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/chef/solr/application/solr.rb, line 154
def solr_schema_name
  schema_attributes["name"]
end
solr_schema_version() click to toggle source
# File lib/chef/solr/application/solr.rb, line 158
def solr_schema_version
  schema_attributes["version"]
end
valid_schema_name?() click to toggle source
# File lib/chef/solr/application/solr.rb, line 172
def valid_schema_name?
  solr_schema_name == Chef::Solr::SCHEMA_NAME
end
valid_schema_version?() click to toggle source
# File lib/chef/solr/application/solr.rb, line 176
def valid_schema_version?
  solr_schema_version == Chef::Solr::SCHEMA_VERSION
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.