diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mixlib/shellout.rb | 2 | ||||
-rw-r--r-- | lib/mixlib/shellout/unix.rb | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb index a267162..66faa40 100644 --- a/lib/mixlib/shellout.rb +++ b/lib/mixlib/shellout.rb @@ -154,6 +154,7 @@ module Mixlib @environment = DEFAULT_ENVIRONMENT @cwd = nil @valid_exit_codes = [0] + @terminate_reason = nil if command_args.last.is_a?(Hash) parse_options(command_args.pop) @@ -191,6 +192,7 @@ module Mixlib # results when the command exited with an unexpected status. def format_for_exception msg = "" + msg << "#{@terminate_reason}\n" if @terminate_reason msg << "---- Begin output of #{command} ----\n" msg << "STDOUT: #{stdout.strip}\n" msg << "STDERR: #{stderr.strip}\n" diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb index 2ffa5cd..15ead60 100644 --- a/lib/mixlib/shellout/unix.rb +++ b/lib/mixlib/shellout/unix.rb @@ -67,7 +67,7 @@ module Mixlib # read anything it wrote when we killed it attempt_buffer_read # raise - raise CommandTimeout, "command timed out:\n#{format_for_exception}" + raise CommandTimeout, "Command timed out after #{@execution_time.to_i}s:\n#{format_for_exception}" end end @@ -302,10 +302,12 @@ module Mixlib def reap_errant_child return if attempt_reap + @terminate_reason = "Command execeded allowed execution time, killed by TERM signal." logger.error("Command execeded allowed execution time, sending TERM") if logger Process.kill(:TERM, @child_pid) sleep 3 return if attempt_reap + @terminate_reason = "Command execeded allowed execution time, did not respond to TERM. Killed by KILL signal." logger.error("Command did not exit from TERM, sending KILL") if logger Process.kill(:KILL, @child_pid) reap |