From 9dcf27ced5949a04a98c76614876aa0f475e98fe Mon Sep 17 00:00:00 2001 From: Amarante Date: Fri, 24 Nov 2017 09:38:45 +0200 Subject: [PATCH 1/2] Adding a slight retry whenever streaming the agent from S3. --- bin/install | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/install b/bin/install index 717a2337..957d6cda 100755 --- a/bin/install +++ b/bin/install @@ -93,7 +93,7 @@ EOF def check_ruby_version_and_symlink @log.info("Starting Ruby version check.") actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}[0,2] - + supported_ruby_versions.each do |version| if ((actual_ruby_version <=> version.split('.').map{|s|s.to_i}) == 0) return File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["RUBY_INSTALL_NAME"] + RbConfig::CONFIG["EXEEXT"]) @@ -109,13 +109,13 @@ EOF end end - unsupported_ruby_version_error + unsupported_ruby_version_error exit(1) end def unsupported_ruby_version_error @log.error("Current running Ruby version for "+ENV['USER']+" is "+RUBY_VERSION+", but Ruby version 2.x needs to be installed.") - @log.error('If you already have the proper Ruby version installed, please either create a symlink to /usr/bin/ruby2.x,') + @log.error('If you already have the proper Ruby version installed, please either create a symlink to /usr/bin/ruby2.x,') @log.error( "or run this install script with right interpreter. Otherwise please install Ruby 2.x for "+ENV['USER']+" user.") @log.error('You can get more information by running the script with --help option.') end @@ -244,11 +244,13 @@ EOF # stream package file to disk begin + retries ||= 0 uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy) do |s3| package_file.write(s3.read) end rescue OpenURI::HTTPError => e - @log.error("Could not find package to download at '#{uri.to_s}'") + retry if (retries +=1) < 5 + @log.error("Could not find package to download at '#{uri.to_s}' - Attempt '#{retries.to_s}'") exit(1) end end From 7ee90c5ccaf25555603712e61dde4d4d4d188a84 Mon Sep 17 00:00:00 2001 From: Amarante Date: Fri, 19 Jan 2018 11:43:41 +0200 Subject: [PATCH 2/2] Adding Exponential backoff while streaming file from S3. --- bin/install | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/install b/bin/install index 957d6cda..7cb02462 100755 --- a/bin/install +++ b/bin/install @@ -243,15 +243,22 @@ EOF uri = get_s3_uri(region, bucket, key) # stream package file to disk + retries ||= 0 + exceptions = [OpenURI::HTTPError, OpenSSL::SSL::SSLError] begin - retries ||= 0 uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy) do |s3| - package_file.write(s3.read) + package_file.write(s3.read) + end + rescue *exceptions => e + @log.error("Could not find package to download at '#{uri.to_s}' - Retrying... Attempt: '#{retries.to_s}'") + if (retries < 5) + sleep 2 ** retries + retries += 1 + retry + else + @log.error("Could not download CodeDeploy Agent Package. Exiting Install script.") + exit(1) end - rescue OpenURI::HTTPError => e - retry if (retries +=1) < 5 - @log.error("Could not find package to download at '#{uri.to_s}' - Attempt '#{retries.to_s}'") - exit(1) end end