app.rb 3.67 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 35 36 37 38 39 40
	# Move solr and adjust permissions to the final destination
	bash 'Move Solr' do
		user 'vagrant'
		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 60 61 62 63 64 65 66
	# Fetch the solr TYPO3 extension
	bash 'Fetch Solr' do
		user 'vagrant'
		timeout 3000000
		action :run
		only_if {
			not ::File.exists?("#{Chef::Config['file_cache_path']}/ext-solr-#{new_resource.extension}.tgz")
		}
Stefan Galinski's avatar
Stefan Galinski committed
67

68 69 70 71 72
		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";
		EOF
Stefan Galinski's avatar
Stefan Galinski committed
73 74
	end

75 76 77 78 79 80 81 82
	# Unpack and copy directories to the final location
	bash 'Move Solr' do
		user 'vagrant'
		timeout 3000000
		action :run
		only_if {
			not ::File.exists?("#{Chef::Config['file_cache_path']}/ext-solr/README.md")
		}
Stefan Galinski's avatar
Stefan Galinski committed
83

84 85 86 87 88 89 90 91 92
		code <<-EOF
			cd #{Chef::Config['file_cache_path']};
			tar -xzf ext-solr-#{new_resource.extension}.tgz;
			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/;
			cp -a #{Chef::Config['file_cache_path']}/ext-solr/Resources/Private/Solr/cores server/solr/;
			chown solr:root -R #{node['typo3_solr']['solr']['solr_home']};
		EOF
Stefan Galinski's avatar
Stefan Galinski committed
93 94
	end

95 96
	# start solr
	execute 'systemctl start solr'
Stefan Galinski's avatar
Stefan Galinski committed
97

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

106 107 108 109 110 111 112
	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
113 114
	end

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

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