Class: Chef::SolrInstaller
- Inherits:
-
Object
- Object
- Chef::SolrInstaller
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/chef/solr/solr_installer.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- PACKAGED_SOLR_DIR =
File.( "../../../../solr", __FILE__)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #chdir(dir, &block) ⇒ Object
- #chef_solr_installed? ⇒ Boolean
- #chown(file) ⇒ Object
- #confirm_overwrite ⇒ Object
- #create_solr_data_dir ⇒ Object
- #create_solr_home ⇒ Object
- #group(message, &block) ⇒ Object
- #indent ⇒ Object
-
#initialize(argv) ⇒ SolrInstaller
constructor
A new instance of SolrInstaller.
- #mkdir_p(directory) ⇒ Object
- #overwriting? ⇒ Boolean
- #rm_rf(path) ⇒ Object
- #run ⇒ Object
- #say(message) ⇒ Object
- #scorch_the_earth ⇒ Object
- #sh(*args) ⇒ Object
- #unpack_solr_jetty ⇒ Object
Constructor Details
#initialize(argv) ⇒ SolrInstaller
Returns a new instance of SolrInstaller.
245 246 247 248 249 |
# File 'lib/chef/solr/solr_installer.rb', line 245 def initialize(argv) @indent = 0 @config = Config.new.configure_from(argv.dup) @overwriting = false end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
243 244 245 |
# File 'lib/chef/solr/solr_installer.rb', line 243 def config @config end |
Instance Method Details
#chdir(dir, &block) ⇒ Object
338 339 340 341 342 343 344 345 |
# File 'lib/chef/solr/solr_installer.rb', line 338 def chdir(dir, &block) say "entering #{dir}" if config.noop? yield if block_given? # still call the block so we get the noop output. else Dir.chdir(dir) { yield if block_given? } end end |
#chef_solr_installed? ⇒ Boolean
255 256 257 |
# File 'lib/chef/solr/solr_installer.rb', line 255 def chef_solr_installed? File.exist?(config.solr_home_path) end |
#chown(file) ⇒ Object
354 355 356 357 358 359 360 361 362 |
# File 'lib/chef/solr/solr_installer.rb', line 354 def chown(file) if config.user msg = "chown -R #{config.user}" msg << ":#{config.group}" if config.group msg << " #{file}" say msg FileUtils.chown_R(config.user, config.group, file) unless config.noop? end end |
#confirm_overwrite ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/chef/solr/solr_installer.rb', line 281 def confirm_overwrite if STDIN.tty? && STDOUT.tty? say "Chef Solr is already installed in #{config.solr_home_path}" print "Do you want to overwrite the current install? All existing Solr data will be lost. [y/n] " unless STDIN.gets =~ /^y/ say "Quitting. Try running this with --noop to see what it will change." exit 1 end else say(<<-FAIL) ERROR: Chef Solr is already installed in #{config.solr_home_path} and you did not use the --force option. Use --force to overwrite an existing installation in a non- interactive terminal. FAIL exit 1 end end |
#create_solr_data_dir ⇒ Object
316 317 318 319 320 321 |
# File 'lib/chef/solr/solr_installer.rb', line 316 def create_solr_data_dir group("Creating Solr Data Directory") do mkdir_p(config.solr_data_path) chown(config.solr_data_path) end end |
#create_solr_home ⇒ Object
307 308 309 310 311 312 313 314 |
# File 'lib/chef/solr/solr_installer.rb', line 307 def create_solr_home group("Creating Solr Home Directory") do mkdir_p(config.solr_home_path) chdir(config.solr_home_path) do sh("tar zxvf #{File.join(PACKAGED_SOLR_DIR, 'solr-home.tar.gz')}") end end end |
#group(message, &block) ⇒ Object
375 376 377 378 |
# File 'lib/chef/solr/solr_installer.rb', line 375 def group(, &block) say() indent(&block) end |
#indent ⇒ Object
369 370 371 372 373 |
# File 'lib/chef/solr/solr_installer.rb', line 369 def indent @indent += 1 yield @indent -= 1 end |
#mkdir_p(directory) ⇒ Object
333 334 335 336 |
# File 'lib/chef/solr/solr_installer.rb', line 333 def mkdir_p(directory) say "mkdir -p #{directory}" FileUtils.mkdir_p(directory, :mode => 0755) unless config.noop? end |
#overwriting? ⇒ Boolean
251 252 253 |
# File 'lib/chef/solr/solr_installer.rb', line 251 def overwriting? @overwriting end |
#rm_rf(path) ⇒ Object
364 365 366 367 |
# File 'lib/chef/solr/solr_installer.rb', line 364 def rm_rf(path) say "rm -rf #{path}" FileUtils.rm_rf(path) unless config.noop? end |
#run ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/chef/solr/solr_installer.rb', line 259 def run say '' say "*** DRY RUN ***" if config.noop? if chef_solr_installed? @overwriting = true confirm_overwrite unless config.force? || config.noop? scorch_the_earth end create_solr_home create_solr_data_dir unpack_solr_jetty say "" say "Successfully installed Chef Solr." if overwriting? say "You can restore your search index using `knife index rebuild`" end end |
#say(message) ⇒ Object
380 381 382 |
# File 'lib/chef/solr/solr_installer.rb', line 380 def say() puts "#{' ' * (2 * @indent)}#{}" end |
#scorch_the_earth ⇒ Object
299 300 301 302 303 304 305 |
# File 'lib/chef/solr/solr_installer.rb', line 299 def scorch_the_earth group("Removing the existing Chef Solr installation") do rm_rf(config.solr_home_path) rm_rf(config.solr_jetty_path) rm_rf(config.solr_data_path) end end |
#sh(*args) ⇒ Object
347 348 349 350 351 352 |
# File 'lib/chef/solr/solr_installer.rb', line 347 def sh(*args) opts = args[1, args.size - 1] opts_msg = opts.empty? ? '' : " #{opts.to_s}" say "#{args.first}#{opts_msg}" shell_out!(*(args << {:cwd => false})) unless config.noop? end |
#unpack_solr_jetty ⇒ Object
323 324 325 326 327 328 329 330 331 |
# File 'lib/chef/solr/solr_installer.rb', line 323 def unpack_solr_jetty group("Unpacking Solr Jetty") do mkdir_p(config.solr_jetty_path) chdir(config.solr_jetty_path) do sh("tar zxvf #{File.join(PACKAGED_SOLR_DIR, 'solr-jetty.tar.gz')}") end chown(config.solr_jetty_path) end end |