Skip to content

Commit

Permalink
basic tomcat::webapp_jdbc works
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwb committed Mar 19, 2012
1 parent 9ca11fb commit 2070c39
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ark/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
license "Apache 2.0"
description "Installs/Configures ark"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.2"
version "0.0.3"

%w{ java }.each do |cb|
depends cb
Expand Down
18 changes: 12 additions & 6 deletions jboss/recipes/_load_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
# license Apache v2.0
#

app_name = node['jboss']['application']
ruby_block "set jdbc parameters" do
block do
app_name = node['jboss']['application']

db = data_bag_item("apps", app_name)[node['app_env']]
node['jboss']['java_opts'] = db['java_opts']
node['jboss']['jdbc']['schema'] = db['jdbc']['schema']
node['jboss']['jdbc']['user'] = db['jdbc']['user']
node['jboss']['jdbc']['host'] = db['jdbc']['host']
db = data_bag_item("apps", app_name)[node['app_env']]
Chef::Log.debug("application name is #{app_name} and env is #{node['app_env']}")
Chef::Log.debug("databag contents are #{db.inspect}")
node['jboss']['java_opts'] = db['java_opts']
node['jboss']['jdbc']['schema'] = db['jdbc']['schema']
node['jboss']['jdbc']['user'] = db['jdbc']['user']
node['jboss']['jdbc']['host'] = db['jdbc']['host']
end
end
File renamed without changes.
2 changes: 1 addition & 1 deletion maven/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
license "Apache 2.0"
description "Installs/Configures maven"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.3.0"
version "0.3.1"

depends "java"

Expand Down
4 changes: 2 additions & 2 deletions tomcat/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
# urls for arks and sha256 checksum for each
set['tomcat']['6']['url'] = 'http://apache.mirrors.tds.net/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.tar.gz'
set['tomcat']['6']['checksum'] = 'b28c9cbc2a8ef271df646a50410bab7904953b550697efb5949c9b2d6a9f3d53'
set['tomcat']['7']['url'] = 'http://apache.mirrors.tds.net/tomcat/tomcat-7/v7.0.25/bin/apache-tomcat-7.0.25.tar.gz'
set['tomcat']['7']['checksum'] = '7ba03b6703b43da6868613fd625bfb13a791d57478b4a4e49bdb56f9fc3994b4'
set['tomcat']['7']['url'] = 'http://apache.mirrors.tds.net/tomcat/tomcat-7/v7.0.26/bin/apache-tomcat-7.0.26.tar.gz'
set['tomcat']['7']['checksum'] = '89ba5fde0c596db388c3bbd265b63007a9cc3df3a8e6d79a46780c1a39408cb5'
2 changes: 1 addition & 1 deletion tomcat/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
license "Apache 2.0"
description "Installs/Configures tomcat"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.11.2"
version "0.11.3"

%w{ java logrotate ark }.each do |cb|
depends cb
Expand Down
1 change: 0 additions & 1 deletion tomcat/providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

def get_distro
if platform? [ "centos","redhat","fedora"]
package "redhat-lsb"
"el"
else
"debian"
Expand Down
9 changes: 9 additions & 0 deletions tomcat/recipes/_jdbc_password.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ruby_block "get jdbc password" do
block do
app_name = node['tomcat']['application']
app_env = node['app_env']
bag, item = node[:passwd_data_bag].split('/')
db = Chef::EncryptedDataBagItem.load(bag, item)
node['tomcat']['jdbc']['password'] = db[app_name][app_env]['jdbc']
end
end
16 changes: 16 additions & 0 deletions tomcat/recipes/_load_jdbc_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

ruby_block "load jdbc parameters" do
block do
app_name = node['tomcat']['application']
db = data_bag_item("apps", app_name)[node['app_env']]
node['tomcat']['java_opts'] = db['java_opts']
node['tomcat']['jdbc']['schema'] = db['jdbc']['schema']
node['tomcat']['jdbc']['user'] = db['jdbc']['user']
node['tomcat']['jdbc']['host'] = db['jdbc']['host']
jdbc_url = "jdbc:#{node['tomcat']['jdbc']['driver']['name']}://" +
"#{node['tomcat']['jdbc']['host']}:" +
"#{node['tomcat']['jdbc']['port']}/" +
"#{node['tomcat']['jdbc']['schema']}"
node['tomcat']['jdbc']['url'] = jdbc_url
end
end
39 changes: 39 additions & 0 deletions tomcat/recipes/webapp_jdbc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Cookbook Name:: tomcat
# Recipe:: webapp_jdbc
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Copyright 2012, Food and Agriculture Organization of the United Nations
#
# license Apache v2.0
#

include_recipe "ark"
include_recipe "tomcat::base"
include_recipe "maven"
include_recipe "tomcat::_jdbc_password"
include_recipe "tomcat::_load_jdbc_params"

t = tomcat node['tomcat']['user'] do
user node['tomcat']['user']
action :install
jvm_opts node['tomcat']['java_opts']
end

maven node['tomcat']['jdbc']['driver']['name'] do
groupId node['tomcat']['jdbc']['driver']['name']
version node['tomcat']['jdbc']['driver']['version']
dest "#{t.base}/lib"
owner node['tomcat']['user']
end

directory "#{t.base}/conf/Catalina/localhost" do
recursive true
owner node['tomcat']['user']
end

template "jdbc context" do
path "#{t.base}/conf/Catalina/localhost/#{node['tomcat']['application']}.xml"
source "context.xml.erb"
owner node['tomcat']['user']
end

16 changes: 16 additions & 0 deletions tomcat/templates/default/context.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Context path="/<%= node['tomcat']['application'] %>" debug="0" useHttpOnly="true">

<Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction"
factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>


<Resource name="jdbc/<%= node['tomcat']['application'].capitalize %>DS" auth="Container"
type="javax.sql.DataSource"
username="<%= node['tomcat']['jdbc']['user'] %>"
password="<%= node['tomcat']['jdbc']['password'] %>"
driverClassName="<%= node['tomcat']['jdbc']['driver']['name'] %>"
url="<%= node['tomcat']['jdbc']['url'] %>"
maxActive="20"
validationQuery="select 1"
/>
</Context>

0 comments on commit 2070c39

Please sign in to comment.