Class: 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 |
# 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 trap("HUP") do Chef::Log.info("SIGHUP received, reconfiguring") reconfigure end at_exit do # tear down the logger end end |
Class Method Details
Instance Method Details
#configure_chef ⇒ Object
Parse the configuration file
61 62 63 64 65 66 |
# File 'lib/chef/application.rb', line 61 def configure_chef Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exists?(config[:config_file]) && File.readable?(config[:config_file]) Chef::Config.merge!(config) end |
#configure_logging ⇒ Object
Initialize and configure the logger
69 70 71 72 |
# File 'lib/chef/application.rb', line 69 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.
48 49 50 51 |
# File 'lib/chef/application.rb', line 48 def reconfigure configure_chef configure_logging end |
#run ⇒ Object
Get this party started
54 55 56 57 58 |
# File 'lib/chef/application.rb', line 54 def run reconfigure setup_application run_application end |
#run_application ⇒ Object
Actually run the application
80 81 82 |
# File 'lib/chef/application.rb', line 80 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
75 76 77 |
# File 'lib/chef/application.rb', line 75 def setup_application raise Chef::Exceptions::Application, "#{self.to_s}: you must override setup_application" end |