app.rb 3.88 KB
Newer Older
1 2
use_inline_resources

Stefan Galinski's avatar
Stefan Galinski committed
3
action :add do
4 5
	# Install requirements
	package 'lsof'
Stefan Galinski's avatar
Stefan Galinski committed
6

7 8 9 10 11 12 13
	# Create the solr user
	user 'solr' do
		comment 'Solr User'
		home node['typo3_solr']['solr']['solr_home']
		shell '/bin/bash'
		# openssl passwd -1 "mypassword"
		password '$1$YwUKq1QX$qIVeFlybWqOKJjRLed29j'
Stefan Galinski's avatar
Stefan Galinski committed
14 15
	end

16 17
	# Fetch and unpack the wanted solr release from our deploy server
	# TODO Add a fallback to an official server if the release is not available on our server
Stefan Galinski's avatar
Stefan Galinski committed
18 19 20
	bash 'Fetch Solr' do
		user 'vagrant'
		timeout 3000000
21
		action :run
Stefan Galinski's avatar
Stefan Galinski committed
22
		only_if {
23
			not ::File.exists?("#{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}.tar.gz")
Stefan Galinski's avatar
Stefan Galinski committed
24 25 26 27 28
		}

		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 \
29
				"#{Chef::Config['file_cache_path']}/apache-solr-#{new_resource.solr}.tar.gz";
Stefan Galinski's avatar
Stefan Galinski committed
30 31 32
		EOF
	end

33 34
	# Move solr and adjust permissions to the final destination
	bash 'Move Solr' do
35
		user 'root'
36 37 38 39 40
		timeout 3000000
		action :run
		only_if {
			not ::File.exists?("#{node['typo3_solr']['solr']['solr_home']}/README.txt")
		}
Stefan Galinski's avatar
Stefan Galinski committed
41

42 43 44 45 46 47
		code <<-EOF
			cd #{Chef::Config['file_cache_path']};
			tar -xzf apache-solr-#{new_resource.solr}.tar.gz;
			mv solr-#{new_resource.solr} #{node['typo3_solr']['solr']['solr_home']};
			chown solr:root -R #{node['typo3_solr']['solr']['solr_home']};
		EOF
Stefan Galinski's avatar
Stefan Galinski committed
48 49
	end

50 51 52 53
	# Add systemd starter script
	template "#{node['typo3_solr']['solr']['systemd']}/solr.service" do
		source 'solr.service.erb'
		variables(:app => new_resource.solr)
Stefan Galinski's avatar
Stefan Galinski committed
54 55 56
		mode 0644
		cookbook 'typo3_solr'
	end
57
	execute 'systemctl enable solr'
Stefan Galinski's avatar
Stefan Galinski committed
58

59
	# Fetch the solr TYPO3 extension
60
	bash 'Fetch TYPO3 Solr' do
61 62 63 64
		user 'vagrant'
		timeout 3000000
		action :run
		only_if {
65
			not ::File.exists?("#{Chef::Config['file_cache_path']}/ext-solr-#{new_resource.extension}.tgz")
66
		}
Stefan Galinski's avatar
Stefan Galinski committed
67

68 69 70 71
		code <<-EOF
			rsync --delete -auvz --progress -e "ssh -o StrictHostKeyChecking=no" \
				--no-o --no-g deploy@deploy.sgalinski.de:~/solr/ext-solr-#{new_resource.extension}.tgz \
				"#{Chef::Config['file_cache_path']}/ext-solr-#{new_resource.extension}.tgz";
72 73
			cd #{Chef::Config['file_cache_path']};
			tar -xzf ext-solr-#{new_resource.extension}.tgz;
74
		EOF
Stefan Galinski's avatar
Stefan Galinski committed
75 76
	end

77
	# Copy extension configuration to the final location
78 79 80 81
	full_extension_version = new_resource.extension
	if full_extension_version.count('.') == 1
		full_extension_version = full_extension_version + '.0'
	end
82 83
	bash 'Copy TYPO3 Solr configuration' do
		user 'root'
84 85
		timeout 3000000
		action :run
Stefan Galinski's avatar
Stefan Galinski committed
86

87 88
		code <<-EOF
			cd #{node['typo3_solr']['solr']['solr_home']};
Stefan Galinski's avatar
Stefan Galinski committed
89 90
			rm -rf server/solr/configsets/ && cp -a #{Chef::Config['file_cache_path']}/ext-solr-#{full_extension_version}/Resources/Private/Solr/configsets server/solr/configsets/;
			cp -a #{Chef::Config['file_cache_path']}/ext-solr-#{full_extension_version}/Resources/Private/Solr/solr.xml server/solr/;
91 92
			chown solr:root -R #{node['typo3_solr']['solr']['solr_home']};
		EOF
Stefan Galinski's avatar
Stefan Galinski committed
93 94
	end

95
	# start solr and wait some time (otherwise the "add core" calls are maybe not executed, because the server is not started)
96
	execute 'systemctl restart solr'
97
	execute 'sleep 5'
Stefan Galinski's avatar
Stefan Galinski committed
98

99 100 101 102 103
	# Setup Tika server
	directory node['typo3_solr']['solr']['tika_home'] do
		owner 'root'
		group 'root'
		mode 0770
Stefan Galinski's avatar
Stefan Galinski committed
104 105 106
		action :create
	end

107 108 109 110 111 112 113
	remote_file "#{node['typo3_solr']['solr']['tika_home']}/tika-server-#{new_resource.tika_server}.jar" do
		source "http://mirror.dkd.de/apache/tika/tika-server-#{new_resource.tika_server}.jar"
		mode 0550
		owner 'root'
		only_if {
			not ::File.exists?("#{node['typo3_solr']['solr']['tika_home']}/tika-server-#{new_resource.tika_server}.jar")
		}
Stefan Galinski's avatar
Stefan Galinski committed
114 115
	end

116 117
	template "#{node['typo3_solr']['solr']['systemd']}/tika-server.service" do
		source 'tika-server.service.erb'
118 119 120 121
		variables(:app => new_resource.tika_server)
		mode 0644
		cookbook 'typo3_solr'
	end
122
	execute 'systemctl enable tika-server'
123
	execute 'systemctl start tika-server'
124

125
	# done
Stefan Galinski's avatar
Stefan Galinski committed
126
	new_resource.updated_by_last_action(true)
127
end