app.rb 9.85 KB
Newer Older
1
2
use_inline_resources

Stefan Galinski's avatar
Stefan Galinski committed
3
action :add do
4
	uri = URI.parse("https://raw.githubusercontent.com/TYPO3-Solr/ext-solr/release-#{new_resource.extension}.x/README.md")
Stefan Galinski's avatar
Stefan Galinski committed
5
6
7
8
9
10
11

	request = Net::HTTP.new(uri.host, uri.port)
	request.use_ssl = true
	request.verify_mode = OpenSSL::SSL::VERIFY_NONE
	response = request.request_head uri.request_uri

	if response.code.to_i == 200
12
		remote_branch = "release-#{new_resource.extension}.x"
Stefan Galinski's avatar
Stefan Galinski committed
13
	else
14
		remote_branch = 'master'
Stefan Galinski's avatar
Stefan Galinski committed
15
16
	end

17
	resources_path = 'Resources/Solr'
Stefan Galinski's avatar
Stefan Galinski committed
18

19
20
	ext_solr_uri = "https://raw.githubusercontent.com/TYPO3-Solr/ext-solr/#{remote_branch}/#{resources_path}"
	plugin_uri = "https://github.com/TYPO3-Solr/solr-typo3-plugin/releases/download/release-#{new_resource.plugin}"
21
	tika_server_uri = "http://mirror.dkd.de/apache/tika"
22

23
	service 'tomcat' do
24
		service_name node['tomcat']['base_instance']
Stefan Galinski's avatar
Stefan Galinski committed
25
26
27
28
29
30
31
		supports :restart => true, :reload => true, :status => true
	end

	bash 'Fetch Solr' do
		user 'vagrant'
		timeout 3000000
		only_if {
32
			not ::File.exists?("#{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}.tar.gz")
Stefan Galinski's avatar
Stefan Galinski committed
33
34
35
36
37
		}

		code <<-EOF
			rsync --delete -auvz --progress -e "ssh -o StrictHostKeyChecking=no" \
				--no-o --no-g deploy@deploy.sgalinski.de:~/solr/solr-#{new_resource.solr}.tgz \
38
				"#{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}.tar.gz";
Stefan Galinski's avatar
Stefan Galinski committed
39
40
41
42
43
		EOF
		action :run
	end

	execute "decompress-solr-archive - #{new_resource.name}" do
44
		cwd Chef::Config['file_cache_path']
Stefan Galinski's avatar
Stefan Galinski committed
45
		command "tar -xzf apache-solr-#{new_resource.solr}.tar.gz"
46
		creates "#{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}/dist/apache-solr-#{new_resource.solr}.war"
Stefan Galinski's avatar
Stefan Galinski committed
47
48
49
50
51
	end

	# copy solr war-file

	execute "rename-solr-dir - #{new_resource.name}" do
52
		cwd Chef::Config['file_cache_path']
Stefan Galinski's avatar
Stefan Galinski committed
53
		command "mv solr-#{new_resource.solr} apache-solr-#{new_resource.solr}"
54
		creates "#{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}"
Stefan Galinski's avatar
Stefan Galinski committed
55
56
57
	end

	execute "copy-solr-app - #{new_resource.name}" do
58
59
60
		cwd Chef::Config['file_cache_path']
		command "cp apache-solr-#{new_resource.solr}/dist/solr-#{new_resource.solr}.war #{node['tomcat']['webapp_dir']}/#{new_resource.name}.war"
		creates "#{node['tomcat']['webapp_dir']}/#{new_resource.name}.war"
Stefan Galinski's avatar
Stefan Galinski committed
61
62
63
	end

	execute "copy-solr-libs - #{new_resource.name}" do
64
65
		cwd Chef::Config['file_cache_path']
		command "cp apache-solr-#{new_resource.solr}/example/lib/ext/*.jar #{node['tomcat']['home']}/lib/"
Stefan Galinski's avatar
Stefan Galinski committed
66
67
68
69
		only_if { Gem::Version.new(new_resource.solr) >= Gem::Version.new('4.0.0') }
	end

	execute "chmod - #{new_resource.name}" do
70
		command "chmod -R 777 #{node['tomcat']['home']}/lib/"
Stefan Galinski's avatar
Stefan Galinski committed
71
72
73
	end

	execute "copy-log4j-properties - #{new_resource.name}" do
74
75
76
		cwd Chef::Config['file_cache_path']
		command "cp apache-solr-#{new_resource.solr}/example/resources/log4j.properties #{node['tomcat']['home']}/lib/log4j.properties"
		creates "#{node['tomcat']['home']}/lib/log4j.properties"
Stefan Galinski's avatar
Stefan Galinski committed
77
78
79
		only_if { Gem::Version.new(new_resource.solr) >= Gem::Version.new('4.0.0') }
	end

