Class: Chef::Application::Base Deprecated

Inherits:
Chef::Application show all
Includes:
Mixin::ShellOut, ChefConfig::Mixin::DotD, ChefLicensing::CLIFlags::MixlibCLI, LicenseAcceptance::CLIFlags::MixlibCLI
Defined in:
lib/chef/application/base.rb

Overview

Deprecated.

use Chef::Application::Client instead, this will be removed in Chef-16

This is a temporary class being used as a part of an effort to reduce duplication between Chef::Application::Client and Chef::Application::Solo.

If you are looking to make edits to the Client/Solo behavior please make changes here.

If you are looking to reference or subclass this class, use Chef::Application::Client instead. This base class will be removed once the work is complete and external code will break.

Direct Known Subclasses

Client, Solo

Constant Summary collapse

SELF_PIPE =

Mimic self_pipe sleep from Unicorn to capture signals safely

[]
IMMEDIATE_RUN_SIGNAL =
"1".freeze
RECONFIGURE_SIGNAL =
"H".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chef::Application

#apply_extra_config_options, #check_license_acceptance, #chef_config, #chef_configfetcher, #configure_chef, #configure_encoding, #configure_log_location, #configure_logging, debug_stacktrace, #emit_warnings, exit!, fatal!, #force_force_logger, #initialize, #load_config_file, #logger, logger, normalize_exit_code, #reconfigure, #resolve_log_level, #run, #run_chef_client, #set_specific_recipes, use_separate_defaults?, #using_output_formatter?

Constructor Details

This class inherits a constructor from Chef::Application

Instance Attribute Details

#chef_client_jsonObject (readonly)

Returns the value of attribute chef_client_json.



338
339
340
# File 'lib/chef/application/base.rb', line 338

def chef_client_json
  @chef_client_json
end

Class Method Details



340
341
342
343
344
345
346
# File 'lib/chef/application/base.rb', line 340

def self.print_help
  instance = new
  instance.parse_options([])
  puts instance.opt_parser
  puts Chef::Licensing.licensing_help if ChefUtils::Dist::Infra::EXEC == "chef"
  exit 0
end

Instance Method Details

#run_applicationObject

Run the chef client, optionally daemonizing or looping at intervals.



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/chef/application/base.rb', line 372

def run_application
  if ENV["TEST_KITCHEN"]
    puts "Temporarily bypassing licensing check in Kitchen"
  else
    Chef::Licensing.check_software_entitlement! if ChefUtils::Dist::Infra::EXEC == "chef"
  end
  if Chef::Config[:version]
    puts "#{ChefUtils::Dist::Infra::PRODUCT} version: #{::Chef::VERSION}"
  end

  if !Chef::Config[:client_fork] || Chef::Config[:once]
    begin
      # run immediately without interval sleep, or splay
      run_chef_client(Chef::Config[:specific_recipes])
    rescue SystemExit
      raise
    rescue Exception => e
      Chef::Application.fatal!("#{e.class}: #{e.message}", e)
    end
  else
    interval_run_chef_client
  end
end

#setup_applicationObject



348
349
350
# File 'lib/chef/application/base.rb', line 348

def setup_application
  Chef::Daemon.change_privilege
end

#setup_signal_handlersObject



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/chef/application/base.rb', line 352

def setup_signal_handlers
  super

  unless Chef::Platform.windows?
    SELF_PIPE.replace IO.pipe

    trap("USR1") do
      Chef::Log.info("SIGUSR1 received, will run now or after the current run")
      SELF_PIPE[1].putc(IMMEDIATE_RUN_SIGNAL) # wakeup master process from select
    end

    # Override the trap setup in the parent so we can avoid running reconfigure during a run
    trap("HUP") do
      Chef::Log.info("SIGHUP received, will reconfigure now or after the current run")
      SELF_PIPE[1].putc(RECONFIGURE_SIGNAL) # wakeup master process from select
    end
  end
end