app.rb 9.57 KB
Newer Older
Stefan Galinski's avatar
Stefan Galinski committed
1
action :add do
2
	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
3 4 5 6 7 8 9

	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
10
		remote_branch = "release-#{new_resource.extension}.x"
Stefan Galinski's avatar
Stefan Galinski committed
11 12 13 14 15 16
	else
		remote_branch = "master"
	end

	resources_path = "Resources/Solr"

17 18 19 20 21 22 23 24
  if Gem::Version.new(new_resource.extension) >= Gem::Version.new('3.1')
		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}"
  else
		ext_solr_uri = "https://forge.typo3.org/projects/extension-solr/repository/revisions/#{remote_branch}/raw/#{resources_path}"
		plugin_uri = "http://www.typo3-solr.com/fileadmin/files/solr"
  end

Stefan Galinski's avatar
Stefan Galinski committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38
	service "tomcat" do
		service_name "tomcat6"
		supports :restart => true, :reload => true, :status => true
	end

	#remote_file "/home/vagrant/apache-solr-#{new_resource.solr}.tar.gz" do
	#	source "http://www.us.apache.org/dist/lucene/solr/#{new_resource.solr}/solr-#{new_resource.solr}.tgz"
	#	action :create_if_missing
	#end

	bash 'Fetch Solr' do
		user 'vagrant'
		timeout 3000000
		only_if {
Stefan Galinski's avatar
Stefan Galinski committed
39
			not ::File.exists?("#{Chef::Config[:file_cache_path]}/apache-solr-#{new_resource.solr}.tar.gz")
Stefan Galinski's avatar
Stefan Galinski committed
40 41 42 43 44
		}

		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 \
Stefan Galinski's avatar
Stefan Galinski committed
45
				"#{Chef::Config[:file_cache_path]}/apache-solr-#{new_resource.solr}.tar.gz";
Stefan Galinski's avatar
Stefan Galinski committed
46 47 48 49 50
		EOF
		action :run
	end

	execute "decompress-solr-archive - #{new_resource.name}" do
Stefan Galinski's avatar
Stefan Galinski committed
51
		cwd "#{Chef::Config[:file_cache_path]}"
Stefan Galinski's avatar
Stefan Galinski committed
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
		command "tar -xzf apache-solr-#{new_resource.solr}.tar.gz"
		creates "#{Chef::Config[:file_cache_path]}/apache-solr-#{new_resource.solr}/dist/apache-solr-#{new_resource.solr}.war"
	end

	# copy solr war-file

	execute "rename-solr-dir - #{new_resource.name}" do
		cwd Chef::Config[:file_cache_path]
		command "mv solr-#{new_resource.solr} apache-solr-#{new_resource.solr}"
		creates "#{Chef::Config[:file_cache_path]}/apache-solr-#{new_resource.solr}"
	end

	execute "copy-solr-app - #{new_resource.name}" do
		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"
	end

	execute "copy-solr-libs - #{new_resource.name}" do
		cwd Chef::Config[:file_cache_path]
		command "cp apache-solr-#{new_resource.solr}/example/lib/ext/*.jar #{node["tomcat"]["home"]}/lib/"
		only_if { Gem::Version.new(new_resource.solr) >= Gem::Version.new('4.0.0') }
	end

	execute "chmod - #{new_resource.name}" do
		command "chmod -R 777 #{node["tomcat"]["home"]}/lib/"
	end

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

	directory "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3cores/conf" do
		owner node[:tomcat][:user]
		group "root"
		mode 0775
		action :create
		recursive true
	end

	execute "copy-solr-files - #{new_resource.name}" do
		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}/"
		creates
	end

	new_resource.languages.each do |language|
		directory "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3cores/conf/#{language}" do
			owner node[:tomcat][:user]
			group "root"
			mode 0775
			action :create
		end

		%w{ protwords.txt schema.xml synonyms.txt }.each do |file|
			remote_file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3cores/conf/#{language}/#{file}" do
111
				source "#{ext_solr_uri}/typo3cores/conf/#{language}/#{file}"
Stefan Galinski's avatar
Stefan Galinski committed
112 113 114 115 116 117 118
				action :create_if_missing
				owner node[:tomcat][:user]
				mode 0644
			end
		end

		remote_file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3cores/conf/#{language}/_schema_analysis_stopwords_#{language}.json" do
