summaryrefslogtreecommitdiff
path: root/lib/chef/application.rb
diff options
context:
space:
mode:
authorSteven Murawski <steven.murawski@gmail.com>2016-02-18 14:58:32 -0600
committerSteven Murawski <steven.murawski@gmail.com>2016-05-23 13:32:49 -0500
commite24b8e2cd67aef572fde184e8b07d48333184b29 (patch)
tree2b1f6507104149182791436be30561be3be1aef2 /lib/chef/application.rb
parente4bca443a3ddca6381275a1a252de04f5e4883c4 (diff)
downloadchef-e24b8e2cd67aef572fde184e8b07d48333184b29.tar.gz
* define exit codes
* exit code functional specs * audit exit codes * reboot now/reboot failed/reboot pending exit codes * Deal with forked and unforked process and get the right exit code * Reboot Now should really be reboot scheduled * pass exception rather than exit code * updated with sigint and sigterm * support legacy fatal!("", 2) behavior * fixup all fatal! and exit! calls
Diffstat (limited to 'lib/chef/application.rb')
-rw-r--r--lib/chef/application.rb23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index 7dbffd8dec..f8df71f723 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -27,6 +27,7 @@ require "chef/platform"
require "mixlib/cli"
require "tmpdir"
require "rbconfig"
+require "chef/application/exit_code"
class Chef
class Application
@@ -60,11 +61,11 @@ class Chef
def setup_signal_handlers
trap("INT") do
- Chef::Application.fatal!("SIGINT received, stopping", 2)
+ Chef::Application.fatal!("SIGINT received, stopping", Chef::Exceptions::SigInt.new)
end
trap("TERM") do
- Chef::Application.fatal!("SIGTERM received, stopping", 3)
+ Chef::Application.fatal!("SIGTERM received, stopping", Chef::Exceptions::SigTerm.new)
end
unless Chef::Platform.windows?
@@ -149,7 +150,7 @@ class Chef
Chef::Log.level = resolve_log_level
rescue StandardError => error
Chef::Log.fatal("Failed to open or create log file at #{Chef::Config[:log_location]}: #{error.class} (#{error.message})")
- Chef::Application.fatal!("Aborting due to invalid 'log_location' configuration", 2)
+ Chef::Application.fatal!("Aborting due to invalid 'log_location' configuration", error)
end
# Turn `log_location :syslog` and `log_location :win_evt` into the
@@ -285,7 +286,7 @@ class Chef
@chef_client.run
rescue Exception => e
Chef::Log.error(e.to_s)
- exit 1
+ exit Chef::Application.normalize_exit_code(e)
else
exit 0
end
@@ -314,7 +315,7 @@ class Chef
Chef::Log.fatal("Configuration error #{error.class}: #{error.message}")
filtered_trace = error.backtrace.grep(/#{Regexp.escape(config_file_path)}/)
filtered_trace.each { |line| Chef::Log.fatal(" " + line ) }
- Chef::Application.fatal!("Aborting due to error in '#{config_file_path}'", 2)
+ Chef::Application.fatal!("Aborting due to error in '#{config_file_path}'", error)
end
# This is a hook for testing
@@ -341,15 +342,19 @@ class Chef
true
end
+ def normalize_exit_code(exit_code)
+ Chef::Application::ExitCode.normalize_exit_code(exit_code)
+ end
+
# Log a fatal error message to both STDERR and the Logger, exit the application
- def fatal!(msg, err = -1)
+ def fatal!(msg, err = nil)
Chef::Log.fatal(msg)
- Process.exit err
+ Process.exit(normalize_exit_code(err))
end
- def exit!(msg, err = -1)
+ def exit!(msg, err = nil)
Chef::Log.debug(msg)
- Process.exit err
+ Process.exit(normalize_exit_code(err))
end
end