Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

COOK-858, COOK-813

special thanks to jtimberman for mentoring me through this process
  • Loading branch information...
commit 846862c4514804e4c82f501fb14c1221b34a48da 1 parent 8885042
Bryan Berry bryanwb authored
120 README.md
Source Rendered
... ... @@ -1,7 +1,12 @@
1 1 Description
2 2 ===========
3 3
4   -Installs a Java. Uses OpenJDK by default but supports installation of the Sun's Java.
  4 +Installs a Java. Uses OpenJDK by default but supports installation of
  5 +the Oracle's JDK.
  6 +
  7 +This cookbook also provides the java_ark LWRP which other java
  8 +cookbooks can use to install java-related applications from binary
  9 +packages.
5 10
6 11 ---
7 12 Requirements
@@ -16,13 +21,16 @@ Platform
16 21 Cookbooks
17 22 ---------
18 23
19   -* apt
  24 +* java
20 25
21 26 ---
22 27 Attributes
23 28 ==========
24 29
25   -* `node["java"]["install_flavor"]` - Flavor of JVM you would like installed (`sun` or `openjdk`), default `openjdk`.
  30 +* `node["java"]["install_flavor"]` - Flavor of JVM you would like installed (`oracle` or `openjdk`), default `openjdk`.
  31 +* `node['java']['java_home']`
  32 +* `node['java']['tarball']` - name of the tarball to retrieve from your corporate repository default `jdk1.6.0_29_i386.tar.gz`
  33 +* `node['java']['tarball_checksum']` - checksum for the tarball, if you use a different tarball, you also need to create a new sha256 checksum
26 34
27 35 ---
28 36 Recipes
@@ -38,14 +46,87 @@ openjdk
38 46
39 47 This recipe installs the `openjdk` flavor of Java.
40 48
41   -sun
  49 +oracle
42 50 ---
43 51
44   -This recipe installs the `sun` flavor of Java.
45   -
46   -On Debian and Ubuntu systems the recipe will add the correct apt repository (`non-free` on Debian or `partner` on Ubuntu), pre-seed the package and update java alternatives.
47   -
48   -On Red Hat flavored Linux (RHEL, CentOS, Fedora), the installation of the Sun flavor of Java is slightly more complicated as the `rpm` package is not readily available in any public Yum repository. The Sun JDK `rpm` package can be downloaded directly from Sun but comes wrapped as a compressed bin file. After the file has been downloaded, decompressed and license accepted the `rpm` package (names something like `jdk-6u25-ea-linux-amd64.rpm`) can be retrieved by this recipe using the `remote_file` or `cookbook_file` resources. The recipe will choose the correct resource based on the existence (or non-existence) of the `node['sun']['rpm_url']` attribute. See below for an example role using this attribute in the proper way. If you would like to deliver the `rpm` package file as part of this cookbook place the `rpm` package file in the `files/default` directory and the cookbook will retrieve the file during installation.
  52 +This recipe installs the `oracle` flavor of Java. This recipe does not
  53 +use distribution packages as Oracle changed the licensing terms with
  54 +JDK 1.6u27 and prohibited the practice for both the debian and EL worlds.
  55 +
  56 +For both debian and centos/rhel, this recipe pulls the binary
  57 +distribution from the Oracle website, and installs it in the default
  58 +JAVA_HOME for each distribution. For debian/ubuntu, this is
  59 +/usr/lib/jvm/default-java. For Centos/RHEL, this is /usr/lib/jvm/java
  60 +
  61 +After putting the binaries in place, the oracle recipe updates
  62 +/usr/bin/java to point to the installed JDK using the update-alternatives script
  63 +
  64 +oracle_i386
  65 +-----------
  66 +
  67 +This recipe installs the 32-bit Java virtual machine without setting it as the default. This can be useful if you have applications on the same machine that require different versions of the JVM.
  68 +
  69 +Resources/Providers
  70 +===================
  71 +
  72 +This LWRP provides an easy way to manage java applications. It uses
  73 +the LWRP arkive (deliberately misspelled). It is an arkive and not an
  74 +"archive" because the java_ark lwrp is not the same as a java archive
  75 +or "jar". Essentially, you provide the java_ark with the URL to a tarball and
  76 +the commands within the extracted result that you want symlinked to /usr/bin/
  77 +
  78 +If you have a better name for this lwrp please contact the maintainer.
  79 +
  80 +By default, the extracted directory is extracted to app_root/extracted_dir_name and symlinked to app_root/default
  81 +
  82 +# Actions
  83 +
  84 +- :install: extracts the tarball and makes necessary symlinks
  85 +- :remove: removes the tarball and run update-alternatives for all
  86 + symlinked bin_cmds
  87 +
  88 +# Attribute Parameters
  89 +
  90 +- url: path to tarball, .tar.gz, .bin (oracle-specific), and .zip
  91 + currently supported
  92 +- checksum: sha256 checksum, not used for security but avoid
  93 + redownloading the archive on each chef-client run
  94 +- app_home: the default for installations of this type of
  95 + application, for example, /usr/lib/tomcat/default. If your
  96 + application is not set to the default, it will be placed at the same
  97 + level in the directory hierarchy but the directory name will be
  98 + app_root/extracted_directory_name + "_alt"
  99 +- app_home_mode: file mode for app_home, is an integer
  100 +- bin_cmds: array of binary commands that should be symlinked to
  101 + /usr/bin, examples are mvn, java, javac, etc. These cmds must be in
  102 + the bin/ subdirectory of the extracted folder. Will be ignored if this
  103 + java_ark is not the default
  104 +- owner: owner of extracted directory, set to "root" by default
  105 +- default: whether this the default installation of this package,
  106 + boolean true or false
  107 +
  108 +
  109 +# Examples
  110 +
  111 + # install jdk6 from Oracle
  112 + java_ark "jdk" do
  113 + url 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin'
  114 + checksum 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365'
  115 + app_home '/usr/local/java/default'
  116 + bin_cmds ["java", "javac"]
  117 + action :install
  118 + end
  119 +
  120 + # installs maven2
  121 + java_ark "maven2" do
  122 + url "http://www.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.tar.gz"
  123 + checksum "b9a36559486a862abfc7fb2064fd1429f20333caae95ac51215d06d72c02d376"
  124 + app_home "/usr/local/maven/default"
  125 + bin_cmds ["mvn"]
  126 + action :install
  127 + end
  128 +
  129 +
