diff options
author | danielsdeleo <dan@opscode.com> | 2013-07-05 16:13:47 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-07-05 16:13:47 -0700 |
commit | af181c74a1b39c123400b1027285e883e71060c3 (patch) | |
tree | e7c7e7813ba658e8b55666a167a12a26f454b520 | |
parent | 8505ed76e545af010e3d66b2882732fcfffc0084 (diff) | |
parent | 1d7d704c1df4f42627ff0d08bb2b8a4d21782d27 (diff) | |
download | chef-af181c74a1b39c123400b1027285e883e71060c3.tar.gz |
Merge branch 'CHEF-4357'
-rw-r--r-- | lib/chef/application/client.rb | 2 | ||||
-rw-r--r-- | lib/chef/application/solo.rb | 1 | ||||
-rw-r--r-- | lib/chef/application/windows_service.rb | 1 | ||||
-rw-r--r-- | lib/chef/client.rb | 34 | ||||
-rw-r--r-- | lib/chef/exceptions.rb | 2 |
5 files changed, 30 insertions, 10 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 42a7744795..b08a795697 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -316,7 +316,6 @@ class Chef::Application::Client < Chef::Application rescue Exception => e if Chef::Config[:interval] Chef::Log.error("#{e.class}: #{e}") - Chef::Application.debug_stacktrace(e) Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again") unless SELF_PIPE.empty? client_sleep Chef::Config[:interval] @@ -326,7 +325,6 @@ class Chef::Application::Client < Chef::Application end retry else - Chef::Application.debug_stacktrace(e) Chef::Application.fatal!("#{e.class}: #{e.message}", 1) end end diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index 7e316dc260..5e3fe90607 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -253,7 +253,6 @@ class Chef::Application::Solo < Chef::Application sleep Chef::Config[:interval] retry else - Chef::Application.debug_stacktrace(e) Chef::Application.fatal!("#{e.class}: #{e.message}", 1) end end diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 5b77a44392..85a18c7a17 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -99,7 +99,6 @@ class Chef Chef::Log.error("#{e.class}: #{e}") rescue Exception => e Chef::Log.error("#{e.class}: #{e}") - Chef::Application.debug_stacktrace(e) end end end diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 80c6dd5ecd..ceb0873079 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -191,20 +191,41 @@ class Chef if(Chef::Config[:client_fork] && Process.respond_to?(:fork) && !Chef::Platform.windows?) Chef::Log.info "Forking chef instance to converge..." pid = fork do - Chef::Log.info "Forked instance now converging" - do_run - exit + [:INT, :TERM].each {|s| trap(s, "EXIT") } + client_solo = Chef::Config[:solo] ? "chef-solo" : "chef-client" + $0 = "#{client_solo} worker: ppid=#{Process.ppid};start=#{Time.new.strftime("%R:%S")};" + begin + Chef::Log.debug "Forked instance now converging" + do_run + rescue Exception + exit 1 + else + exit 0 + end end - Chef::Log.info "Fork successful. Waiting for new chef pid: #{pid}" + Chef::Log.debug "Fork successful. Waiting for new chef pid: #{pid}" result = Process.waitpid2(pid) - raise "Forked convergence run failed" unless result.last.success? - Chef::Log.info "Forked child successfully reaped (pid: #{pid})" + handle_child_exit(result) + Chef::Log.debug "Forked child successfully reaped (pid: #{pid})" true else do_run end end + def handle_child_exit(pid_and_status) + status = pid_and_status[1] + return true if status.success? + message = if status.signaled? + "Chef run process terminated by signal #{status.termsig} (#{Signal.list.invert[status.termsig]})" + else + "Chef run process exited unsuccessfully (exit code #{status.exitstatus})" + end + raise Exceptions::ChildConvergeError, message + end + + + # Configures the Chef::Cookbook::FileVendor class to fetch file from the # server or disk as appropriate, creates the run context for this run, and # sanity checks the cookbook collection. @@ -488,6 +509,7 @@ class Chef run_status.exception = e run_failed end + Chef::Application.debug_stacktrace(e) @events.run_failed(e) raise ensure diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index c0a5a185d6..99054eb254 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -160,6 +160,8 @@ class Chef # the symlink that is there either loops or points to a nonexistent file class InvalidSymlink < RuntimeError; end + class ChildConvergeError < RuntimeError; end + class MissingRole < RuntimeError NULL = Object.new |