Skip to content

Commit

Permalink
Merge pull request #28 from dhoer/install_java
Browse files Browse the repository at this point in the history
Make install of Java optional
  • Loading branch information
bdwyertech committed Oct 21, 2015
2 parents b7b8653 + 9dba78d commit 63ff73d
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ rvm:
- 1.9.3
- 2.0.0
script:
- bundle exec foodcritic -f any . --tags ~FC007 --tags ~FC024
- bundle exec foodcritic -f any . --tags ~FC007 --tags ~FC024 --tags ~FC048
# - bundle exec rspec --color --format progress
- bundle exec rubocop
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "http://api.berkshelf.com"
source 'http://api.berkshelf.com'

metadata
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
WildFly Cookbook CHANGELOG
==========================

# 0.2.0 (2015-09-09)
* Make install of Java optional.

# 0.1.19 (2015-04-01)
* Fixed location of wildfly.conf in Debian init script.


# 0.1.18 (2015-03-19)
* Adjusted behavior of the service user update procedure.
* Fixed hardcoded username.
Expand Down Expand Up @@ -104,4 +106,4 @@ WildFly Cookbook CHANGELOG


# 0.1.0 (2014-02-18)
* Initial commit
* Initial commit
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
Cookbook to deploy Wildfly Java Application Server

# Requirements
Chef Client 11+

Java Opscode Community Cookbook
- Chef Client 11+
- Java Cookbook (ignored if node['wildfly']['install_java'] is false)

# Platform
- CentOS, Red Hat
Expand All @@ -17,9 +16,13 @@ You can add users in the proper format to `attributes\users.rb`

You can customize the Java version, and the Connector/J if you'd like.

If running in production, I STRONGLY recommend you use a wrapper cookbook, and manually specify the Wildfly version, Java version, and cookbook version as well. This cookbook and configuration templates will continually be updated to support the latest stable release of Wildfly. Currently, version upgrades will trigger configuration enforcement, meaning any changes made outside of Chef will be wiped out.
If running in production, I STRONGLY recommend you use a wrapper cookbook, and manually specify the Wildfly version,
Java version (if node['wildfly']['install_java'] is true), and cookbook version as well.
This cookbook and configuration templates will continually be updated to support the latest stable release of Wildfly.
Currently, version upgrades will trigger configuration enforcement, meaning any changes made outside of Chef will be wiped out.

# Attributes
* `node['wildfly']['install_java']` - Install Java using Java Cookbook. Default `true`
* `node['wildfly']['base']` - Base directory to run Wildfly from

* `node['wildfly']['version']` - Specify the version of Wildfly
Expand All @@ -39,7 +42,8 @@ If running in production, I STRONGLY recommend you use a wrapper cookbook, and m


# Recipes
* `::default` - Installs Java & Wildfly. Also installs Connector/J if you've got it enabled.
* `::default` - Installs Java (if node['wildfly']['install_java'] is true) & Wildfly.
Also installs Connector/J if you've got it enabled.
* `::install` - Installs Wildfly.
* `::mysql_connector` - Installs Connector/J into appropriate Wildfly directory.

Expand Down
7 changes: 3 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_workstation'

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
VAGRANTFILE_API_VERSION = '2'

Vagrant.require_version ">= 1.5.0"
Vagrant.require_version '>= 1.5.0'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
Expand All @@ -19,11 +19,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# Set the version of chef to install using the vagrant-omnibus plugin


config.omnibus.chef_version = :latest

# Every Vagrant virtual environment requires a box to build off of.
# If this value is a shorthand to a box in Vagrant Cloud then
# If this value is a shorthand to a box in Vagrant Cloud then
# config.vm.box_url doesn't need to be specified.
config.vm.box = 'CentOS6.6_x64'

Expand Down
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8
# rubocop:disable LineLength
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand Down Expand Up @@ -91,3 +90,5 @@
# => Hardcode JAVA_HOME into init.d configuration.
# => Based on value of node['java']['java_home']
default['wildfly']['java']['enforce_java_home'] = true

default['wildfly']['install_java'] = true
1 change: 0 additions & 1 deletion attributes/mysql_datasources.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8
# rubocop:disable LineLength
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand Down
2 changes: 1 addition & 1 deletion attributes/postgres_datasources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
pool_min: '5',
pool_max: '20'
}
]
]
1 change: 0 additions & 1 deletion attributes/system_properties.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8
# rubocop:disable LineLength
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand Down
1 change: 0 additions & 1 deletion attributes/users.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8
# rubocop:disable LineLength
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
license 'Apache License, Version 2.0'
description 'Installs/Configures wildfly'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.19'
version '0.2.0'

supports 'centos'

