Class: Chef::Application::Client
- Inherits:
-
Chef::Application
- Object
- Chef::Application
- Chef::Application::Client
- 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
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 inherited from Chef::Application
#auto_log_level?, #configure_chef, #configure_encoding, #configure_proxy_environment_variables, #configure_stdout_logger, debug_stacktrace, exit!, fatal!, #initialize, #resolve_log_level, #run, #run_chef_client, #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.
248 249 250 |
# File 'lib/chef/application/client.rb', line 248 def chef_client_json @chef_client_json end |
Instance Method Details
#configure_logging ⇒ Object
294 295 296 297 298 |
# File 'lib/chef/application/client.rb', line 294 def configure_logging super Mixlib::Authentication::Log.use_log_devices( Chef::Log ) Ohai::Log.use_log_devices( Chef::Log ) end |
#load_config_file ⇒ Object
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/chef/application/client.rb', line 283 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 super end |
#reconfigure ⇒ Object
Reconfigure the chef client Re-open the JSON attributes and load them into the node
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/chef/application/client.rb', line 252 def reconfigure super Chef::Config[:specific_recipes] = cli_arguments.map { |file| File.(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 Chef::Application.fatal!() if !Chef::Config[:client_fork] && Chef::Config[:interval] if Chef::Config[:json_attribs] config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs]) @chef_client_json = config_fetcher.fetch_json end end |
#run_application ⇒ Object
Run the chef client, optionally daemonizing or looping at intervals.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/chef/application/client.rb', line 318 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.}", 1) end else interval_run_chef_client end end |
#setup_application ⇒ Object
300 301 302 |
# File 'lib/chef/application/client.rb', line 300 def setup_application Chef::Daemon.change_privilege end |
#setup_signal_handlers ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/chef/application/client.rb', line 304 def setup_signal_handlers super 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 end end |