119
			source "#{ext_solr_uri}/typo3cores/conf/#{language}/_schema_analysis_stopwords_#{language}.json"
Stefan Galinski's avatar
Stefan Galinski committed
120 121 122 123 124 125
			action :create_if_missing
			owner node[:tomcat][:user]
			mode 0644
		end

		remote_file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3cores/conf/#{language}/german-common-nouns.txt" do
126
			source "#{ext_solr_uri}/typo3cores/conf/#{language}/german-common-nouns.txt"
Stefan Galinski's avatar
Stefan Galinski committed
127 128 129 130 131 132 133 134 135
			action :create_if_missing
			owner node[:tomcat][:user]
			mode 0644
			only_if { language === 'german' }
		end
	end

	%w{ elevate.xml general_schema_fields.xml general_schema_types.xml solrconfig.xml }.each do |file|
		remote_file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3cores/conf/#{file}" do
136
			source "#{ext_solr_uri}/typo3cores/conf/#{file}"
Stefan Galinski's avatar
Stefan Galinski committed
137 138 139 140 141 142 143
			action :create_if_missing
			owner node[:tomcat][:user]
			mode 0664
		end
	end

	remote_file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3cores/conf/currency.xml" do
144
		source "#{ext_solr_uri}/typo3cores/conf/currency.xml"
Stefan Galinski's avatar
Stefan Galinski committed
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 202
		action :create_if_missing
		owner node[:tomcat][:user]
		mode 0644
		only_if { Gem::Version.new(new_resource.extension) >= Gem::Version.new('2.8.0') }
	end

	file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/solr.xml" do
		action :delete
	end

	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]
		mode 0644
		cookbook 'typo3_solr'
	end

	%w{ bin conf data }.each do |directory|
		directory "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/#{directory}" do
			action :delete
			recursive true
		end
	end

	file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/README.txt" do
		action :delete
	end

	template "#{node[:tomcat][:context_dir]}/#{new_resource.name}.xml" do
		source "tomcat_solr.xml.erb"
		variables(:app => new_resource.name)
		owner node[:tomcat][:user]
		mode 0644
		cookbook 'typo3_solr'
	end

	directory "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/dist" do
		action :create
		mode 0775
	end

	execute "copy-dist - #{new_resource.name}" do
		command "cp -r #{Chef::Config[:file_cache_path]}/apache-solr-#{new_resource.solr}/dist #{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/"
	end

	execute "copy-contrib - #{new_resource.name}" do
		command "cp -r #{Chef::Config[:file_cache_path]}/apache-solr-#{new_resource.solr}/contrib #{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/"
	end

	directory "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3lib" do
		action :create
		mode 0775
	end

	# old typo3 solr plugin

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

	# new typo3-solr plugins

	remote_file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3lib/solr-typo3-access-#{new_resource.plugin_access}.jar" do
212
    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
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
		mode 0644
		notifies :restart, "service[tomcat]", :immediately
		only_if { Gem::Version.new(new_resource.plugin_access) > Gem::Version.new('0.0.0') }
	end

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

	remote_file "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}/typo3lib/commons-lang3-#{new_resource.plugin_lang}.jar" do
		source "http://www.typo3-solr.com/fileadmin/files/solr/Solr4x/commons-lang3-#{new_resource.plugin_lang}.jar"
		mode 0644
		notifies :restart, "service[tomcat]", :immediately
		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
		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}"
	end

	new_resource.updated_by_last_action(true)
end

action :remove do
	service "tomcat" do
		service_name "tomcat6"
		supports :restart => true, :reload => true, :status => true
	end

	directory "#{node[:typo3_solr][:solr][:solr_home]}/#{new_resource.name}" do
		action :delete
		recursive true
	end

	file "#{node[:tomcat][:context_dir]}/#{new_resource.name}.xml" do
		action :delete
	end

	file "#{node[:tomcat][:webapp_dir]}/#{new_resource.name}.war" do
		action :delete
	end

	directory "#{node[:tomcat][:webapp_dir]}/#{new_resource.name}" do
		action :delete
		recursive true
		notifies :restart, "service[tomcat]", :immediately
	end

	new_resource.updated_by_last_action(true)
end