Class: Chef::Application
- Inherits:
-
Object
- Object
- Chef::Application
- Includes:
- Mixlib::CLI
- Defined in:
- lib/chef/application.rb
Defined Under Namespace
Class Method Summary collapse
- .exit!(msg, err = -1)) ⇒ Object
-
.fatal!(msg, err = -1)) ⇒ Object
Log a fatal error message to both STDERR and the Logger, exit the application.
Instance Method Summary collapse
-
#configure_chef ⇒ Object
Parse the configuration file.
-
#configure_logging ⇒ Object
Initialize and configure the logger.
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#reconfigure ⇒ Object
Reconfigure the application.
-
#run ⇒ Object
Get this party started.
-
#run_application ⇒ Object
Actually run the application.
-
#setup_application ⇒ Object
Called prior to starting the application, by the run method.
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/chef/application.rb', line 26 def initialize super trap("TERM") do Chef::Application.fatal!("SIGTERM received, stopping", 1) end trap("INT") do Chef::Application.fatal!("SIGINT received, stopping", 2) end unless RUBY_PLATFORM =~ /mswin|mingw32|windows/ trap("HUP") do Chef::Log.info("SIGHUP received, reconfiguring") reconfigure end end at_exit do # tear down the logger end # Always switch to a readable directory. Keeps subsequent Dir.chdir() {} # from failing due to permissions when launched as a less privileged user. end |
Class Method Details
Instance Method Details
#configure_chef ⇒ Object
Parse the configuration file
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chef/application.rb', line 66 def configure_chef begin case config[:config_file] when /^(http|https):\/\// Chef::REST.new("", nil, nil).fetch(config[:config_file]) { |f| apply_config(f.path) } else ::File::open(config[:config_file]) { |f| apply_config(f.path) } end rescue SocketError => error Chef::Application.fatal!("Error getting config file #{Chef::Config[:config_file]}", 2) rescue Exception => error Chef::Log.warn("*****************************************") Chef::Log.warn("Can not find config file: #{config[:config_file]}, using defaults.") Chef::Log.warn("#{error.}") Chef::Log.warn("*****************************************") Chef::Config.merge!(config) end end |
#configure_logging ⇒ Object
Initialize and configure the logger
90 91 92 93 |
# File 'lib/chef/application.rb', line 90 def configure_logging Chef::Log.init(Chef::Config[:log_location]) Chef::Log.level = Chef::Config[:log_level] end |
#reconfigure ⇒ Object
Reconfigure the application. You’ll want to override and super this method.
53 54 55 56 |
# File 'lib/chef/application.rb', line 53 def reconfigure configure_chef configure_logging end |
#run ⇒ Object
Get this party started
59 60 61 62 63 |
# File 'lib/chef/application.rb', line 59 def run reconfigure setup_application run_application end |
#run_application ⇒ Object
Actually run the application
101 102 103 |
# File 'lib/chef/application.rb', line 101 def run_application raise Chef::Exceptions::Application, "#{self.to_s}: you must override run_application" end |
#setup_application ⇒ Object
Called prior to starting the application, by the run method
96 97 98 |
# File 'lib/chef/application.rb', line 96 def setup_application raise Chef::Exceptions::Application, "#{self.to_s}: you must override setup_application" end |