]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Allow civicrm extensions to be installed from a downloaded zip
[chef.git] / cookbooks / civicrm / recipes / default.rb
1 #
2 # Cookbook:: civicrm
3 # Recipe:: default
4 #
5 # Copyright:: 2011, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 include_recipe "wordpress"
21 include_recipe "mysql"
22
23 package %w[
24   php-xml
25   php-curl
26   rsync
27   wkhtmltopdf
28   php-bcmath
29   php-intl
30 ]
31
32 apache_module "rewrite"
33
34 cache_dir = Chef::Config[:file_cache_path]
35
36 passwords = data_bag_item("civicrm", "passwords")
37 wp2fa_encrypt_keys = data_bag_item("civicrm", "wp2fa_encrypt_keys")
38
39 database_password = passwords["database"]
40 site_key = passwords["site_key"]
41 cred_keys = passwords["cred_keys"]
42 sign_keys = passwords["sign_keys"]
43
44 mysql_user "civicrm@localhost" do
45   password database_password
46 end
47
48 mysql_database "civicrm" do
49   permissions "civicrm@localhost" => :all
50 end
51
52 wordpress_site "supporting.openstreetmap.org" do
53   aliases %w[
54     crm.osmfoundation.org
55     donate.openstreetmap.org
56     donate.openstreetmap.com
57     donate.openstreetmap.net
58     donate.osm.org
59     join.osmfoundation.org
60     supporting.osmfoundation.org
61     support.osmfoundation.org
62     support.openstreetmap.org
63     supporting.osm.org
64     support.osm.org
65   ]
66   database_name "civicrm"
67   database_user "civicrm"
68   database_password database_password
69   wp2fa_encrypt_key wp2fa_encrypt_keys["key"]
70   fpm_prometheus_port 11301
71 end
72
73 wordpress_theme "osmblog-wp-theme" do
74   site "supporting.openstreetmap.org"
75   action :delete
76 end
77
78 wordpress_plugin "civicrm-wp-piwik" do
79   plugin "wp-piwik"
80   site "supporting.openstreetmap.org"
81 end
82
83 wordpress_plugin "registration-honeypot" do
84   site "supporting.openstreetmap.org"
85 end
86
87 wordpress_plugin "contact-form-7" do
88   site "supporting.openstreetmap.org"
89 end
90
91 wordpress_plugin "civicrm-admin-utilities" do
92   site "supporting.openstreetmap.org"
93 end
94
95 civicrm_version = node[:civicrm][:version]
96 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
97
98 directory "/opt/civicrm-#{civicrm_version}" do
99   owner "wordpress"
100   group "wordpress"
101   mode "755"
102 end
103
104 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
105   action :create_if_missing
106   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
107   owner "wordpress"
108   group "wordpress"
109   mode "644"
110   backup false
111 end
112
113 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
114   action :create_if_missing
115   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
116   owner "wordpress"
117   group "wordpress"
118   mode "644"
119   backup false
120 end
121
122 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
123   action :nothing
124   destination "/opt/civicrm-#{civicrm_version}"
125   overwrite true
126   owner "wordpress"
127   group "wordpress"
128   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
129 end
130
131 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
132   action :nothing
133   destination "/opt/civicrm-#{civicrm_version}/civicrm"
134   overwrite true
135   owner "wordpress"
136   group "wordpress"
137   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
138 end
139
140 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
141   action :nothing
142   command "rsync --archive --delete --delete-delay --delay-updates /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
143   user "wordpress"
144   group "wordpress"
145   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
146   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
147 end
148
149 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
150   owner "www-data"
151   group "www-data"
152   mode "755"
153 end
154
155 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
156
157 directory extensions_directory do
158   owner "wordpress"
159   group "wordpress"
160   mode "755"
161 end
162
163 node[:civicrm][:extensions].each_value do |details|
164   if details[:repository]
165     git "#{extensions_directory}/#{details[:name]}" do
166       action :sync
167       repository details[:repository]
168       revision details[:revision]
169       user "wordpress"
170       group "wordpress"
171     end
172   elsif details[:zip]
173     remote_file "#{cache_dir}/#{details[:name]}.zip" do
174       source details[:zip]
175       owner "root"
176       group "root"
177       mode "644"
178       backup false
179     end
180
181     archive_file "#{cache_dir}/#{details[:name]}.zip" do
182       action :nothing
183       destination "#{extensions_directory}/#{details[:name]}"
184       strip_components 1
185       owner "wordpress"
186       group "wordpress"
187       overwrite true
188       subscribes :extract, "remote_file[#{cache_dir}/#{details[:name]}.zip]", :immediately
189     end
190   end
191 end
192
193 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
194   line.gsub!(/%%cms%%/, "WordPress")
195   line.gsub!(/%%CMSdbUser%%/, "civicrm")
196   line.gsub!(/%%CMSdbPass%%/, database_password)
197   line.gsub!(/%%CMSdbHost%%/, "localhost")
198   line.gsub!(/%%CMSdbName%%/, "civicrm")
199   line.gsub!(/%%dbUser%%/, "civicrm")
200   line.gsub!(/%%dbPass%%/, database_password)
201   line.gsub!(/%%dbHost%%/, "localhost")
202   line.gsub!(/%%dbName%%/, "civicrm")
203   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
204   line.gsub!(/%%templateCompileDir%%/, "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/templates_c/")
205   line.gsub!(/%%baseURL%%/, "http://supporting.openstreetmap.org/")
206   line.gsub!(/%%siteKey%%/, site_key)
207   line.gsub!(/%%credKeys%%/, cred_keys)
208   line.gsub!(/%%signKeys%%/, sign_keys)
209   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/supporting.openstreetmap.org');")
210
211   line
212 end
213
214 file "#{civicrm_directory}/civicrm.settings.php" do
215   owner "wordpress"
216   group "wordpress"
217   mode "644"
218   content settings
219 end
220
221 systemd_service "osmf-crm-jobs" do
222   description "Run CRM jobs"
223   exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s supporting.openstreetmap.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
224   user "www-data"
225   sandbox :enable_network => true
226   memory_deny_write_execute false
227   restrict_address_families "AF_UNIX"
228   read_write_paths "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm"
229 end
230
231 systemd_timer "osmf-crm-jobs" do
232   description "Run CRM jobs"
233   on_boot_sec "15m"
234   on_unit_inactive_sec "15m"
235 end
236
237 service "osmf-crm-jobs.timer" do
238   action [:enable, :start]
239 end
240
241 template "/etc/cron.daily/osmf-crm-backup" do
242   source "backup.cron.erb"
243   owner "root"
244   group "root"
245   mode "750"
246   variables :passwords => passwords
247 end