49 130
50 131 ---
51 132 Usage
@@ -53,39 +134,26 @@ Usage
53 134
54 135 Simply include the `java` recipe where ever you would like Java installed.
55 136
56   -To install Sun flavored Java on Debian or Ubuntu override the `node['java']['install_flavor']` attribute with in role:
  137 +To install Oracle flavored Java on Debian or Ubuntu override the `node['java']['install_flavor']` attribute with in role:
57 138
58 139 name "java"
59   - description "Install Sun Java on Ubuntu"
  140 + description "Install Oracle Java on Ubuntu"
60 141 override_attributes(
61 142 "java" => {
62   - "install_flavor" => "sun"
  143 + "install_flavor" => "oracle"
63 144 }
64 145 )
65 146 run_list(
66 147 "recipe[java]"
67 148 )
68 149
69   -On RedHat flavored Linux be sure to set the `rpm_url` and `rpm_checksum` attributes if you placed the `rpm` file on a remote server:
70 150
71   - name "java"
72   - description "Install Sun Java on CentOS"
73   - override_attributes(
74   - "java" => {
75   - "install_flavor" => "sun",
76   - "version" => "6u25",
77   - "rpm_url" => "https://mycompany.s3.amazonaws.com/sun_jdk",
78   - "rpm_checksum" => "c473e3026f991e617710bad98f926435959303fe084a5a31140ad5ad75d7bf13"
79   - }
80   - )
81   - run_list(
82   - "recipe[java]"
83   - )
84 151
85 152 License and Author
86 153 ==================
87 154
88 155 Author:: Seth Chisamore (<schisamo@opscode.com>)
  156 +Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
89 157
90 158 Copyright:: 2008-2011, Opscode, Inc
91 159
28 attributes/default.rb
... ... @@ -1,5 +1,6 @@
1 1 #
2 2 # Author:: Seth Chisamore (<schisamo@opscode.com>)
  3 +# Author:: Bryan W. Berry (<bryan.berry@opscode.com>)
3 4 # Cookbook Name:: java
4 5 # Attributes:: default
5 6 #
@@ -17,13 +18,32 @@
17 18 # See the License for the specific language governing permissions and
18 19 # limitations under the License.
19 20
  21 +# default jdk attributes
