app.rb 3.66 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/README.md")
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
	bash 'Copy TYPO3 Solr configuration' do
		user 'root'
80 81
		timeout 3000000
		action :run
Stefan Galinski's avatar
Stefan Galinski committed
82

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

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

95 96 97 98 99
	# Setup Tika server
	directory node['typo3_solr']['solr']['tika_home'] do
		owner 'root'
		group 'root'
		mode 0770
Stefan Galinski's avatar
Stefan Galinski committed
100 101 102
		action :create
	end

103 104 105 106 107 108 109
	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
110 111
	end

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

121
	# done
Stefan Galinski's avatar
Stefan Galinski committed
122 123
	new_resource.updated_by_last_action(true)
end