80
81
82
	directory "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3cores/conf" do
		owner node['tomcat']['user']
		group 'root'
Stefan Galinski's avatar
Stefan Galinski committed
83
84
85
86
87
88
		mode 0775
		action :create
		recursive true
	end

	execute "copy-solr-files - #{new_resource.name}" do
89
90
		cwd Chef::Config['file_cache_path']
		command "cp -r apache-solr-#{new_resource.solr}/example/solr/* #{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/"
Stefan Galinski's avatar
Stefan Galinski committed
91
92
93
94
		creates
	end

	new_resource.languages.each do |language|
95
96
97
		directory "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3cores/conf/#{language}" do
			owner node['tomcat']['user']
			group 'root'
Stefan Galinski's avatar
Stefan Galinski committed
98
99
100
101
102
			mode 0775
			action :create
		end

		%w{ protwords.txt schema.xml synonyms.txt }.each do |file|
103
			remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3cores/conf/#{language}/#{file}" do
104
				source "#{ext_solr_uri}/typo3cores/conf/#{language}/#{file}"
Stefan Galinski's avatar
Stefan Galinski committed
105
				action :create_if_missing
106
				owner node['tomcat']['user']
Stefan Galinski's avatar
Stefan Galinski committed
107
108
109
110
				mode 0644
			end
		end

111
		remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3cores/conf/#{language}/_schema_analysis_stopwords_#{language}.json" do
112
			source "#{ext_solr_uri}/typo3cores/conf/#{language}/_schema_analysis_stopwords_#{language}.json"
Stefan Galinski's avatar
Stefan Galinski committed
113
			action :create_if_missing
114
			owner node['tomcat']['user']
Stefan Galinski's avatar
Stefan Galinski committed
115
116
117
			mode 0644
		end

118
		remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3cores/conf/#{language}/german-common-nouns.txt" do
119
			source "#{ext_solr_uri}/typo3cores/conf/#{language}/german-common-nouns.txt"
Stefan Galinski's avatar
Stefan Galinski committed
120
			action :create_if_missing
121
			owner node['tomcat']['user']
Stefan Galinski's avatar
Stefan Galinski committed
122
123
124
125
126
127
			mode 0644
			only_if { language === 'german' }
		end
	end

	%w{ elevate.xml general_schema_fields.xml general_schema_types.xml solrconfig.xml }.each do |file|
128
		remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3cores/conf/#{file}" do
129
			source "#{ext_solr_uri}/typo3cores/conf/#{file}"
Stefan Galinski's avatar
Stefan Galinski committed
130
			action :create_if_missing
131
			owner node['tomcat']['user']
Stefan Galinski's avatar
Stefan Galinski committed
132
133
134
135
			mode 0664
		end
	end

136
	remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3cores/conf/currency.xml" do
137
		source "#{ext_solr_uri}/typo3cores/conf/currency.xml"
Stefan Galinski's avatar
Stefan Galinski committed
138
		action :create_if_missing
139
		owner node['tomcat']['user']
Stefan Galinski's avatar
Stefan Galinski committed
140
141
142
143
		mode 0644
		only_if { Gem::Version.new(new_resource.extension) >= Gem::Version.new('2.8.0') }
	end

144
	file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/solr.xml" do
Stefan Galinski's avatar
Stefan Galinski committed
145
146
147
		action :delete
	end

148
149
150
151
	template "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/solr.xml" do
		source 'solr.xml.erb'
		#variables(:cores => node['typo3_solr'][:cores][new_resource.extension])
		owner node['tomcat']['user']
Stefan Galinski's avatar
Stefan Galinski committed
152
153
154
155
156
		mode 0644
		cookbook 'typo3_solr'
	end

	%w{ bin conf data }.each do |directory|
157
		directory "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/#{directory}" do
Stefan Galinski's avatar
Stefan Galinski committed
158
159
160
161
162
			action :delete
			recursive true
		end
	end

163
	file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/README.txt" do
Stefan Galinski's avatar
Stefan Galinski committed
164
165
166
		action :delete
	end

167
168
	template "#{node['tomcat']['context_dir']}/#{new_resource.name}.xml" do
		source 'tomcat_solr.xml.erb'
Stefan Galinski's avatar
Stefan Galinski committed
169
		variables(:app => new_resource.name)
170
		owner node['tomcat']['user']
Stefan Galinski's avatar
Stefan Galinski committed
171
172
173
174
		mode 0644
		cookbook 'typo3_solr'
	end

175
	directory "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/dist" do
Stefan Galinski's avatar
Stefan Galinski committed
176
177
178
179
180
		action :create
		mode 0775
	end

	execute "copy-dist - #{new_resource.name}" do
