]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
civicrm: Add additional required php extensions
[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   rsync
25   php-curl
26   php-bcmath
27   php-fileinfo
28   php-intl
29   php-mbstring
30   php-xml
31 ]
32
33 apache_module "rewrite"
34
35 cache_dir = Chef::Config[:file_cache_path]
36
37 passwords = data_bag_item("civicrm", "passwords")
38 wp2fa_encrypt_keys = data_bag_item("civicrm", "wp2fa_encrypt_keys")
39
40 database_password = passwords["database"]
41 site_key = passwords["site_key"]
42 cred_keys = passwords["cred_keys"]
43 sign_keys = passwords["sign_keys"]
44
45 mysql_user "civicrm@localhost" do
46   password database_password
47 end
48
49 mysql_database "civicrm" do
50   permissions "civicrm@localhost" => :all
51 end
52
53 wordpress_site "supporting.openstreetmap.org" do
54   aliases %w[
55     crm.osmfoundation.org
56     donate.openstreetmap.org
57     donate.openstreetmap.com
58     donate.openstreetmap.net
59     donate.osm.org
60     join.osmfoundation.org
61     supporting.osmfoundation.org
62     support.osmfoundation.org
63     support.openstreetmap.org
64     supporting.osm.org
65     support.osm.org
66   ]
67   database_name "civicrm"
68   database_user "civicrm"
69   database_password database_password
70   wp2fa_encrypt_key wp2fa_encrypt_keys["key"]
71   fpm_prometheus_port 11301
72 end
73
74 wordpress_plugin "civicrm-wp-piwik" do
75   plugin "wp-piwik"
76   site "supporting.openstreetmap.org"
77 end
78
79 wordpress_plugin "registration-honeypot" do
80   site "supporting.openstreetmap.org"
81 end
82
83 wordpress_plugin "contact-form-7" do
84   site "supporting.openstreetmap.org"
85 end
86
87 wordpress_plugin "civicrm-admin-utilities" do
88   site "supporting.openstreetmap.org"
89 end
90
91 wordpress_plugin "host-webfonts-local" do
92   site "supporting.openstreetmap.org"
93 end
94
95 wordpress_theme "morden" do
96   site "supporting.openstreetmap.org"
97   repository "https://public-api.wordpress.com/rest/v1/themes/download/morden.zip"
98 end
99
100 wordpress_theme "varia" do
101   site "supporting.openstreetmap.org"
102   repository "https://public-api.wordpress.com/rest/v1/themes/download/varia.zip"
103 end
104
105 civicrm_version = node[:civicrm][:version]
106 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
107
108 directory "/opt/civicrm-#{civicrm_version}" do
109   owner "wordpress"
110   group "wordpress"
111   mode "755"
112 end
113
114 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
115   action :create_if_missing
116   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
117   owner "wordpress"
118   group "wordpress"
119   mode "644"
120   backup false
121 end
122
123 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
124   action :create_if_missing
125   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
126   owner "wordpress"
127   group "wordpress"
128   mode "644"
129   backup false
130 end
131
132 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
133   action :nothing
134   destination "/opt/civicrm-#{civicrm_version}"
135   overwrite true
136   owner "wordpress"
137   group "wordpress"
138   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
139 end
140
141 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
142   action :nothing
143   destination "/opt/civicrm-#{civicrm_version}/civicrm"
144   overwrite true
145   owner "wordpress"
146   group "wordpress"
147   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
148 end
149
150 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
151   action :nothing
152   command "rsync --archive --delete --delete-delay --delay-updates /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
153   user "wordpress"
154   group "wordpress"
155   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
156   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
157 end
158
159 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
160   owner "www-data"
161   group "www-data"
162   mode "755"
163 end
164
165 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
166
167 directory extensions_directory do
168   owner "wordpress"
169   group "wordpress"
170   mode "755"
171 end
172
173 node[:civicrm][:extensions].each_value do |details|
174   if details[:repository]
175     git "#{extensions_directory}/#{details[:name]}" do
176       action :sync
177       repository details[:repository]
178       revision details[:revision]
179       user "wordpress"
180       group "wordpress"
181     end
182   elsif details[:zip]
183     remote_file "#{cache_dir}/#{details[:name]}.zip" do
184       source details[:zip]
185       owner "root"
186       group "root"
187       mode "644"
188       backup false
189     end
190
191     archive_file "#{cache_dir}/#{details[:name]}.zip" do
192       action :nothing
193       destination "#{extensions_directory}/#{details[:name]}"
194       strip_components 1
195       owner "wordpress"
196       group "wordpress"
197       overwrite true
198       subscribes :extract, "remote_file[#{cache_dir}/#{details[:name]}.zip]", :immediately
199     end
200   end
201 end
202
203 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
204   line.gsub!("%%cms%%", "WordPress")
205   line.gsub!("%%CMSdbUser%%", "civicrm")
206   line.gsub!("%%CMSdbPass%%", database_password)
207   line.gsub!("%%CMSdbHost%%", "localhost")
208   line.gsub!("%%CMSdbName%%", "civicrm")
209   line.gsub!("%%dbUser%%", "civicrm")
210   line.gsub!("%%dbPass%%", database_password)
211   line.gsub!("%%dbHost%%", "localhost")
212   line.gsub!("%%dbName%%", "civicrm")
213   line.gsub!("%%crmRoot%%", "#{civicrm_directory}/civicrm/")
214   line.gsub!("%%templateCompileDir%%", "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/templates_c/")
215   line.gsub!("%%baseURL%%", "http://supporting.openstreetmap.org/")
216   line.gsub!("%%siteKey%%", site_key)
217   line.gsub!("%%credKeys%%", cred_keys)
218   line.gsub!("%%signKeys%%", sign_keys)
219   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/supporting.openstreetmap.org');")
220   # Don't recompile smarty templates on every call https://docs.civicrm.org/sysadmin/en/latest/setup/optimizations/#disable-compile-check
221   line.gsub!(%r{//  define\('CIVICRM_TEMPLATE_COMPILE_CHECK', FALSE\);}, "define('CIVICRM_TEMPLATE_COMPILE_CHECK', FALSE);")
222
223   line
224 end
225
226 directory "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm" do
227   owner "www-data"
228   group "www-data"
229   mode "755"
230 end
231
232 file "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/civicrm.settings.php" do
233   owner "wordpress"
234   group "wordpress"
235   mode "644"
236   content settings
237 end
238
239 file "#{civicrm_directory}/civicrm.settings.php" do
240   action :delete
241 end
242
243 systemd_service "osmf-crm-jobs" do
244   description "Run CRM jobs"
245   exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s supporting.openstreetmap.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
246   user "www-data"
247   sandbox :enable_network => true
248   memory_deny_write_execute false
249   restrict_address_families "AF_UNIX"
250   read_write_paths "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm"
251 end
252
253 systemd_timer "osmf-crm-jobs" do
254   description "Run CRM jobs"
255   on_boot_sec "15m"
256   on_unit_inactive_sec "15m"
257 end
258
259 service "osmf-crm-jobs.timer" do
260   action [:enable, :start]
261 end
262
263 template "/etc/cron.daily/osmf-crm-backup" do
264   source "backup.cron.erb"
265   owner "root"
266   group "root"
267   mode "750"
268   variables :passwords => passwords
269 end