Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

COOK-858 #263

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
119 changes: 92 additions & 27 deletions java/README.md
@@ -1,7 +1,11 @@
Description
===========

Installs a Java. Uses OpenJDK by default but supports installation of the Sun's Java.
Installs a Java. Uses Oracle's JDK by default but supports installation of the OpenJDK.

This cookbook also provides the java_cpr LWRP which other java
cookbooks can use to install java-related applications from binary
packages.

---
Requirements
Expand All @@ -16,13 +20,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 `oracle`.
* `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
Expand All @@ -31,61 +38,119 @@ Recipes
default
-------

Include the default recipe in a run list, to get `java`. By default the `openjdk` flavor of Java is installed, but this can be changed by using the `install_flavor` attribute.
Include the default recipe in a run list, to get `java`. By default the `oracle` flavor of Java is installed, but this can be changed by using the `install_flavor` attribute.

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/local/java/default. For Centos/RHEL, this is /usr/java/default

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 CPR (crappy package resource). It is "crappy" because it is
very simple and barely deserves being called a package resource.
Essentially, you provide the java_cpr with the URL to a tarball and
the commands within the extracted result that you want symlinked to /usr/bin/

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_root: the root for all installations of this type of
application, for example /usr/java/, /usr/local/tomcat where there
may be multiple installations of different versions of tomcat and
the jvm on a single machine (esp. in legacy setups).
#{app_root}/default will point to the default installation
- app_root_mode: file mode for app_root, 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_cpr 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_cpr "jdk" do
url 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin'
checksum 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365'
app_root '/usr/local/java'
bin_cmds ["java", "javac"]
action :install
end

# installs maven2
java_cpr "maven2" do
url "http://www.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.tar.gz"
checksum "b9a36559486a862abfc7fb2064fd1429f20333caae95ac51215d06d72c02d376"
app_root "/usr/local/maven"
bin_cmds ["mvn"]
action :install
end



---
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

Expand Down
9 changes: 4 additions & 5 deletions java/attributes/default.rb
Expand Up @@ -17,13 +17,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

default['java']['install_flavor'] = "openjdk"
default['java']['install_flavor'] = "oracle"
default['java']['jdk_version'] = '6'

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"
set['java']['java_home'] = "/usr/java/default"
else
set['java']['java_home'] = "/usr/lib/jvm/default-java"
set['java']['java_home'] = "/usr/local/java/default"
end
28 changes: 28 additions & 0 deletions java/attributes/oracle-jdk6.rb
@@ -0,0 +1,28 @@
#
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Cookbook Name:: java
# Attributes:: oracle-jdk6
#
# 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.

# 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'
29 changes: 29 additions & 0 deletions java/attributes/oracle-jdk7.rb
@@ -0,0 +1,29 @@
#
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Cookbook Name:: java
# Attributes:: oracle-jdk7
#
# 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.

# 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'



50 changes: 50 additions & 0 deletions java/metadata.json
@@ -0,0 +1,50 @@
{
"name": "java",
"description": "Installs Java runtime.",
"long_description": "Description\n===========\n\nInstalls a Java. Uses OpenJDK by default but supports installation of the Sun's Java.\n\n---\nRequirements\n============\n\nPlatform\n--------\n\n* Debian, Ubuntu\n* CentOS, Red Hat, Fedora\n\nCookbooks\n---------\n\n* apt\n\n---\nAttributes\n==========\n\n* `node[\"java\"][\"install_flavor\"]` - Flavor of JVM you would like installed (`sun` or `openjdk`), default `openjdk`.\n\n---\nRecipes\n=======\n\ndefault\n-------\n\nInclude the default recipe in a run list, to get `java`. By default the `openjdk` flavor of Java is installed, but this can be changed by using the `install_flavor` attribute.\n\nopenjdk\n-------\n\nThis recipe installs the `openjdk` flavor of Java.\n\nsun\n---\n\nThis recipe installs the `sun` flavor of Java. \n\nOn 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.\n\nOn 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.\n\n---\nUsage\n=====\n\nSimply include the `java` recipe where ever you would like Java installed. \n\nTo install Sun flavored Java on Debian or Ubuntu override the `node['java']['install_flavor']` attribute with in role:\n\n name \"java\"\n description \"Install Sun Java on Ubuntu\"\n override_attributes(\n \"java\" => {\n \"install_flavor\" => \"sun\"\n }\n )\n run_list(\n \"recipe[java]\"\n )\n\nOn RedHat flavored Linux be sure to set the `rpm_url` and `rpm_checksum` attributes if you placed the `rpm` file on a remote server:\n\n name \"java\"\n description \"Install Sun Java on CentOS\"\n override_attributes(\n \"java\" => {\n \"install_flavor\" => \"sun\",\n \"version\" => \"6u25\",\n \"rpm_url\" => \"https://mycompany.s3.amazonaws.com/sun_jdk\",\n \"rpm_checksum\" => \"c473e3026f991e617710bad98f926435959303fe084a5a31140ad5ad75d7bf13\"\n }\n )\n run_list(\n \"recipe[java]\"\n )\n\nLicense and Author\n==================\n\nAuthor:: Seth Chisamore (<schisamo@opscode.com>)\n\nCopyright:: 2008-2011, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
"maintainer": "Opscode, Inc.",
"maintainer_email": "cookbooks@opscode.com",
"license": "Apache 2.0",
"platforms": {
"debian": [

],
"ubuntu": [

],
"centos": [

],
"redhat": [

],
"fedora": [

]
},
"dependencies": {
"apt": [

]
},
"recommendations": {
},
"suggestions": {
},
"conflicting": {
},
"providing": {
},
"replacing": {
},
"attributes": {
},
"groupings": {
},
"recipes": {
"java": "Installs Java runtime",
"java::openjdk": "Installs the OpenJDK flavor of Java",
"java::sun": "Installs the Sun flavor of Java"
},
"version": "1.1.0"
}
8 changes: 4 additions & 4 deletions java/metadata.rb
Expand Up @@ -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.2.3"

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
Expand Down