20 22 default['java']['install_flavor'] = "openjdk"
  23 +default['java']['jdk_version'] = '6'
  24 +default['java']['arch'] = kernel['machine'] =~ /x86_64/ ? "x86_64" : "i586"
21 25
22 26 case platform
23 27 when "centos","redhat","fedora"
24   - default['java']['version'] = "6u25"
25   - default['java']['arch'] = kernel['machine'] =~ /x86_64/ ? "amd64" : "i586"
26   - set['java']['java_home'] = "/usr/lib/jvm/java"
  28 + default['java']['java_home'] = "/usr/lib/jvm/java"
27 29 else
28   - set['java']['java_home'] = "/usr/lib/jvm/default-java"
  30 + default['java']['java_home'] = "/usr/lib/jvm/default-java"
29 31 end
  32 +
  33 +# jdk6 attributes
  34 +# x86_64
  35 +default['java']['jdk']['6']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin'
  36 +default['java']['jdk']['6']['x86_64']['checksum'] = 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365'
  37 +
  38 +# i586
  39 +default['java']['jdk']['6']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-i586.bin'
  40 +default['java']['jdk']['6']['i586']['checksum'] = '1117f4dfc45632b68ec0f4d5e61e5cafc1d85dc655ee3df5fa6f50128b8c3faf'
  41 +
  42 +# jdk7 attributes
  43 +# x86_64
  44 +default['java']['jdk']['7']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz'
  45 +default['java']['jdk']['7']['x86_64']['checksum'] = 'f88070cfe7fe5ed60dfda7729cf9dd110b77840e2ca8cd14a86d5d2274b09c9c'
  46 +
  47 +# i586
  48 +default['java']['jdk']['7']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.tar.gz'
  49 +default['java']['jdk']['7']['i586']['checksum'] = 'acbfb8912a287facbee02ff138d94457aabab409b2f1d15855714ec9608a6cd4'
8 metadata.rb
@@ -3,13 +3,13 @@
3 3 license "Apache 2.0"
4 4 description "Installs Java runtime."
5 5 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6   -version "1.1"
7   -
8   -depends "apt"
  6 +version "1.3.1"
9 7
10 8 recipe "java", "Installs Java runtime"
11 9 recipe "java::openjdk", "Installs the OpenJDK flavor of Java"
12   -recipe "java::sun", "Installs the Sun flavor of Java"
  10 +recipe "java::oracle", "Installs the Oracle flavor of Java"
  11 +recipe "java::oracle_i386", "Installs the 32-bit jvm without setting it as the default"
  12 +
