Mimic self_pipe sleep from Unicorn to capture signals safely
# File lib/chef/application/client.rb, line 288 def configure_logging super Mixlib::Authentication::Log.use_log_devices( Chef::Log ) Ohai::Log.use_log_devices( Chef::Log ) end
# File lib/chef/application/client.rb, line 275 def load_config_file Chef::Config.config_file_jail = config[:config_file_jail] if config[:config_file_jail] if !config.has_key?(:config_file) if config[:local_mode] require 'chef/knife' config[:config_file] = Chef::Knife.locate_config_file else config[:config_file] = Chef::Config.platform_specific_path("/etc/chef/client.rb") end end super end
Reconfigure the chef client Re-open the JSON attributes and load them into the node
# File lib/chef/application/client.rb, line 246 def reconfigure super Chef::Config[:specific_recipes] = cli_arguments.map { |file| File.expand_path(file) } 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.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 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 if Chef::Config[:json_attribs] config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs]) @chef_client_json = config_fetcher.fetch_json end end
Run the chef client, optionally daemonizing or looping at intervals.
# File lib/chef/application/client.rb, line 299 def run_application unless Chef::Platform.windows? SELF_PIPE.replace IO.pipe trap("USR1") do Chef::Log.info("SIGUSR1 received, waking up") SELF_PIPE[1].putc(IMMEDIATE_RUN_SIGNAL) # wakeup master process from select end # see CHEF-5172 if Chef::Config[:daemonize] || Chef::Config[:interval] trap("TERM") do Chef::Log.info("SIGTERM received, exiting gracefully") SELF_PIPE[1].putc(GRACEFUL_EXIT_SIGNAL) end end end if Chef::Config[:version] puts "Chef version: #{::Chef::VERSION}" end if Chef::Config[:daemonize] Chef::Daemon.daemonize("chef-client") end signal = nil loop do begin Chef::Application.exit!("Exiting", 0) if signal == GRACEFUL_EXIT_SIGNAL if Chef::Config[:splay] and signal != IMMEDIATE_RUN_SIGNAL splay = rand Chef::Config[:splay] Chef::Log.debug("Splay sleep #{splay} seconds") sleep splay end signal = nil run_chef_client(Chef::Config[:specific_recipes]) if Chef::Config[:interval] Chef::Log.debug("Sleeping for #{Chef::Config[:interval]} seconds") signal = interval_sleep else Chef::Application.exit! "Exiting", 0 end rescue SystemExit => e raise rescue Exception => e if Chef::Config[:interval] Chef::Log.error("#{e.class}: #{e}") Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again") signal = interval_sleep retry else Chef::Application.fatal!("#{e.class}: #{e.message}", 1) end end end end
Generated with the Darkfish Rdoc Generator 2.