in lib/instance_agent/plugins/codedeploy/hook_executor.rb [144:185]
def execute_script(script, script_log_file)
script_command = InstanceAgent::Platform.util.prepare_script_command(script, script_absolute_path(script))
log_script("Script - " + script.location + "\n", script_log_file)
exit_status = 1
signal = nil
if !InstanceAgent::Platform.util.supports_process_groups?
open3_options = {}
signal = 'KILL'
else
open3_options = {:pgroup => true}
signal = '-TERM'
end
Open3.popen3(@child_envs, script_command, open3_options) do |stdin, stdout, stderr, wait_thr|
stdin.close
stdout_thread = Thread.new{stdout.each_line { |line| log_script("[stdout]" + line.to_s, script_log_file)}}
stderr_thread = Thread.new{stderr.each_line { |line| log_script("[stderr]" + line.to_s, script_log_file)}}
thread_joiner = InstanceAgent::ThreadJoiner.new(script.timeout)
thread_joiner.joinOrFail(wait_thr) do
Process.kill(signal, wait_thr.pid)
raise Timeout::Error
end
thread_joiner.joinOrFail(stdout_thread) do
script_error = "Script at specified location: #{script.location} failed to close STDOUT"
log :error, script_error
raise ScriptError.new(ScriptError::OUTPUTS_LEFT_OPEN_CODE, script.location, @script_log), script_error
end
thread_joiner.joinOrFail(stderr_thread) do
script_error = "Script at specified location: #{script.location} failed to close STDERR"
log :error, script_error
raise ScriptError.new(ScriptError::OUTPUTS_LEFT_OPEN_CODE, script.location, @script_log), script_error
end
exit_status = wait_thr.value.exitstatus
end
if(exit_status != 0)
script_error = "#{script_error_prefix(script.location, script.runas)} failed with exit code #{exit_status.to_s}"
raise ScriptError.new(ScriptError::SCRIPT_FAILED_CODE, script.location, @script_log), script_error
end
end