13 13
14 14 %w{ debian ubuntu centos redhat fedora }.each do |os|
15 15 supports os
158 providers/ark.rb
... ... @@ -0,0 +1,158 @@
  1 +#
  2 +# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
  3 +# Cookbook Name:: java
  4 +# Provider:: ark
  5 +#
  6 +# Copyright 2011, Bryan w. Berry
  7 +#
  8 +# Licensed under the Apache License, Version 2.0 (the "License");
  9 +# you may not use this file except in compliance with the License.
  10 +# You may obtain a copy of the License at
  11 +#
  12 +# http://www.apache.org/licenses/LICENSE-2.0
  13 +#
  14 +# Unless required by applicable law or agreed to in writing, software
  15 +# distributed under the License is distributed on an "AS IS" BASIS,
  16 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17 +# See the License for the specific language governing permissions and
  18 +# limitations under the License.
  19 +
  20 +def parse_app_dir_name url
  21 + file_name = url.split('/')[-1]
  22 + # funky logic to parse oracle's non-standard naming convention
  23 + # for jdk1.6
  24 + if file_name =~ /^(jre|jdk).*$/
  25 + major_num = file_name.scan(/\d/)[0]
  26 + update_num = file_name.scan(/\d+/)[1]
  27 + # pad a single digit number with a zero
  28 + if update_num.length < 2
  29 + update_num = "0" + update_num
  30 + end
  31 + package_name = file_name.scan(/[a-z]+/)[0]
  32 + app_dir_name = "#{package_name}1.#{major_num}.0_#{update_num}"
  33 + else
  34 + app_dir_name = file_name.split(/(.tar.gz|.zip)/)[0]
  35 + app_dir_name = app_dir_name.split("-bin")[0]
  36 + end
  37 + [app_dir_name, file_name]
  38 +end
  39 +
  40 +action :install do
  41 + app_dir_name, tarball_name = parse_app_dir_name(new_resource.url)
  42 + app_root = new_resource.app_home.split('/')[0..-2].join('/')
  43 + app_dir = app_root + '/' + app_dir_name
  44 +
  45 + unless new_resource.default
  46 + Chef::Log.debug("processing alternate jdk")
  47 + app_dir = app_dir + "_alt"
  48 + app_home = app_dir
  49 + else
  50 + app_home = new_resource.app_home
  51 + end
  52 +
  53 + unless ::File.exists?(app_dir)
  54 + Chef::Log.info "Adding #{new_resource.name} to #{app_dir}"
  55 + require 'fileutils'
  56 +
  57 + unless ::File.exists?(app_root)
  58 + FileUtils.mkdir app_root, :mode => new_resource.app_home_mode
  59 + FileUtils.chown new_resource.owner, new_resource.owner, app_root
  60 + end
  61 +
  62 + r = remote_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do
  63 + source new_resource.url
  64 + checksum new_resource.checksum
  65 + mode 0755
  66 + action :nothing
  67 + end
  68 + r.run_action(:create_if_missing)
  69 +
  70 + require 'tmpdir'
  71 +
  72 + tmpdir = Dir.mktmpdir
  73 + case tarball_name
  74 + when /^.*\.bin/
  75 + cmd = Chef::ShellOut.new(
  76 + %Q[ cd "#{tmpdir}";
  77 + cp "#{Chef::Config[:file_cache_path]}/#{tarball_name}" . ;
  78 + bash ./#{tarball_name} -noregister
  79 + ] ).run_command
  80 + unless cmd.exitstatus == 0
  81 + Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
  82 + end
  83 + when /^.*\.zip/
  84 + cmd = Chef::ShellOut.new(
  85 + %Q[ unzip "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -d "#{tmpdir}" ]
  86 + ).run_command
  87 + unless cmd.exitstatus == 0
  88 + Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
  89 + end
  90 + when /^.*\.tar.gz/
  91 + cmd = Chef::ShellOut.new(
  92 + %Q[ tar xvzf "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -C "#{tmpdir}" ]
  93 + ).run_command
  94 + unless cmd.exitstatus == 0
  95 + Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
  96 + end
  97 + end
  98 +
  99 + cmd = Chef::ShellOut.new(
  100 + %Q[ mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" ]
  101 + ).run_command
  102 + unless cmd.exitstatus == 0
  103 + Chef::Application.fatal!(%Q[ Command \' mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" \' failed ])
  104 + end
  105 + FileUtils.rm_r tmpdir
  106 + new_resource.updated_by_last_action(true)
  107 + end
  108 +
  109 + #update-alternatives
  110 + if new_resource.default
  111 + Chef::Log.debug "app_home is #{app_home} and app_dir is #{app_dir}"
  112 + current_link = ::File.symlink?(app_home) ? ::File.readlink(app_home) : nil
  113 + if current_link != app_dir
  114 + Chef::Log.debug "symlinking #{app_dir} to #{app_home}"
  115 + FileUtils.rm_f app_home
  116 + FileUtils.ln_sf app_dir, app_home
  117 + end
  118 + if new_resource.bin_cmds
  119 + new_resource.bin_cmds.each do |cmd|
  120 + if ::File.exists? "/usr/bin/#{cmd}"
  121 + current_bin_link = ::File.readlink("/usr/bin/#{cmd}")
  122 + else
  123 + current_bin_link = false
  124 + end
  125 + should_be_link = "#{app_home}/bin/#{cmd}"
  126 + if current_bin_link != should_be_link
  127 + cmd = Chef::ShellOut.new(
  128 + %Q[ update-alternatives --install /usr/bin/#{cmd} #{cmd} #{app_home}/bin/#{cmd} 1;
  129 + update-alternatives --set #{cmd} #{app_home}/bin/#{cmd} ]
  130 + ).run_command
  131 + unless cmd.exitstatus == 0
  132 + Chef::Application.fatal!(%Q[ update alternatives failed ])
  133 + end
  134 + end
  135 + end
  136 + end
  137 + end
  138 +end
  139 +
  140 +action :remove do
  141 + app_dir_name, tarball_name = parse_app_dir_name(new_resource.url)
  142 + app_root = new_resource.app_home.split('/')[0..-2].join('/')
  143 + app_dir = app_root + '/' + app_dir_name
  144 +
  145 + if ::File.exists?(app_dir)
  146 + new_resource.bin_cmds.each do |cmd|
  147 + cmd = execute "update_alternatives" do
  148 + command "update-alternatives --remove #{cmd} #{app_dir} "
  149 + returns [0,2]
  150 + action :nothing
  151 + end
  152 + cmd.run_action(:run)
  153 + end
  154 + Chef::Log.info "Removing #{new_resource.name} at #{app_dir}"
  155 + FileUtils.rm_rf app_dir
  156 + new_resource.updated_by_last_action(true)
  157 + end
  158 +end
69 recipes/openjdk.rb
... ... @@ -1,4 +1,4 @@
1   -#
  1 +# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
2 2 # Author:: Seth Chisamore (<schisamo@opscode.com>)
3 3 # Cookbook Name:: java
4 4 # Recipe:: openjdk
@@ -17,26 +17,65 @@
17 17 # See the License for the specific language governing permissions and
18 18 # limitations under the License.
19 19
  20 +version = node['java']['jdk_version']
  21 +java_home = node['java']['java_home']
  22 +java_home_parent = File.dirname java_home
  23 +jdk_home = ""
  24 +
20 25 pkgs = value_for_platform(
21   - ["centos","redhat","fedora"] => {
22   - "default" => ["java-1.6.0-openjdk","java-1.6.0-openjdk-devel"]
23   - },
24   - ["arch","freebsd"] => {
25   - "default" => ["openjdk6"]
26   - },
27   - "default" => ["openjdk-6-jdk","default-jdk"]
28   -)
  26 + ["centos","redhat","fedora"] => {
  27 + "default" => ["java-1.#{version}.0-openjdk","java-1.#{version}.0-openjdk-devel"]
  28 + },
  29 + "default" => ["openjdk-#{version}-jdk"]
  30 + )
29 31
30   -execute "update-java-alternatives" do
31   - command "update-java-alternatives -s java-6-openjdk"
32   - returns [0,2]
33   - action :nothing
34   - only_if { platform?("ubuntu", "debian") }
  32 +# done by special request for rberger
  33 +ruby_block "set-env-java-home" do
  34 + block do
  35 + ENV["JAVA_HOME"] = java_home
  36 + end
35 37 end
36 38
  39 +ruby_block "update-java-alternatives" do
  40 + block do
  41 + require "fileutils"
  42 + arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
  43 + Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
  44 + jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk?{,#{arch}}")[0]
  45 + Chef::Log.debug("jdk_home is #{jdk_home}")
  46 + # delete the symlink if it already exists
  47 + if File.exists? java_home
  48 + FileUtils.rm_f java_home
  49 + end
  50 + FileUtils.ln_sf jdk_home, java_home
  51 +
  52 + if platform?("ubuntu", "debian") and version == 6
  53 + # specific to Ubuntu, this finds the file which specifies all
  54 + # the symlinks to be updated
  55 + java_link_name = Dir.glob("#{java_home_parent}/.java*#{version}*openjdk.jinfo")[0]
  56 + java_link_name = File.basename(java_link_name).split('.')[1..-2].join('.')
  57 + cmd = Chef::ShellOut.new(
  58 + "update-java-alternatives -s #{java_link_name}"
  59 + ).run_command
  60 + unless cmd.exitstatus == 0 or cmd.exitstatus == 2
  61 + Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
  62 + end
  63 + else
  64 + cmd = Chef::ShellOut.new(
  65 + %Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
  66 + update-alternatives --set java #{java_home}/bin/java ]
  67 + ).run_command
  68 + unless cmd.exitstatus == 0 or cmd.exitstatus == 2
  69 + Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
  70 + end
  71 + end
  72 + end
  73 + action :nothing
  74 +end
  75 +
37 76 pkgs.each do |pkg|
38 77 package pkg do
39 78 action :install
40   - notifies :run, "execute[update-java-alternatives]"
  79 + notifies :create, "ruby_block[update-java-alternatives]"
41 80 end
42 81 end
52 recipes/oracle.rb
... ... @@ -0,0 +1,52 @@
  1 +#
  2 +# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
  3 +# Cookbook Name:: java
  4 +# Recipe:: oracle
  5 +#
  6 +# Copyright 2011, Bryan w. Berry
  7 +#
  8 +# Licensed under the Apache License, Version 2.0 (the "License");
  9 +# you may not use this file except in compliance with the License.
  10 +# You may obtain a copy of the License at
  11 +#
  12 +# http://www.apache.org/licenses/LICENSE-2.0
  13 +#
  14 +# Unless required by applicable law or agreed to in writing, software
  15 +# distributed under the License is distributed on an "AS IS" BASIS,
  16 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17 +# See the License for the specific language governing permissions and
  18 +# limitations under the License.
  19 +
  20 +
  21 +java_home = node['java']["java_home"]
  22 +arch = node['java']['arch']
  23 +jdk_version = node['java']['jdk_version']
  24 +
  25 +#convert version number to a string if it isn't already
  26 +if jdk_version.instance_of? Fixnum
  27 + jdk_version = jdk_version.to_s
  28 +end
  29 +
  30 +case jdk_version
  31 +when "6"
  32 + tarball_url = node['java']['jdk']['6'][arch]['url']
  33 + tarball_checksum = node['java']['jdk']['6'][arch]['checksum']
  34 +when "7"
  35 + tarball_url = node['java']['jdk']['7'][arch]['url']
  36 + tarball_checksum = node['java']['jdk']['7'][arch]['checksum']
  37 +end
  38 +
  39 +ruby_block "set-env-java-home" do
  40 + block do
  41 + ENV["JAVA_HOME"] = java_home
  42 + end
  43 +end
  44 +
  45 +java_ark "jdk" do
  46 + url tarball_url
  47 + checksum tarball_checksum
  48 + app_home java_home
  49 + bin_cmds ["java"]
  50 + action :install
  51 +end
  52 +
48 recipes/oracle_i386.rb
... ... @@ -0,0 +1,48 @@
  1 +#
  2 +# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
  3 +# Cookbook Name:: java
  4 +# Recipe:: oracle_i386
  5 +#
  6 +# Copyright 2010-2011, Opscode, Inc.
  7 +#
  8 +# Licensed under the Apache License, Version 2.0 (the "License");
  9 +# you may not use this file except in compliance with the License.
  10 +# You may obtain a copy of the License at
  11 +#
  12 +# http://www.apache.org/licenses/LICENSE-2.0
  13 +#
  14 +# Unless required by applicable law or agreed to in writing, software
  15 +# distributed under the License is distributed on an "AS IS" BASIS,
  16 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17 +# See the License for the specific language governing permissions and
  18 +# limitations under the License.
  19 +
  20 +java_home = node['java']["java_home"]
  21 +
  22 +case node['java']['jdk_version']
  23 +when "6"
  24 + tarball_url = node['java']['jdk']['6']['i586']['url']
  25 + tarball_checksum = node['java']['jdk']['6']['i586']['checksum']
  26 +when "7"
  27 + tarball_url = node['java']['jdk']['7']['i586']['url']
  28 + tarball_checksum = node['java']['jdk']['7']['i586']['checksum']
  29 +end
  30 +
  31 +ruby_block "set-env-java-home" do
  32 + block do
  33 + ENV["JAVA_HOME"] = java_home
  34 + end
  35 +end
  36 +
  37 +yum_package "glibc" do
  38 + arch "i686"
  39 +# provider Chef::Provider::Package::Yum
  40 +end
  41 +
  42 +java_ark "jdk-alt" do
  43 + url tarball_url
  44 + checksum tarball_checksum
  45 + app_home java_home
  46 + default false
  47 + action :install
  48 +end
98 recipes/sun.rb
... ... @@ -1,98 +0,0 @@
1   -#
2   -# Author:: Seth Chisamore (<schisamo@opscode.com>)
3   -# Cookbook Name:: java
4   -# Recipe:: sun
5   -#
6   -# Copyright 2010-2011, Opscode, Inc.
7   -#
8   -# Licensed under the Apache License, Version 2.0 (the "License");
9   -# you may not use this file except in compliance with the License.
10   -# You may obtain a copy of the License at
11   -#
12   -# http://www.apache.org/licenses/LICENSE-2.0
13   -#
14   -# Unless required by applicable law or agreed to in writing, software
15   -# distributed under the License is distributed on an "AS IS" BASIS,
16   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   -# See the License for the specific language governing permissions and
18   -# limitations under the License.
19   -
20   -pkgs = value_for_platform(
21   - ["centos","redhat","fedora"] => {
22   - "default" => ["jdk-#{node['java']['version']}-ea-linux-#{node['java']['arch']}.rpm"]
23   - },
24   - ["debian","ubuntu"] => {
25   - "default" => ["sun-java6-jdk"]
26   - },
27   - "arch" => {
28   - "default" => ["jre"]
29   - }
30   -)
31   -
32   -case node['platform']
33   -when "ubuntu"
34   -
35   - apt_repository "ubuntu-partner" do
36   - uri "http://archive.canonical.com/ubuntu"
37   - distribution node['lsb']['codename']
38   - components ['partner']
39   - action :add
40   - end
41   - # update-java-alternatives doesn't work with only sun java installed
42   - node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
43   -
44   -when "debian"
45   -
46   - apt_repository "debian-non-free" do
47   - uri "http://http.us.debian.org/debian"
48   - distribution "stable"
49   - components ['main','contrib','non-free']
50   - action :add
51   - end
52   - # update-java-alternatives doesn't work with only sun java installed
53   - node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
54   -
55   -when "centos", "redhat", "fedora"
56   -
57   - pkgs.each do |pkg|
58   - if node['java'].attribute?('rpm_url')
59   - remote_file "#{Chef::Config[:file_cache_path]}/#{pkg}" do
60   - source "#{node['java']['rpm_url']}/#{pkg}"
61   - checksum node['java']['rpm_checksum']
62   - mode "0644"
63   - end
64   - else
65   - cookbook_file "#{Chef::Config[:file_cache_path]}/#{pkg}" do
66   - source pkg
67   - mode "0644"
68   - action :create_if_missing
69   - end
70   - end
71   - end
72   -
73   -when "arch"
74   -
75   -else
76   - Chef::Log.error("Installation of Sun Java packages not supported on this platform.")
77   -end
78   -
79   -execute "update-java-alternatives" do
80   - command "update-java-alternatives -s java-6-sun"
81   - returns [0,2]
82   - action :nothing
83   - only_if { platform?("ubuntu", "debian") }
84   -end
85   -
86   -pkgs.each do |pkg|
87   - package pkg do
88   - case node['platform']
89   - when "ubuntu", "debian"
90   - response_file "java.seed"
91   - when "centos", "redhat", "fedora"
92   - source "#{Chef::Config[:file_cache_path]}/#{pkg}"
93   - options "--nogpgcheck" # sun/oracle doesn't sign their RPMs o_O
94   - end
95   - action :install
96   - notifies :run, "execute[update-java-alternatives]"
97   - end
98   -end
37 resources/ark.rb
... ... @@ -0,0 +1,37 @@
  1 +#
  2 +# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
  3 +# Cookbook Name:: java
  4 +# Resource:: ark
  5 +#
  6 +# Copyright 2011, Bryan w. Berry
  7 +#
  8 +# Licensed under the Apache License, Version 2.0 (the "License");
  9 +# you may not use this file except in compliance with the License.
  10 +# You may obtain a copy of the License at
  11 +#
  12 +# http://www.apache.org/licenses/LICENSE-2.0
  13 +#
  14 +# Unless required by applicable law or agreed to in writing, software
  15 +# distributed under the License is distributed on an "AS IS" BASIS,
  16 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17 +# See the License for the specific language governing permissions and
  18 +# limitations under the License.
  19 +
  20 +actions :install, :remove
  21 +
  22 +attribute :url, :regex => /^http:\/\/.*(tar.gz|bin|zip)$/, :default => nil
  23 +attribute :mirrorlist, :kind_of => Array, :default => nil
  24 +attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/, :default => nil
  25 +attribute :app_home, :kind_of => String, :default => nil
  26 +attribute :app_home_mode, :kind_of => Integer, :default => 0755
  27 +attribute :bin_cmds, :kind_of => Array, :default => nil
  28 +attribute :owner, :default => "root"
  29 +attribute :default, :equal_to => [true, false], :default => true
  30 +
  31 +# we have to set default for the supports attribute
  32 +# in initializer since it is a 'reserved' attribute name
  33 +def initialize(*args)
  34 + super
  35 + @action = :install
  36 + @supports = {:report => true, :exception => true}
  37 +end

0 comments on commit 846862c

Please sign in to comment.
Something went wrong with that request. Please try again.