This repository has been archived by the owner on Nov 23, 2017. It is now read-only.
/
default.rb
201 lines (167 loc) · 4.78 KB
/
default.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#
# Cookbook Name:: tomcat6
# Recipe:: default
#
# Copyright 2009, Edmund Haselwanter
#
# 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.
#
#include_recipe "java"
service "tomcat6" do
action :nothing
supports :status => true, :start => true, :stop => true, :restart => true
end
group node[:tomcat6][:user] do
end
user node[:tomcat6][:user] do
comment "Apache Tomcat"
gid node[:tomcat6][:user]
home node[:tomcat6][:home]
shell "/bin/sh"
end
[node[:tomcat6][:temp],node[:tomcat6][:logs],node[:tomcat6][:webapp_base_dir],node[:tomcat6][:webapps],node[:tomcat6][:home],node[:tomcat6][:conf]].each do |dir|
directory dir do
action :create
mode 0755
owner "#{node[:tomcat6][:user]}"
group "#{node[:tomcat6][:user]}"
end
end
[:temp,:logs,:webapps,:conf].each do |dir|
link File.join(node[:tomcat6][:home],dir.to_s) do
to node[:tomcat6][dir] # use values from attributes
end
end
usr_share_dir = "/usr/share"
bash "update_manager" do
user node[:tomcat6][:user]
action :nothing
cwd node[:tomcat6][:webapps]
code <<-EOH
rm -rf ./manager
cp -r #{usr_share_dir}/apache-tomcat-#{node[:tomcat6][:version]}/webapps/manager .
EOH
end
bash "install_tomcat6" do
tomcat_version_name = "apache-tomcat-#{node[:tomcat6][:version]}"
tomcat_version_name_tgz = "#{tomcat_version_name}.tar.gz"
user "root"
cwd usr_share_dir
not_if do File.exists?(File.join(usr_share_dir,tomcat_version_name)) end
code <<-EOH
wget http://archive.apache.org/dist/tomcat/tomcat-6/v#{node[:tomcat6][:version]}/bin/#{tomcat_version_name_tgz}
tar -zxf #{tomcat_version_name_tgz}
rm #{tomcat_version_name_tgz}
chown -R #{node[:tomcat6][:user]}:#{node[:tomcat6][:user]} #{tomcat_version_name}
EOH
end
# just to have it here, may be overriden through own configuration
bash "install_tomcat6_etc" do
user node[:tomcat6][:user]
not_if do File.exists?(File.join(node[:tomcat6][:conf],"tomcat6.conf")) end
cwd node[:tomcat6][:conf]
code <<-EOH
cp -r #{usr_share_dir}/apache-tomcat-#{node[:tomcat6][:version]}/conf/* .
EOH
end
link File.join(node[:tomcat6][:home],"lib") do
to File.join(usr_share_dir,"apache-tomcat-#{node[:tomcat6][:version]}","lib")
notifies :run, resources(:bash => "update_manager"), :immediately
notifies :restart, resources(:service => "tomcat6"), :delayed
end
link File.join(node[:tomcat6][:home],"bin") do
to File.join(usr_share_dir,"apache-tomcat-#{node[:tomcat6][:version]}","bin")
notifies :restart, resources(:service => "tomcat6"), :delayed
end
case node[:platform]
when "centos"
# remote_file "/etc/yum.repos.d/rightscale.repo" do
# source "rightscale.repo"
# mode 0755
# owner "root"
# group "root"
# end
#
# package "tomcat6"
#
# link "/usr/share/java/tomcat6/\[ecj\].jar" do
# to "/usr/share/java/eclipse-ecj.jar"
# end
#
# package "tomcat6-admin-webapps"
r = cookbook_file "/tmp/JVM-MANAGEMENT-MIB.mib" do
source "JVM-MANAGEMENT-MIB.mib"
mode 0755
owner "root"
group "root"
end
r.run_action(:create)
p = package "libsmi" do
action :install
end
p.run_action(:install)
g = gem_package "snmp" do
action :install
end
g.run_action(:install)
require 'rubygems'
Gem.clear_paths
require "snmp"
SNMP::MIB.import_module("/tmp/JVM-MANAGEMENT-MIB.mib")
package "tomcat-native" do
action :install
only_if do node[:tomcat6][:with_native] end
end
else
end
cookbook_file "/etc/init.d/tomcat6" do
source "tomcat6"
mode 0755
owner "root"
group "root"
end
cookbook_file "/usr/bin/dtomcat6" do
source "dtomcat6"
mode 0755
owner "root"
group "root"
end
cookbook_file File.join(node[:tomcat6][:dir],"logging.properties") do
source "logging.properties"
mode 0644
owner "root"
group "root"
end
service "tomcat6" do
case node[:platform]
when "centos"
service_name "tomcat6"
else
name "tomcat"
end
supports :start=> true, :stop => true, :restart => true, :status => true
action :enable
end
template "#{node[:tomcat6][:dir]}/tomcat6.conf" do
source "tomcat6.conf.erb"
group "#{node[:tomcat6][:user]}"
owner "#{node[:tomcat6][:user]}"
mode 0644
if File.exists?("/etc/god")
notifies :stop, resources(:service => "god"), :immediately
end
notifies :restart, resources(:service => "tomcat6"), :immediately
end
service "tomcat6" do
action :start
end