5 # Copyright:: 2011, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "wordpress"
21 include_recipe "mysql"
31 apache_module "rewrite"
33 cache_dir = Chef::Config[:file_cache_path]
35 passwords = data_bag_item("civicrm", "passwords")
36 wp2fa_encrypt_keys = data_bag_item("civicrm", "wp2fa_encrypt_keys")
38 database_password = passwords["database"]
39 site_key = passwords["site_key"]
40 cred_keys = passwords["cred_keys"]
41 sign_keys = passwords["sign_keys"]
43 mysql_user "civicrm@localhost" do
44 password database_password
47 mysql_database "civicrm" do
48 permissions "civicrm@localhost" => :all
51 wordpress_site "supporting.openstreetmap.org" do
54 donate.openstreetmap.org
55 donate.openstreetmap.com
56 donate.openstreetmap.net
58 join.osmfoundation.org
59 supporting.osmfoundation.org
60 support.osmfoundation.org
61 support.openstreetmap.org
65 database_name "civicrm"
66 database_user "civicrm"
67 database_password database_password
68 wp2fa_encrypt_key wp2fa_encrypt_keys["key"]
69 fpm_prometheus_port 11301
72 wordpress_plugin "civicrm-wp-piwik" do
74 site "supporting.openstreetmap.org"
77 wordpress_plugin "registration-honeypot" do
78 site "supporting.openstreetmap.org"
81 wordpress_plugin "contact-form-7" do
82 site "supporting.openstreetmap.org"
85 wordpress_plugin "civicrm-admin-utilities" do
86 site "supporting.openstreetmap.org"
89 wordpress_plugin "host-webfonts-local" do
90 site "supporting.openstreetmap.org"
93 wordpress_theme "morden" do
94 site "supporting.openstreetmap.org"
95 repository "https://public-api.wordpress.com/rest/v1/themes/download/morden.zip"
98 wordpress_theme "varia" do
99 site "supporting.openstreetmap.org"
100 repository "https://public-api.wordpress.com/rest/v1/themes/download/varia.zip"
103 civicrm_version = node[:civicrm][:version]
104 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
106 directory "/opt/civicrm-#{civicrm_version}" do
112 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
113 action :create_if_missing
114 source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
121 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
122 action :create_if_missing
123 source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
130 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
132 destination "/opt/civicrm-#{civicrm_version}"
136 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
139 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
141 destination "/opt/civicrm-#{civicrm_version}/civicrm"
145 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
148 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
150 command "rsync --archive --delete --delete-delay --delay-updates /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
153 subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
154 subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
157 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
163 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
165 directory extensions_directory do
171 node[:civicrm][:extensions].each_value do |details|
172 if details[:repository]
173 git "#{extensions_directory}/#{details[:name]}" do
175 repository details[:repository]
176 revision details[:revision]
181 remote_file "#{cache_dir}/#{details[:name]}.zip" do
189 archive_file "#{cache_dir}/#{details[:name]}.zip" do
191 destination "#{extensions_directory}/#{details[:name]}"
196 subscribes :extract, "remote_file[#{cache_dir}/#{details[:name]}.zip]", :immediately
201 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
202 line.gsub!("%%cms%%", "WordPress")
203 line.gsub!("%%CMSdbUser%%", "civicrm")
204 line.gsub!("%%CMSdbPass%%", database_password)
205 line.gsub!("%%CMSdbHost%%", "localhost")
206 line.gsub!("%%CMSdbName%%", "civicrm")
207 line.gsub!("%%dbUser%%", "civicrm")
208 line.gsub!("%%dbPass%%", database_password)
209 line.gsub!("%%dbHost%%", "localhost")
210 line.gsub!("%%dbName%%", "civicrm")
211 line.gsub!("%%crmRoot%%", "#{civicrm_directory}/civicrm/")
212 line.gsub!("%%templateCompileDir%%", "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/templates_c/")
213 line.gsub!("%%baseURL%%", "http://supporting.openstreetmap.org/")
214 line.gsub!("%%siteKey%%", site_key)
215 line.gsub!("%%credKeys%%", cred_keys)
216 line.gsub!("%%signKeys%%", sign_keys)
217 line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/supporting.openstreetmap.org');")
218 # Don't recompile smarty templates on every call https://docs.civicrm.org/sysadmin/en/latest/setup/optimizations/#disable-compile-check
219 line.gsub!(%r{// define\('CIVICRM_TEMPLATE_COMPILE_CHECK', FALSE\);}, "define('CIVICRM_TEMPLATE_COMPILE_CHECK', FALSE);")
224 directory "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm" do
230 file "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/civicrm.settings.php" do
237 file "#{civicrm_directory}/civicrm.settings.php" do
241 systemd_service "osmf-crm-jobs" do
242 description "Run CRM jobs"
243 exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s supporting.openstreetmap.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
245 sandbox :enable_network => true
246 memory_deny_write_execute false
247 restrict_address_families "AF_UNIX"
248 read_write_paths "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm"
251 systemd_timer "osmf-crm-jobs" do
252 description "Run CRM jobs"
254 on_unit_inactive_sec "15m"
257 service "osmf-crm-jobs.timer" do
258 action [:enable, :start]
261 template "/etc/cron.daily/osmf-crm-backup" do
262 source "backup.cron.erb"
266 variables :passwords => passwords