From 37f9b09414ea34209b1494c8deeec8013b3546b2 Mon Sep 17 00:00:00 2001 From: Myers Carpenter Date: Mon, 16 Sep 2013 13:41:15 -0400 Subject: [PATCH 1/4] So that we can get more verbose error messages, Use .error! to report errors, rather than a check for exit_code 0. --- providers/ark.rb | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/providers/ark.rb b/providers/ark.rb index db0b3b14..6246d3c1 100644 --- a/providers/ark.rb +++ b/providers/ark.rb @@ -134,31 +134,23 @@ def download_direct_from_oracle(tarball_name, new_resource) cp "#{Chef::Config[:file_cache_path]}/#{tarball_name}" . ; bash ./#{tarball_name} -noregister ] ) - unless cmd.exitstatus == 0 - Chef::Application.fatal!("Failed to extract file #{tarball_name}!") - end + cmd.error! when /^.*\.zip/ cmd = shell_out( %Q[ unzip "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -d "#{tmpdir}" ] ) - unless cmd.exitstatus == 0 - Chef::Application.fatal!("Failed to extract file #{tarball_name}!") - end + cmd.error! when /^.*\.(tar.gz|tgz)/ cmd = shell_out( %Q[ tar xvzf "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -C "#{tmpdir}" ] ) - unless cmd.exitstatus == 0 - Chef::Application.fatal!("Failed to extract file #{tarball_name}!") - end + cmd.error! end cmd = shell_out( %Q[ mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" ] ) - unless cmd.exitstatus == 0 - Chef::Application.fatal!(%Q[ Command \' mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" \' failed ]) - end + cmd.error! FileUtils.rm_r tmpdir end new_resource.updated_by_last_action(true) @@ -212,9 +204,7 @@ def download_direct_from_oracle(tarball_name, new_resource) converge_by(description) do Chef::Log.debug "Adding alternative for #{cmd}" install_cmd = shell_out("update-alternatives --install #{bin_path} #{cmd} #{alt_path} #{priority}") - unless install_cmd.exitstatus == 0 - Chef::Application.fatal!(%Q[ set alternative failed ]) - end + install_cmd.error! end new_resource.updated_by_last_action(true) end @@ -227,9 +217,7 @@ def download_direct_from_oracle(tarball_name, new_resource) converge_by(description) do Chef::Log.debug "Setting alternative for #{cmd}" set_cmd = shell_out("update-alternatives --set #{cmd} #{alt_path}").run_command - unless set_cmd.exitstatus == 0 - Chef::Application.fatal!(%Q[ set alternative failed ]) - end + set_cmd.error! end new_resource.updated_by_last_action(true) end From e6563c0a204973cc85427947553264b0b73048bd Mon Sep 17 00:00:00 2001 From: Myers Carpenter Date: Mon, 16 Sep 2013 14:21:18 -0400 Subject: [PATCH 2/4] create directory to download tarball --- providers/ark.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/providers/ark.rb b/providers/ark.rb index 6246d3c1..4acec40d 100644 --- a/providers/ark.rb +++ b/providers/ark.rb @@ -56,6 +56,9 @@ def oracle_downloaded?(download_path, new_resource) def download_direct_from_oracle(tarball_name, new_resource) download_path = "#{Chef::Config[:file_cache_path]}/#{tarball_name}" + directory Chef::Config[:file_cache_path] do + action :create + end jdk_id = new_resource.url.scan(/\/([6789]u[0-9][0-9]?-b[0-9][0-9])\//)[0][0] cookie = "oraclelicensejdk-#{jdk_id}-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com" if node['java']['oracle']['accept_oracle_download_terms'] From db28e362b0a60af0efb4802e95efaecb225cdee7 Mon Sep 17 00:00:00 2001 From: Myers Carpenter Date: Mon, 16 Sep 2013 14:21:18 -0400 Subject: [PATCH 3/4] create directory to download tarball --- providers/ark.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/providers/ark.rb b/providers/ark.rb index 6246d3c1..4acec40d 100644 --- a/providers/ark.rb +++ b/providers/ark.rb @@ -56,6 +56,9 @@ def oracle_downloaded?(download_path, new_resource) def download_direct_from_oracle(tarball_name, new_resource) download_path = "#{Chef::Config[:file_cache_path]}/#{tarball_name}" + directory Chef::Config[:file_cache_path] do + action :create + end jdk_id = new_resource.url.scan(/\/([6789]u[0-9][0-9]?-b[0-9][0-9])\//)[0][0] cookie = "oraclelicensejdk-#{jdk_id}-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com" if node['java']['oracle']['accept_oracle_download_terms'] From b5a33377cbe7e94d5607a5b77245d0ab658acdd3 Mon Sep 17 00:00:00 2001 From: Myers Carpenter Date: Mon, 16 Sep 2013 15:03:18 -0400 Subject: [PATCH 4/4] Another try at getting the directory created --- providers/ark.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/providers/ark.rb b/providers/ark.rb index 4acec40d..e9db6aa1 100644 --- a/providers/ark.rb +++ b/providers/ark.rb @@ -56,9 +56,6 @@ def oracle_downloaded?(download_path, new_resource) def download_direct_from_oracle(tarball_name, new_resource) download_path = "#{Chef::Config[:file_cache_path]}/#{tarball_name}" - directory Chef::Config[:file_cache_path] do - action :create - end jdk_id = new_resource.url.scan(/\/([6789]u[0-9][0-9]?-b[0-9][0-9])\//)[0][0] cookie = "oraclelicensejdk-#{jdk_id}-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com" if node['java']['oracle']['accept_oracle_download_terms'] @@ -70,10 +67,9 @@ def download_direct_from_oracle(tarball_name, new_resource) p.run_action(:install) description = "download oracle tarball straight from the server" converge_by(description) do - Chef::Log.debug "downloading oracle tarball straight from the source" - cmd = shell_out!( - %Q[ curl -L --cookie "#{cookie}" #{new_resource.url} -o #{download_path} ] - ) + FileUtils.mkdir_p Chef::Config[:file_cache_path] + Chef::Log.debug "downloading oracle tarball straight from the source" + cmd = shell_out!(%Q[ curl -L --cookie "#{cookie}" #{new_resource.url} -o #{download_path} ]) end else Chef::Application.fatal!("You must set the attribute node['java']['oracle']['accept_oracle_download_terms'] to true if you want to download directly from the oracle site!")