Expand Down
6 changes: 3 additions & 3 deletions providers/attribute.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8
# rubocop:disable LineLength, SpecialGlobalVars, MethodLength
# rubocop:disable LineLength, Metrics/AbcSize, MethodLength
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand All @@ -26,9 +26,9 @@ def whyrun_supported?

action :set do
if @current_resource.exists
Chef::Log.info "#{ @new_resource } already set - nothing to do."
Chef::Log.info "#{@new_resource} already set - nothing to do."
else
converge_by("Set #{ @new_resource }") do
converge_by("Set #{@new_resource}") do
attribute_set
end
end
Expand Down
15 changes: 8 additions & 7 deletions providers/datasource.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8
# rubocop:disable LineLength, SpecialGlobalVars, MethodLength
# rubocop:disable LineLength, Metrics/AbcSize
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand All @@ -17,6 +17,7 @@
#

require 'etc'
include Chef::Mixin::ShellOut

# Support whyrun
def whyrun_supported?
Expand All @@ -25,21 +26,21 @@ def whyrun_supported?

action :create do
if @current_resource.exists
Chef::Log.info "#{ @new_resource } already exists - nothing to do."
Chef::Log.info "#{@new_resource} already exists - nothing to do."
else
converge_by("Create #{ @new_resource }") do
converge_by("Create #{@new_resource}") do
create_datasource
end
end
end

action :delete do
if @current_resource.exists
converge_by("Delete #{ @new_resource }") do
converge_by("Delete #{@new_resource}") do
delete_datasource
end
else
Chef::Log.info "#{ @current_resource } doesn't exist - can't delete."
Chef::Log.info "#{@current_resource} doesn't exist - can't delete."
end
end

Expand All @@ -56,8 +57,8 @@ def load_current_resource
private

def datasource_exists?(name)
`su #{node['wildfly']['user']} -s /bin/bash -c "#{node['wildfly']['base']}/bin/jboss-cli.sh -c ' /subsystem=datasources/data-source=#{name}:read-resource'"`
$?.exitstatus == 0
result = shell_out("su #{node['wildfly']['user']} -s /bin/bash -c \"#{node['wildfly']['base']}/bin/jboss-cli.sh -c ' /subsystem=datasources/data-source=#{name}:read-resource'\"")
result.exitstatus == 0
end

def create_datasource
Expand Down
52 changes: 30 additions & 22 deletions providers/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8
# rubocop:disable LineLength, SpecialGlobalVars
# rubocop:disable LineLength, Metrics/AbcSize
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand All @@ -26,51 +26,59 @@ def whyrun_supported?

action :install do
if runtime_exists?
Chef::Log.info "#{ @new_resource.runtime_name } already exists"
Chef::Log.info "#{@new_resource.runtime_name} already exists"
if deploy_exists?
Chef::Log.info "#{ @new_resource.name } already enabled - nothing to do."
Chef::Log.info "#{@new_resource.name} already enabled - nothing to do."
else
Chef::Log.info "#{ @new_resource.name } is not the active resource."
deploy_remove(@current_resource.runtime_name, false)
read_deployment_details(true)
deploy_install(@current_resource.cli, @current_resource.name, @current_resource.runtime_name)
converge_by("#{@new_resource.name} is not the active resource.") do
deploy_remove(@current_resource.runtime_name, false)
read_deployment_details(true)
deploy_install(@current_resource.cli, @current_resource.name, @current_resource.runtime_name)
end
end
else
deploy_install(@current_resource.cli, @current_resource.name, @current_resource.runtime_name)
converge_by("install #{@new_resource.name}") do
deploy_install(@current_resource.cli, @current_resource.name, @current_resource.runtime_name)
end
end
end

action :remove do
if runtime_exists?
deploy_remove(@current_resource.runtime_name, false)
converge_by("remove #{@current_resource.runtime_name}") do
deploy_remove(@current_resource.runtime_name, false)
end
else
Chef::Log.info "#{ @new_resource.runtime_name } does not exist - nothing to do."
Chef::Log.info "#{@new_resource.runtime_name} does not exist - nothing to do."
end
end

action :enable do
if runtime_exists?
Chef::Log.info "#{ @new_resource.runtime_name } already exists"
Chef::Log.info "#{@new_resource.runtime_name} already exists"
if deploy_exists?
if deploy_enabled?(@current_resource.name)
Chef::Log.info "#{ @new_resource.name } resource is already enabled."
Chef::Log.info "#{@new_resource.name} resource is already enabled."
else
Chef::Log.info "#{ @new_resource.name } activating previously loaded resource."
deploy_install('', @current_resource.name, @current_resource.runtime_name)
converge_by("#{@new_resource.name} activating previously loaded resource.") do
deploy_install('', @current_resource.name, @current_resource.runtime_name)
end
end
else
Chef::Log.info "#{ @new_resource.name } resource does not exist yet, cannot enable."
Chef::Log.info "#{@new_resource.name} resource does not exist yet, cannot enable."
end
else
Chef::Log.info "#{ @new_resource.runtime_name } resource does not exist yet, cannot enable."
Chef::Log.info "#{@new_resource.runtime_name} resource does not exist yet, cannot enable."
end
end