181
		command "cp -r #{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}/dist #{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/"
Stefan Galinski's avatar
Stefan Galinski committed
182
183
184
	end

	execute "copy-contrib - #{new_resource.name}" do
185
		command "cp -r #{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}/contrib #{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/"
Stefan Galinski's avatar
Stefan Galinski committed
186
187
	end

188
	directory "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3lib" do
Stefan Galinski's avatar
Stefan Galinski committed
189
190
191
192
193
194
		action :create
		mode 0775
	end

	# old typo3 solr plugin

195
	remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3lib/solr-typo3-plugin-#{new_resource.plugin}.jar" do
196
		source "#{plugin_uri}/solr-typo3-plugin-#{new_resource.plugin}.jar"
Stefan Galinski's avatar
Stefan Galinski committed
197
		mode 0644
198
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
199
200
201
202
203
		only_if { Gem::Version.new(new_resource.plugin) > Gem::Version.new('0.0.0') }
	end

	# new typo3-solr plugins

204
205
	remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3lib/solr-typo3-access-#{new_resource.plugin_access}.jar" do
		source "http://www.typo3-solr.com/fileadmin/files/solr/Solr4x/solr-typo3-access-#{new_resource.plugin_access}.jar"
Stefan Galinski's avatar
Stefan Galinski committed
206
		mode 0644
207
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
208
209
210
		only_if { Gem::Version.new(new_resource.plugin_access) > Gem::Version.new('0.0.0') }
	end

211
	remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3lib/solr-typo3-utils-#{new_resource.plugin_utils}.jar" do
Stefan Galinski's avatar
Stefan Galinski committed
212
213
		source "http://www.typo3-solr.com/fileadmin/files/solr/Solr4x/solr-typo3-utils-#{new_resource.plugin_utils}.jar"
		mode 0644
214
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
215
216
217
		only_if { Gem::Version.new(new_resource.plugin_utils) > Gem::Version.new('0.0.0') }
	end

218
	remote_file "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}/typo3lib/commons-lang3-#{new_resource.plugin_lang}.jar" do
Stefan Galinski's avatar
Stefan Galinski committed
219
220
		source "http://www.typo3-solr.com/fileadmin/files/solr/Solr4x/commons-lang3-#{new_resource.plugin_lang}.jar"
		mode 0644
221
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
222
223
224
		only_if { Gem::Version.new(new_resource.plugin_lang) > Gem::Version.new('0.0.0') }
	end

225
	# tika server
226
227
228
229
230
231
232
233
234
235

	template "#{node['typo3_solr']['solr']['etc_init']}/tika-server.conf" do
		source 'tika-server.conf.erb'
		variables(:app => new_resource.tika_server)
		owner node['tomcat']['user']
		mode 0644
		cookbook 'typo3_solr'
	end

	remote_file "#{node['typo3_solr']['solr']['tika_home']}/tika-server-#{new_resource.tika_server}.jar" do
236
237
		source "#{tika_server_uri}/tika-server-#{new_resource.tika_server}.jar"
		mode 0550
238
239
		owner node['tomcat']['user']
		only_if { Gem::Version.new(new_resource.tika_server) > Gem::Version.new('0.0.0') }
240
241
242
	end


Stefan Galinski's avatar
Stefan Galinski committed
243
244
245
	# reset directory access restrictions

	execute "chown - #{new_resource.name}" do
246
		command "chown -R #{node['tomcat']['user']}:#{node['tomcat']['group']} #{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name} && chmod -R o+rw #{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}"
Stefan Galinski's avatar
Stefan Galinski committed
247
248
249
250
251
252
	end

	new_resource.updated_by_last_action(true)
end

action :remove do
253
	service 'tomcat' do
254
		service_name node['tomcat']['base_instance']
Stefan Galinski's avatar
Stefan Galinski committed
255
256
257
		supports :restart => true, :reload => true, :status => true
	end

258
	directory "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}" do
Stefan Galinski's avatar
Stefan Galinski committed
259
260
261
262
		action :delete
		recursive true
	end

263
	file "#{node['tomcat']['context_dir']}/#{new_resource.name}.xml" do
Stefan Galinski's avatar
Stefan Galinski committed
264
265
266
		action :delete
	end

267
	file "#{node['tomcat']['webapp_dir']}/#{new_resource.name}.war" do
Stefan Galinski's avatar
Stefan Galinski committed
268
269
270
		action :delete
	end

271
	directory "#{node['tomcat']['webapp_dir']}/#{new_resource.name}" do
Stefan Galinski's avatar
Stefan Galinski committed
272
273
		action :delete
		recursive true
274
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
275
276
277
278
	end

	new_resource.updated_by_last_action(true)
end