]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
podman: revert to using default slirp4netns mtu
[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_plugin "civicrm-wp-piwik" do
74   plugin "wp-piwik"
75   site "supporting.openstreetmap.org"
76 end
77
78 wordpress_plugin "registration-honeypot" do
79   site "supporting.openstreetmap.org"
80 end
81
82 wordpress_plugin "contact-form-7" do
83   site "supporting.openstreetmap.org"
84 end
85
86 wordpress_plugin "civicrm-admin-utilities" do
87   site "supporting.openstreetmap.org"
88 end
89
90 wordpress_plugin "host-webfonts-local" do
91   site "supporting.openstreetmap.org"
92 end
93
94 civicrm_version = node[:civicrm][:version]
95 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
96
97 directory "/opt/civicrm-#{civicrm_version}" do
98   owner "wordpress"
99   group "wordpress"
100   mode "755"
101 end
102
103 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
104   action :create_if_missing
105   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
106   owner "wordpress"
107   group "wordpress"
108   mode "644"
109   backup false
110 end
111
112 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
113   action :create_if_missing
114   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
115   owner "wordpress"
116   group "wordpress"
117   mode "644"
118   backup false
119 end
120
121 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
122   action :nothing
123   destination "/opt/civicrm-#{civicrm_version}"
124   overwrite true
125   owner "wordpress"
126   group "wordpress"
127   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
128 end
129
130 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
131   action :nothing
132   destination "/opt/civicrm-#{civicrm_version}/civicrm"
133   overwrite true
134   owner "wordpress"
135   group "wordpress"
136   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
137 end
138
139 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
140   action :nothing
141   command "rsync --archive --delete --delete-delay --delay-updates /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
142   user "wordpress"
143   group "wordpress"
144   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
145   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
146 end
147
148 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
149   owner "www-data"
150   group "www-data"
151   mode "755"
152 end
153
154 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
155
156 directory extensions_directory do
157   owner "wordpress"
158   group "wordpress"
159   mode "755"
160 end
161
162 node[:civicrm][:extensions].each_value do |details|
163   if details[:repository]
164     git "#{extensions_directory}/#{details[:name]}" do
165       action :sync
166       repository details[:repository]
167       revision details[:revision]
168       user "wordpress"
169       group "wordpress"
170     end
171   elsif details[:zip]
172     remote_file "#{cache_dir}/#{details[:name]}.zip" do
173       source details[:zip]
174       owner "root"
175       group "root"
176       mode "644"
177       backup false
178     end
179
180     archive_file "#{cache_dir}/#{details[:name]}.zip" do
181       action :nothing
182       destination "#{extensions_directory}/#{details[:name]}"
183       strip_components 1
184       owner "wordpress"
185       group "wordpress"
186       overwrite true
187       subscribes :extract, "remote_file[#{cache_dir}/#{details[:name]}.zip]", :immediately
188     end
189   end
190 end
191
192 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
193   line.gsub!(/%%cms%%/, "WordPress")
194   line.gsub!(/%%CMSdbUser%%/, "civicrm")
195   line.gsub!(/%%CMSdbPass%%/, database_password)
196   line.gsub!(/%%CMSdbHost%%/, "localhost")
197   line.gsub!(/%%CMSdbName%%/, "civicrm")
198   line.gsub!(/%%dbUser%%/, "civicrm")
199   line.gsub!(/%%dbPass%%/, database_password)
200   line.gsub!(/%%dbHost%%/, "localhost")
201   line.gsub!(/%%dbName%%/, "civicrm")
202   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
203   line.gsub!(/%%templateCompileDir%%/, "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/templates_c/")
204   line.gsub!(/%%baseURL%%/, "http://supporting.openstreetmap.org/")
205   line.gsub!(/%%siteKey%%/, site_key)
206   line.gsub!(/%%credKeys%%/, cred_keys)
207   line.gsub!(/%%signKeys%%/, sign_keys)
208   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/supporting.openstreetmap.org');")
209
210   line
211 end
212
213 file "#{civicrm_directory}/civicrm.settings.php" do
214   owner "wordpress"
215   group "wordpress"
216   mode "644"
217   content settings
218 end
219
220 systemd_service "osmf-crm-jobs" do
221   description "Run CRM jobs"
222   exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s supporting.openstreetmap.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
223   user "www-data"
224   sandbox :enable_network => true
225   memory_deny_write_execute false
226   restrict_address_families "AF_UNIX"
227   read_write_paths "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm"
228 end
229
230 systemd_timer "osmf-crm-jobs" do
231   description "Run CRM jobs"
232   on_boot_sec "15m"
233   on_unit_inactive_sec "15m"
234 end
235
236 service "osmf-crm-jobs.timer" do
237   action [:enable, :start]
238 end
239
240 template "/etc/cron.daily/osmf-crm-backup" do
241   source "backup.cron.erb"
242   owner "root"
243   group "root"
244   mode "750"
245   variables :passwords => passwords
246 end