This file is indexed.

/usr/lib/ruby/vendor_ruby/chef/solr/application/solr.rb is in chef-solr 10.12.0+dfsg-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#
# Author:: AJ Christensen (<aj@opscode.com)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


require 'rexml/document'
require 'chef/log'
require 'chef/config'
require 'chef/application'
require 'chef/daemon'
require 'chef/solr'

class Chef
  class Solr
    class Application
      class Solr < Chef::Application

        attr_accessor :logfile

        option :config_file,
          :short => "-c CONFIG",
          :long  => "--config CONFIG",
          :default => "/etc/chef/solr.rb",
          :description => "The configuration file to use"

        option :log_level,
          :short        => "-l LEVEL",
          :long         => "--log_level LEVEL",
          :description  => "Set the log level (debug, info, warn, error, fatal)",
          :proc         => lambda { |l| l.to_sym }

        option :log_location,
          :short        => "-L LOGLOCATION",
          :long         => "--logfile LOGLOCATION",
          :description  => "Set the log file location, defaults to STDOUT - recommended for daemonizing",
          :proc         => nil

        option :pid_file,
          :short        => "-P PID_FILE",
          :long         => "--pid PIDFILE",
          :description  => "Set the PID file location, defaults to /tmp/chef-solr.pid",
          :proc         => nil

        option :help,
          :short        => "-h",
          :long         => "--help",
          :description  => "Show this message",
          :on           => :tail,
          :boolean      => true,
          :show_options => true,
          :exit         => 0

        option :user,
          :short => "-u USER",
          :long => "--user USER",
          :description => "User to set privilege to",
          :proc => nil

        option :group,
          :short => "-g GROUP",
          :long => "--group GROUP",
          :description => "Group to set privilege to",
          :proc => nil

        option :daemonize,
          :short => "-d",
          :long => "--daemonize",
          :description => "Daemonize the process",
          :proc => lambda { |p| true }

        option :solr_jetty_path,
          :short => "-W PATH",
          :long => "--solr-jetty-dir PATH",
          :description => "Where to place the Solr Jetty instance"

        option :solr_data_path,
          :short => "-D PATH",
          :long => "--solr-data-dir PATH",
          :description => "Where the Solr data lives"

        option :solr_home_path,
          :short => "-H PATH",
          :long => "--solr-home-dir PATH",
          :description => "Solr home directory"

        option :solr_heap_size,
          :short => "-x SIZE",
          :long => "--solor-heap-size SIZE",
          :description => "Set the size of the Java Heap"

        option :solr_java_opts,
          :short => "-j OPTS",
          :long => "--java-opts OPTS",
          :description => "Raw options passed to Java"

        option :version,
          :short => "-v",
          :long => "--version",
          :description => "Show chef-solr version",
          :boolean => true,
          :proc => lambda {|v| puts "chef-solr: #{::Chef::Solr::VERSION}"},
          :exit => 0

        def initialize
          super
        end

        def schema_file_path
          @schema_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'schema.xml')
        end

        def solr_config_file_path
          @solr_config_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'solrconfig.xml')
        end

        def schema_document
          @schema_document ||= begin
            File.open(schema_file_path, 'r') do |xmlsux|
              REXML::Document.new(xmlsux)
            end
          end
        end

        def config_document
          @config_document ||=begin
            File.open(solr_config_file_path, 'r') do |xmlsux|
              REXML::Document.new(xmlsux)
            end
          end
        end

        def schema_attributes
          @schema_attributes ||= REXML::XPath.first(schema_document, '/schema').attributes
        end

        def solr_main_index_elements
          location = '/config/mainIndex/'
          @solr_main_index_elements ||= REXML::XPath.first(config_document, location).elements
        end

        def solr_schema_name
          schema_attributes["name"]
        end

        def solr_schema_version
          schema_attributes["version"]
        end

        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

        def valid_schema_name?
          solr_schema_name == Chef::Solr::SCHEMA_NAME
        end

        def valid_schema_version?
          solr_schema_version == Chef::Solr::SCHEMA_VERSION
        end

        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

        def solr_home_exist?
          File.directory?(Chef::Config[:solr_home_path])
        end

        def solr_data_dir_exist?
          File.directory?(Chef::Config[:solr_data_path])
        end

        def solr_jetty_home_exist?
          File.directory?(Chef::Config[:solr_jetty_path])
        end

        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

        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

        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

        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

        def close_and_reopen_log_file
          Chef::Log.close

          STDOUT.reopen(@logfile)
          STDERR.reopen(@logfile)
        end

      end
    end
  end
end