Class: Chef::Application::Base Deprecated

Inherits:
Chef::Application show all
Includes:
Mixin::ShellOut, ChefConfig::Mixin::DotD, 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

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


318
319
320
# File 'lib/chef/application/base.rb', line 318

def chef_client_json
  @chef_client_json
end

Instance Method Details

#run_applicationObject

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


344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/chef/application/base.rb', line 344

def run_application
  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


320
321
322
# File 'lib/chef/application/base.rb', line 320

def setup_application
  Chef::Daemon.change_privilege
end

#setup_signal_handlersObject


324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/chef/application/base.rb', line 324

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