Skip to content
Browse files

COOK-858, COOK-813

special thanks to jtimberman for mentoring me through this process
  • Loading branch information...
1 parent 8885042 commit 846862c4514804e4c82f501fb14c1221b34a48da @bryanwb bryanwb committed
Showing with 471 additions and 147 deletions.
  1. +94 −26 README.md
  2. +24 −4 attributes/default.rb
  3. +4 −4 metadata.rb
  4. +158 −0 providers/ark.rb
  5. +54 −15 recipes/openjdk.rb
  6. +52 −0 recipes/oracle.rb
  7. +48 −0 recipes/oracle_i386.rb
  8. +0 −98 recipes/sun.rb
  9. +37 −0 resources/ark.rb
View
120 README.md
@@ -1,7 +1,12 @@
Description
===========
-Installs a Java. Uses OpenJDK by default but supports installation of the Sun's Java.
+Installs a Java. Uses OpenJDK by default but supports installation of
+the Oracle's JDK.
+
+This cookbook also provides the java_ark LWRP which other java
+cookbooks can use to install java-related applications from binary
+packages.
---
Requirements
@@ -16,13 +21,16 @@ Platform
Cookbooks
---------
-* apt
+* java
---
Attributes
==========
-* `node["java"]["install_flavor"]` - Flavor of JVM you would like installed (`sun` or `openjdk`), default `openjdk`.
+* `node["java"]["install_flavor"]` - Flavor of JVM you would like installed (`oracle` or `openjdk`), default `openjdk`.
+* `node['java']['java_home']`
+* `node['java']['tarball']` - name of the tarball to retrieve from your corporate repository default `jdk1.6.0_29_i386.tar.gz`
+* `node['java']['tarball_checksum']` - checksum for the tarball, if you use a different tarball, you also need to create a new sha256 checksum
---
Recipes
@@ -38,14 +46,87 @@ openjdk
This recipe installs the `openjdk` flavor of Java.
-sun
+oracle
---
-This recipe installs the `sun` flavor of Java.
-
-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.
-
-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.
+This recipe installs the `oracle` flavor of Java. This recipe does not
+use distribution packages as Oracle changed the licensing terms with
+JDK 1.6u27 and prohibited the practice for both the debian and EL worlds.
+
+For both debian and centos/rhel, this recipe pulls the binary
+distribution from the Oracle website, and installs it in the default
+JAVA_HOME for each distribution. For debian/ubuntu, this is
+/usr/lib/jvm/default-java. For Centos/RHEL, this is /usr/lib/jvm/java
+
+After putting the binaries in place, the oracle recipe updates
+/usr/bin/java to point to the installed JDK using the update-alternatives script
+
+oracle_i386
+-----------
+
+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.
+
+Resources/Providers
+===================
+
+This LWRP provides an easy way to manage java applications. It uses
+the LWRP arkive (deliberately misspelled). It is an arkive and not an
+"archive" because the java_ark lwrp is not the same as a java archive
+or "jar". Essentially, you provide the java_ark with the URL to a tarball and
+the commands within the extracted result that you want symlinked to /usr/bin/
+
+If you have a better name for this lwrp please contact the maintainer.
+
+By default, the extracted directory is extracted to app_root/extracted_dir_name and symlinked to app_root/default
+
+# Actions
+
+- :install: extracts the tarball and makes necessary symlinks
+- :remove: removes the tarball and run update-alternatives for all
+ symlinked bin_cmds
+
+# Attribute Parameters
+
+- url: path to tarball, .tar.gz, .bin (oracle-specific), and .zip
+ currently supported
+- checksum: sha256 checksum, not used for security but avoid
+ redownloading the archive on each chef-client run
+- app_home: the default for installations of this type of
+ application, for example, /usr/lib/tomcat/default. If your
+ application is not set to the default, it will be placed at the same
+ level in the directory hierarchy but the directory name will be
+ app_root/extracted_directory_name + "_alt"
+- app_home_mode: file mode for app_home, is an integer
+- bin_cmds: array of binary commands that should be symlinked to
+ /usr/bin, examples are mvn, java, javac, etc. These cmds must be in
+ the bin/ subdirectory of the extracted folder. Will be ignored if this
+ java_ark is not the default
+- owner: owner of extracted directory, set to "root" by default
+- default: whether this the default installation of this package,
+ boolean true or false
+
+
+# Examples
+
+ # install jdk6 from Oracle
+ java_ark "jdk" do
+ url 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin'
+ checksum 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365'
+ app_home '/usr/local/java/default'
+ bin_cmds ["java", "javac"]
+ action :install
+ end
+
+ # installs maven2
+ java_ark "maven2" do
+ url "http://www.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.tar.gz"
+ checksum "b9a36559486a862abfc7fb2064fd1429f20333caae95ac51215d06d72c02d376"
+ app_home "/usr/local/maven/default"
+ bin_cmds ["mvn"]
+ action :install
+ end
+
+
---
Usage
@@ -53,39 +134,26 @@ Usage
Simply include the `java` recipe where ever you would like Java installed.
-To install Sun flavored Java on Debian or Ubuntu override the `node['java']['install_flavor']` attribute with in role:
+To install Oracle flavored Java on Debian or Ubuntu override the `node['java']['install_flavor']` attribute with in role:
name "java"
- description "Install Sun Java on Ubuntu"
+ description "Install Oracle Java on Ubuntu"
override_attributes(
"java" => {
- "install_flavor" => "sun"
+ "install_flavor" => "oracle"
}
)
run_list(
"recipe[java]"
)
-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:
- name "java"
- description "Install Sun Java on CentOS"
- override_attributes(
- "java" => {
- "install_flavor" => "sun",
- "version" => "6u25",
- "rpm_url" => "https://mycompany.s3.amazonaws.com/sun_jdk",
- "rpm_checksum" => "c473e3026f991e617710bad98f926435959303fe084a5a31140ad5ad75d7bf13"
- }
- )
- run_list(
- "recipe[java]"
- )
License and Author
==================
Author:: Seth Chisamore (<schisamo@opscode.com>)
+Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
Copyright:: 2008-2011, Opscode, Inc
View
28 attributes/default.rb
@@ -1,5 +1,6 @@
#
# Author:: Seth Chisamore (<schisamo@opscode.com>)
+# Author:: Bryan W. Berry (<bryan.berry@opscode.com>)
# Cookbook Name:: java
# Attributes:: default
#
@@ -17,13 +18,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# default jdk attributes
default['java']['install_flavor'] = "openjdk"
+default['java']['jdk_version'] = '6'
+default['java']['arch'] = kernel['machine'] =~ /x86_64/ ? "x86_64" : "i586"
case platform
when "centos","redhat","fedora"
- default['java']['version'] = "6u25"
- default['java']['arch'] = kernel['machine'] =~ /x86_64/ ? "amd64" : "i586"
- set['java']['java_home'] = "/usr/lib/jvm/java"
+ default['java']['java_home'] = "/usr/lib/jvm/java"
else
- set['java']['java_home'] = "/usr/lib/jvm/default-java"
+ default['java']['java_home'] = "/usr/lib/jvm/default-java"
end
+
+# jdk6 attributes
+# x86_64
+default['java']['jdk']['6']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin'
+default['java']['jdk']['6']['x86_64']['checksum'] = 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365'
+
+# i586
+default['java']['jdk']['6']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-i586.bin'
+default['java']['jdk']['6']['i586']['checksum'] = '1117f4dfc45632b68ec0f4d5e61e5cafc1d85dc655ee3df5fa6f50128b8c3faf'
+
+# jdk7 attributes
+# x86_64
+default['java']['jdk']['7']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz'
+default['java']['jdk']['7']['x86_64']['checksum'] = 'f88070cfe7fe5ed60dfda7729cf9dd110b77840e2ca8cd14a86d5d2274b09c9c'
+
+# i586
+default['java']['jdk']['7']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.tar.gz'
+default['java']['jdk']['7']['i586']['checksum'] = 'acbfb8912a287facbee02ff138d94457aabab409b2f1d15855714ec9608a6cd4'
View
8 metadata.rb
@@ -3,13 +3,13 @@
license "Apache 2.0"
description "Installs Java runtime."
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version "1.1"
-
-depends "apt"
+version "1.3.1"
recipe "java", "Installs Java runtime"
recipe "java::openjdk", "Installs the OpenJDK flavor of Java"
-recipe "java::sun", "Installs the Sun flavor of Java"
+recipe "java::oracle", "Installs the Oracle flavor of Java"
+recipe "java::oracle_i386", "Installs the 32-bit jvm without setting it as the default"
+
%w{ debian ubuntu centos redhat fedora }.each do |os|
supports os
View
158 providers/ark.rb
@@ -0,0 +1,158 @@
+#
+# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
+# Cookbook Name:: java
+# Provider:: ark
+#
+# Copyright 2011, Bryan w. Berry
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+def parse_app_dir_name url
+ file_name = url.split('/')[-1]
+ # funky logic to parse oracle's non-standard naming convention
+ # for jdk1.6
+ if file_name =~ /^(jre|jdk).*$/
+ major_num = file_name.scan(/\d/)[0]
+ update_num = file_name.scan(/\d+/)[1]
+ # pad a single digit number with a zero
+ if update_num.length < 2
+ update_num = "0" + update_num
+ end
+ package_name = file_name.scan(/[a-z]+/)[0]
+ app_dir_name = "#{package_name}1.#{major_num}.0_#{update_num}"
+ else
+ app_dir_name = file_name.split(/(.tar.gz|.zip)/)[0]
+ app_dir_name = app_dir_name.split("-bin")[0]
+ end
+ [app_dir_name, file_name]
+end
+
+action :install do
+ app_dir_name, tarball_name = parse_app_dir_name(new_resource.url)
+ app_root = new_resource.app_home.split('/')[0..-2].join('/')
+ app_dir = app_root + '/' + app_dir_name
+
+ unless new_resource.default
+ Chef::Log.debug("processing alternate jdk")
+ app_dir = app_dir + "_alt"
+ app_home = app_dir
+ else
+ app_home = new_resource.app_home
+ end
+
+ unless ::File.exists?(app_dir)
+ Chef::Log.info "Adding #{new_resource.name} to #{app_dir}"
+ require 'fileutils'
+
+ unless ::File.exists?(app_root)
+ FileUtils.mkdir app_root, :mode => new_resource.app_home_mode
+ FileUtils.chown new_resource.owner, new_resource.owner, app_root
+ end
+
+ r = remote_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do
+ source new_resource.url
+ checksum new_resource.checksum
+ mode 0755
+ action :nothing
+ end
+ r.run_action(:create_if_missing)
+
+ require 'tmpdir'
+
+ tmpdir = Dir.mktmpdir
+ case tarball_name
+ when /^.*\.bin/
+ cmd = Chef::ShellOut.new(
+ %Q[ cd "#{tmpdir}";
+ cp "#{Chef::Config[:file_cache_path]}/#{tarball_name}" . ;
+ bash ./#{tarball_name} -noregister
+ ] ).run_command
+ unless cmd.exitstatus == 0
+ Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
+ end
+ when /^.*\.zip/
+ cmd = Chef::ShellOut.new(
+ %Q[ unzip "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -d "#{tmpdir}" ]
+ ).run_command
+ unless cmd.exitstatus == 0
+ Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
+ end
+ when /^.*\.tar.gz/
+ cmd = Chef::ShellOut.new(
+ %Q[ tar xvzf "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -C "#{tmpdir}" ]
+ ).run_command
+ unless cmd.exitstatus == 0
+ Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
+ end
+ end
+
+ cmd = Chef::ShellOut.new(
+ %Q[ mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" ]
+ ).run_command
+ unless cmd.exitstatus == 0
+ Chef::Application.fatal!(%Q[ Command \' mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" \' failed ])
+ end
+ FileUtils.rm_r tmpdir
+ new_resource.updated_by_last_action(true)
+ end
+
+ #update-alternatives
+ if new_resource.default
+ Chef::Log.debug "app_home is #{app_home} and app_dir is #{app_dir}"
+ current_link = ::File.symlink?(app_home) ? ::File.readlink(app_home) : nil
+ if current_link != app_dir
+ Chef::Log.debug "symlinking #{app_dir} to #{app_home}"
+ FileUtils.rm_f app_home
+ FileUtils.ln_sf app_dir, app_home
+ end
+ if new_resource.bin_cmds
+ new_resource.bin_cmds.each do |cmd|
+ if ::File.exists? "/usr/bin/#{cmd}"
+ current_bin_link = ::File.readlink("/usr/bin/#{cmd}")
+ else
+ current_bin_link = false
+ end
+ should_be_link = "#{app_home}/bin/#{cmd}"
+ if current_bin_link != should_be_link
+ cmd = Chef::ShellOut.new(
+ %Q[ update-alternatives --install /usr/bin/#{cmd} #{cmd} #{app_home}/bin/#{cmd} 1;
+ update-alternatives --set #{cmd} #{app_home}/bin/#{cmd} ]
+ ).run_command
+ unless cmd.exitstatus == 0
+ Chef::Application.fatal!(%Q[ update alternatives failed ])
+ end
+ end
+ end
+ end
+ end
+end
+
+action :remove do
+ app_dir_name, tarball_name = parse_app_dir_name(new_resource.url)
+ app_root = new_resource.app_home.split('/')[0..-2].join('/')
+ app_dir = app_root + '/' + app_dir_name
+
+ if ::File.exists?(app_dir)
+ new_resource.bin_cmds.each do |cmd|
+ cmd = execute "update_alternatives" do
+ command "update-alternatives --remove #{cmd} #{app_dir} "
+ returns [0,2]
+ action :nothing
+ end
+ cmd.run_action(:run)
+ end
+ Chef::Log.info "Removing #{new_resource.name} at #{app_dir}"
+ FileUtils.rm_rf app_dir
+ new_resource.updated_by_last_action(true)
+ end
+end
View
69 recipes/openjdk.rb
@@ -1,4 +1,4 @@
-#
+# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: java
# Recipe:: openjdk
@@ -17,26 +17,65 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+version = node['java']['jdk_version']
+java_home = node['java']['java_home']
+java_home_parent = File.dirname java_home
+jdk_home = ""
+
pkgs = value_for_platform(
- ["centos","redhat","fedora"] => {
- "default" => ["java-1.6.0-openjdk","java-1.6.0-openjdk-devel"]
- },
- ["arch","freebsd"] => {
- "default" => ["openjdk6"]
- },
- "default" => ["openjdk-6-jdk","default-jdk"]
-)
+ ["centos","redhat","fedora"] => {
+ "default" => ["java-1.#{version}.0-openjdk","java-1.#{version}.0-openjdk-devel"]
+ },
+ "default" => ["openjdk-#{version}-jdk"]
+ )
-execute "update-java-alternatives" do
- command "update-java-alternatives -s java-6-openjdk"
- returns [0,2]
- action :nothing
- only_if { platform?("ubuntu", "debian") }
+# done by special request for rberger
+ruby_block "set-env-java-home" do
+ block do
+ ENV["JAVA_HOME"] = java_home
+ end
end
+ruby_block "update-java-alternatives" do
+ block do
+ require "fileutils"
+ arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
+ Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
+ jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk?{,#{arch}}")[0]
+ Chef::Log.debug("jdk_home is #{jdk_home}")
+ # delete the symlink if it already exists
+ if File.exists? java_home
+ FileUtils.rm_f java_home
+ end
+ FileUtils.ln_sf jdk_home, java_home
+
+ if platform?("ubuntu", "debian") and version == 6
+ # specific to Ubuntu, this finds the file which specifies all
+ # the symlinks to be updated
+ java_link_name = Dir.glob("#{java_home_parent}/.java*#{version}*openjdk.jinfo")[0]
+ java_link_name = File.basename(java_link_name).split('.')[1..-2].join('.')
+ cmd = Chef::ShellOut.new(
+ "update-java-alternatives -s #{java_link_name}"
+ ).run_command
+ unless cmd.exitstatus == 0 or cmd.exitstatus == 2
+ Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
+ end
+ else
+ cmd = Chef::ShellOut.new(
+ %Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
+ update-alternatives --set java #{java_home}/bin/java ]
+ ).run_command
+ unless cmd.exitstatus == 0 or cmd.exitstatus == 2
+ Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
+ end
+ end
+ end
+ action :nothing
+end
+
pkgs.each do |pkg|
package pkg do
action :install
- notifies :run, "execute[update-java-alternatives]"
+ notifies :create, "ruby_block[update-java-alternatives]"
end
end
View
52 recipes/oracle.rb
@@ -0,0 +1,52 @@
+#
+# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
+# Cookbook Name:: java
+# Recipe:: oracle
+#
+# Copyright 2011, Bryan w. Berry
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+java_home = node['java']["java_home"]
+arch = node['java']['arch']
+jdk_version = node['java']['jdk_version']
+
+#convert version number to a string if it isn't already
+if jdk_version.instance_of? Fixnum
+ jdk_version = jdk_version.to_s
+end
+
+case jdk_version
+when "6"
+ tarball_url = node['java']['jdk']['6'][arch]['url']
+ tarball_checksum = node['java']['jdk']['6'][arch]['checksum']
+when "7"
+ tarball_url = node['java']['jdk']['7'][arch]['url']
+ tarball_checksum = node['java']['jdk']['7'][arch]['checksum']
+end
+
+ruby_block "set-env-java-home" do
+ block do
+ ENV["JAVA_HOME"] = java_home
+ end
+end
+
+java_ark "jdk" do
+ url tarball_url
+ checksum tarball_checksum
+ app_home java_home
+ bin_cmds ["java"]
+ action :install
+end
+
View
48 recipes/oracle_i386.rb
@@ -0,0 +1,48 @@
+#
+# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
+# Cookbook Name:: java
+# Recipe:: oracle_i386
+#
+# Copyright 2010-2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+java_home = node['java']["java_home"]
+
+case node['java']['jdk_version']
+when "6"
+ tarball_url = node['java']['jdk']['6']['i586']['url']
+ tarball_checksum = node['java']['jdk']['6']['i586']['checksum']
+when "7"
+ tarball_url = node['java']['jdk']['7']['i586']['url']
+ tarball_checksum = node['java']['jdk']['7']['i586']['checksum']
+end
+
+ruby_block "set-env-java-home" do
+ block do
+ ENV["JAVA_HOME"] = java_home
+ end
+end
+
+yum_package "glibc" do
+ arch "i686"
+# provider Chef::Provider::Package::Yum
+end
+
+java_ark "jdk-alt" do
+ url tarball_url
+ checksum tarball_checksum
+ app_home java_home
+ default false
+ action :install
+end
View
98 recipes/sun.rb
@@ -1,98 +0,0 @@
-#
-# Author:: Seth Chisamore (<schisamo@opscode.com>)
-# Cookbook Name:: java
-# Recipe:: sun
-#
-# Copyright 2010-2011, Opscode, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-pkgs = value_for_platform(
- ["centos","redhat","fedora"] => {
- "default" => ["jdk-#{node['java']['version']}-ea-linux-#{node['java']['arch']}.rpm"]
- },
- ["debian","ubuntu"] => {
- "default" => ["sun-java6-jdk"]
- },
- "arch" => {
- "default" => ["jre"]
- }
-)
-
-case node['platform']
-when "ubuntu"
-
- apt_repository "ubuntu-partner" do
- uri "http://archive.canonical.com/ubuntu"
- distribution node['lsb']['codename']
- components ['partner']
- action :add
- end
- # update-java-alternatives doesn't work with only sun java installed
- node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
-
-when "debian"
-
- apt_repository "debian-non-free" do
- uri "http://http.us.debian.org/debian"
- distribution "stable"
- components ['main','contrib','non-free']
- action :add
- end
- # update-java-alternatives doesn't work with only sun java installed
- node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
-
-when "centos", "redhat", "fedora"
-
- pkgs.each do |pkg|
- if node['java'].attribute?('rpm_url')
- remote_file "#{Chef::Config[:file_cache_path]}/#{pkg}" do
- source "#{node['java']['rpm_url']}/#{pkg}"
- checksum node['java']['rpm_checksum']
- mode "0644"
- end
- else
- cookbook_file "#{Chef::Config[:file_cache_path]}/#{pkg}" do
- source pkg
- mode "0644"
- action :create_if_missing
- end
- end
- end
-
-when "arch"
-
-else
- Chef::Log.error("Installation of Sun Java packages not supported on this platform.")
-end
-
-execute "update-java-alternatives" do
- command "update-java-alternatives -s java-6-sun"
- returns [0,2]
- action :nothing
- only_if { platform?("ubuntu", "debian") }
-end
-
-pkgs.each do |pkg|
- package pkg do
- case node['platform']
- when "ubuntu", "debian"
- response_file "java.seed"
- when "centos", "redhat", "fedora"
- source "#{Chef::Config[:file_cache_path]}/#{pkg}"
- options "--nogpgcheck" # sun/oracle doesn't sign their RPMs o_O
- end
- action :install
- notifies :run, "execute[update-java-alternatives]"
- end
-end
View
37 resources/ark.rb
@@ -0,0 +1,37 @@
+#
+# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
+# Cookbook Name:: java
+# Resource:: ark
+#
+# Copyright 2011, Bryan w. Berry
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+actions :install, :remove
+
+attribute :url, :regex => /^http:\/\/.*(tar.gz|bin|zip)$/, :default => nil
+attribute :mirrorlist, :kind_of => Array, :default => nil
+attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/, :default => nil
+attribute :app_home, :kind_of => String, :default => nil
+attribute :app_home_mode, :kind_of => Integer, :default => 0755
+attribute :bin_cmds, :kind_of => Array, :default => nil
+attribute :owner, :default => "root"
+attribute :default, :equal_to => [true, false], :default => true
+
+# we have to set default for the supports attribute
+# in initializer since it is a 'reserved' attribute name
+def initialize(*args)
+ super
+ @action = :install
+ @supports = {:report => true, :exception => true}
+end

0 comments on commit 846862c

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