Class: Chef::Application::Client

Inherits:
Base show all
Defined in:
lib/chef/application/client.rb

Overview

DO NOT MAKE EDITS, see Chef::Application::Base

External code may call / subclass or make references to this class.

Constant Summary

Constants inherited from Base

Base::IMMEDIATE_RUN_SIGNAL, Base::RECONFIGURE_SIGNAL, Base::SELF_PIPE

Instance Attribute Summary

Attributes inherited from Base

#chef_client_json

Instance Method Summary collapse

Methods inherited from Base

#run_application, #setup_application, #setup_signal_handlers

Methods included from Mixin::ShellOut

apply_default_env, maybe_add_timeout, #shell_out, #shell_out!

Methods inherited from Chef::Application

#apply_extra_config_options, #auto_log_level?, #check_license_acceptance, #chef_config, #chef_configfetcher, #configure_chef, #configure_encoding, #configure_log_location, #configure_stdout_logger, debug_stacktrace, #emit_warnings, exit!, fatal!, #initialize, #logger, logger, normalize_exit_code, #resolve_log_level, #run, #run_application, #run_chef_client, #set_specific_recipes, #setup_application, #setup_signal_handlers, use_separate_defaults?, #using_output_formatter?, #want_additional_logger?

Constructor Details

This class inherits a constructor from Chef::Application

Instance Method Details

#configure_loggingObject



161
162
163
164
165
# File 'lib/chef/application/client.rb', line 161

def configure_logging
  super
  Mixlib::Authentication::Log.use_log_devices( Chef::Log )
  Ohai::Log.use_log_devices( Chef::Log )
end

#load_config_fileObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/chef/application/client.rb', line 145

def load_config_file
  if !config.key?(:config_file) && !config[:disable_config]
    if config[:local_mode]
      config[:config_file] = Chef::WorkstationConfigLoader.new(nil, Chef::Log).config_location
    else
      config[:config_file] = Chef::Config.platform_specific_path("#{Chef::Dist::CONF_DIR}/client.rb")
    end
  end

  # Load the client.rb configuration
  super

  # Load all config files in client.d
  load_dot_d(Chef::Config[:client_d_dir]) if Chef::Config[:client_d_dir]
end

#reconfigureObject

Reconfigure the chef client Re-open the JSON attributes and load them into the node



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
# File 'lib/chef/application/client.rb', line 68

def reconfigure
  super

  raise Chef::Exceptions::PIDFileLockfileMatch if Chef::Util::PathHelper.paths_eql? (Chef::Config[:pid_file] || "" ), (Chef::Config[:lockfile] || "")

  set_specific_recipes

  Chef::Config[:fips] = config[:fips] if config.key? :fips

  Chef::Config[:chef_server_url] = config[:chef_server_url] if config.key? :chef_server_url

  Chef::Config.local_mode = config[:local_mode] if config.key?(:local_mode)

  if Chef::Config.key?(:chef_repo_path) && Chef::Config.chef_repo_path.nil?
    Chef::Config.delete(:chef_repo_path)
    Chef::Log.warn "chef_repo_path was set in a config file but was empty. Assuming #{Chef::Config.chef_repo_path}"
  end

  if Chef::Config.local_mode && !Chef::Config.key?(:cookbook_path) && !Chef::Config.key?(:chef_repo_path)
    Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
  end

  if Chef::Config[:recipe_url]
    if !Chef::Config.local_mode
      Chef::Application.fatal!("recipe-url can be used only in local-mode")
    else
      if Chef::Config[:delete_entire_chef_repo]
        Chef::Log.trace "Cleanup path #{Chef::Config.chef_repo_path} before extract recipes into it"
        FileUtils.rm_rf(Chef::Config.chef_repo_path, secure: true)
      end
      Chef::Log.trace "Creating path #{Chef::Config.chef_repo_path} to extract recipes into"
      FileUtils.mkdir_p(Chef::Config.chef_repo_path)
      tarball_path = File.join(Chef::Config.chef_repo_path, "recipes.tgz")
      fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path)
      Mixlib::Archive.new(tarball_path).extract(Chef::Config.chef_repo_path, perms: false, ignore: /^\.$/)
      config_path = File.join(Chef::Config.chef_repo_path, "#{Chef::Dist::USER_CONF_DIR}/config.rb")
      Chef::Config.from_string(IO.read(config_path), config_path) if File.file?(config_path)
    end
  end

  Chef::Config.chef_zero.host = config[:chef_zero_host] if config[:chef_zero_host]
  Chef::Config.chef_zero.port = config[:chef_zero_port] if config[:chef_zero_port]

  if config[:target] || Chef::Config.target
    Chef::Config.target_mode.enabled = true
    Chef::Config.target_mode.host = config[:target] || Chef::Config.target
    Chef::Config.node_name = Chef::Config.target_mode.host unless Chef::Config.node_name
  end

  if Chef::Config[:daemonize]
    Chef::Config[:interval] ||= 1800
  end

  if Chef::Config[:once]
    Chef::Config[:interval] = nil
    Chef::Config[:splay] = nil
  end

  # supervisor processes are enabled by default for interval-running processes but not for one-shot runs
  if Chef::Config[:client_fork].nil?
    Chef::Config[:client_fork] = !!Chef::Config[:interval]
  end

  if Chef::Config[:interval]
    if Chef::Platform.windows?
      Chef::Application.fatal!(windows_interval_error_message)
    elsif !Chef::Config[:client_fork]
      Chef::Application.fatal!(unforked_interval_error_message)
    end
  end

  if Chef::Config[:json_attribs]
    config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs])
    @chef_client_json = config_fetcher.fetch_json
  end
end