action :disable do
if runtime_exists?
deploy_remove(@current_resource.runtime_name, true)
converge_by("disable #{@current_resource.runtime_name}") do
deploy_remove(@current_resource.runtime_name, true)
end
else
Chef::Log.info "#{ @new_resource.runtime_name } does not exist - nothing to do."
Chef::Log.info "#{@new_resource.runtime_name} does not exist - nothing to do."
end
end

Expand Down Expand Up @@ -102,7 +110,7 @@ def deploy_enabled?(name)

def deploy_install(source, name, runtime_name)
Chef::Log.info "Deploying #{name}"
converge_by((source == '' ? 'Enabling' : 'Deploying') + " #{ detailed_name(runtime_name, name) }") do
converge_by((source == '' ? 'Enabling' : 'Deploying') + " #{detailed_name(runtime_name, name)}") do
result = shell_out("bin/jboss-cli.sh -c ' deploy #{source} --name=#{name} --runtime-name=#{runtime_name}'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.error! if result.exitstatus != 0
end
Expand All @@ -111,8 +119,8 @@ def deploy_install(source, name, runtime_name)

def deploy_remove(runtime_name, keep_content = false)
deployments = read_deployment_details
deployments[runtime_name].each do | deployed |
converge_by((keep_content ? 'Disabling' : 'Removing') + " #{ detailed_name(runtime_name, deployed.keys.first) }") do
deployments[runtime_name].each do |deployed|
converge_by((keep_content ? 'Disabling' : 'Removing') + " #{detailed_name(runtime_name, deployed.keys.first)}") do
Chef::Log.info 'Undeploying #{detailed_name(runtime_name, deployed.keys.first)}'
result = shell_out("bin/jboss-cli.sh -c ' undeploy #{deployed.keys.first} #{keep_content ? '--keep-content' : ''}'", user: node['wildfly']['user'], cwd: node['wildfly']['base'])
result.error! if result.exitstatus != 0
Expand All @@ -136,7 +144,7 @@ def detailed_name(runtime_name, name)

def format_output(data)
result = {}
data.split(/\n/).each do | item |
data.split(/\n/).each do |item|
output = item.split(/\s+/)
if result.key?(output[1])
result[output[1]] << { output[0] => { persistent: output[2], enabled: output[3], status: output[4] } }
Expand Down
15 changes: 8 additions & 7 deletions providers/logcategory.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8
# rubocop:disable LineLength, SpecialGlobalVars, MethodLength
# rubocop:disable LineLength, MethodLength, Metrics/AbcSize
#
# Copyright (C) 2014 Brian Dwyer - Intelligent Digital Services
#
Expand All @@ -17,6 +17,7 @@
#

require 'etc'
include Chef::Mixin::ShellOut

# Support whyrun
def whyrun_supported?
Expand All @@ -25,21 +26,21 @@ def whyrun_supported?

action :create do
if @current_resource.exists
Chef::Log.info "#{ @new_resource } already exists - nothing to do."
Chef::Log.info "#{@new_resource} already exists - nothing to do."
else
converge_by("Create #{ @new_resource }") do
converge_by("Create #{@new_resource}") do
create_logcategory
end
end
end

action :delete do
if @current_resource.exists
converge_by("Delete #{ @new_resource }") do
converge_by("Delete #{@new_resource}") do
delete_logcategory
end
else
Chef::Log.info "#{ @current_resource } doesn't exist - can't delete."
Chef::Log.info "#{@current_resource} doesn't exist - can't delete."
end
end

Expand All @@ -56,8 +57,8 @@ def load_current_resource
private

def logcategory_exists?(name)
`su #{node['wildfly']['user']} -s /bin/bash -c "#{node['wildfly']['base']}/bin/jboss-cli.sh -c ' /subsystem=logging/logger=#{name}:read-resource'"`
$?.exitstatus == 0
result = shell_out("su #{node['wildfly']['user']} -s /bin/bash -c \"#{node['wildfly']['base']}/bin/jboss-cli.sh -c ' /subsystem=logging/logger=#{name}:read-resource'\"")
result.exitstatus == 0
end

def create_logcategory
Expand Down
Loading

0 comments on commit 63ff73d

Please sign in to comment.