app.rb 9.26 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

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

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

		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 \
37
				"#{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}.tar.gz";
Stefan Galinski's avatar
Stefan Galinski committed
38 39 40 41 42
		EOF
		action :run
	end

	execute "decompress-solr-archive - #{new_resource.name}" do
43
		cwd Chef::Config['file_cache_path']
Stefan Galinski's avatar
Stefan Galinski committed
44
		command "tar -xzf apache-solr-#{new_resource.solr}.tar.gz"
45
		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
46 47 48 49 50
	end

	# copy solr war-file

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

	execute "copy-solr-app - #{new_resource.name}" do
57 58 59
		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
60 61 62
	end

	execute "copy-solr-libs - #{new_resource.name}" do
63 64
		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
65 66 67 68
		only_if { Gem::Version.new(new_resource.solr) >= Gem::Version.new('4.0.0') }
	end

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

	execute "copy-log4j-properties - #{new_resource.name}" do
73 74 75
		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
76 77 78
		only_if { Gem::Version.new(new_resource.solr) >= Gem::Version.new('4.0.0') }
	end

79 80 81
	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
82 83 84 85 86 87
		mode 0775
		action :create
		recursive true
	end

	execute "copy-solr-files - #{new_resource.name}" do
88 89
		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
90 91 92 93
		creates
	end

	new_resource.languages.each do |language|
94 95 96
		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
97 98 99 100 101
			mode 0775
			action :create
		end

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

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

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

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

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

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

147 148 149 150
	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
151 152 153 154 155
		mode 0644
		cookbook 'typo3_solr'
	end

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

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

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

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

	execute "copy-dist - #{new_resource.name}" do
180
		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
181 182 183
	end

	execute "copy-contrib - #{new_resource.name}" do
184
		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
185 186
	end

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

	# old typo3 solr plugin

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

	# new typo3-solr plugins

203 204
	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
205
		mode 0644
206
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
207 208 209
		only_if { Gem::Version.new(new_resource.plugin_access) > Gem::Version.new('0.0.0') }
	end

210
	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
211 212
		source "http://www.typo3-solr.com/fileadmin/files/solr/Solr4x/solr-typo3-utils-#{new_resource.plugin_utils}.jar"
		mode 0644
213
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
214 215 216
		only_if { Gem::Version.new(new_resource.plugin_utils) > Gem::Version.new('0.0.0') }
	end

217
	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
218 219
		source "http://www.typo3-solr.com/fileadmin/files/solr/Solr4x/commons-lang3-#{new_resource.plugin_lang}.jar"
		mode 0644
220
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
221 222 223 224 225 226
		only_if { Gem::Version.new(new_resource.plugin_lang) > Gem::Version.new('0.0.0') }
	end

	# reset directory access restrictions

	execute "chown - #{new_resource.name}" do
227
		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
228 229 230 231 232 233
	end

	new_resource.updated_by_last_action(true)
end

action :remove do
234
	service 'tomcat' do
235
		service_name node['tomcat']['base_instance']
Stefan Galinski's avatar
Stefan Galinski committed
236 237 238
		supports :restart => true, :reload => true, :status => true
	end

239
	directory "#{node['typo3_solr']['solr']['solr_home']}/#{new_resource.name}" do
Stefan Galinski's avatar
Stefan Galinski committed
240 241 242 243
		action :delete
		recursive true
	end

244
	file "#{node['tomcat']['context_dir']}/#{new_resource.name}.xml" do
Stefan Galinski's avatar
Stefan Galinski committed
245 246 247
		action :delete
	end

248
	file "#{node['tomcat']['webapp_dir']}/#{new_resource.name}.war" do
Stefan Galinski's avatar
Stefan Galinski committed
249 250 251
		action :delete
	end

252
	directory "#{node['tomcat']['webapp_dir']}/#{new_resource.name}" do
Stefan Galinski's avatar
Stefan Galinski committed
253 254
		action :delete
		recursive true
255
		notifies :restart, 'service[tomcat]', :immediately
Stefan Galinski's avatar
Stefan Galinski committed
256 257 258 259
	end

	new_resource.updated_by_last_action(true)
end