Class: Chef::Application::Client
- Inherits:
-
Chef::Application
- Object
- Chef::Application
- Chef::Application::Client
- Includes:
- Mixin::ShellOut, ChefConfig::Mixin::DotD
- Defined in:
- lib/chef/application/client.rb
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
-
#chef_client_json ⇒ Object
readonly
Returns the value of attribute chef_client_json.
Instance Method Summary collapse
- #configure_logging ⇒ Object
- #load_config_file ⇒ Object
-
#reconfigure ⇒ Object
Reconfigure the chef client Re-open the JSON attributes and load them into the node.
-
#run_application ⇒ Object
Run the chef client, optionally daemonizing or looping at intervals.
- #setup_application ⇒ Object
- #setup_signal_handlers ⇒ Object
Methods included from Mixin::ShellOut
#a_to_s, #clean_array, #shell_out, #shell_out!, #shell_out_compact, #shell_out_compact!, #shell_out_compact_timeout, #shell_out_compact_timeout!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Methods included from Mixin::PathSanity
#enforce_path_sanity, #sanitized_path
Methods inherited from Chef::Application
#apply_extra_config_options, #auto_log_level?, #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_chef_client, #set_specific_recipes, use_separate_defaults?, #using_output_formatter?, #want_additional_logger?
Constructor Details
This class inherits a constructor from Chef::Application
Instance Attribute Details
#chef_client_json ⇒ Object (readonly)
Returns the value of attribute chef_client_json.
308 309 310 |
# File 'lib/chef/application/client.rb', line 308 def chef_client_json @chef_client_json end |
Instance Method Details
#configure_logging ⇒ Object
402 403 404 405 406 |
# File 'lib/chef/application/client.rb', line 402 def configure_logging super Mixlib::Authentication::Log.use_log_devices( Chef::Log ) Ohai::Log.use_log_devices( Chef::Log ) end |
#load_config_file ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/chef/application/client.rb', line 386 def load_config_file if !config.has_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("/etc/chef/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 |
#reconfigure ⇒ Object
Reconfigure the chef client Re-open the JSON attributes and load them into the node
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/chef/application/client.rb', line 312 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.has_key? :fips Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url Chef::Config.local_mode = config[:local_mode] if config.has_key?(:local_mode) if Chef::Config.has_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.has_key?(:cookbook_path) && !Chef::Config.has_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!("chef-client 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(recipes_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/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 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[:client_fork] && Chef::Config[:interval] && !Chef::Platform.windows? Chef::Application.fatal!() end if Chef::Config[:json_attribs] config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs]) @chef_client_json = config_fetcher.fetch_json end if mode = config[:audit_mode] || Chef::Config[:audit_mode] expected_modes = [:enabled, :disabled, :audit_only] unless expected_modes.include?(mode) Chef::Application.fatal!(unrecognized_audit_mode(mode)) end end end |
#run_application ⇒ Object
Run the chef client, optionally daemonizing or looping at intervals.
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/chef/application/client.rb', line 432 def run_application if Chef::Config[:version] puts "Chef 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_application ⇒ Object
408 409 410 |
# File 'lib/chef/application/client.rb', line 408 def setup_application Chef::Daemon.change_privilege end |
#setup_signal_handlers ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/chef/application/client.rb', line 412 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 |