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"
33 apache_module "rewrite"
35 cache_dir = Chef::Config[:file_cache_path]
37 passwords = data_bag_item("civicrm", "passwords")
38 wp2fa_encrypt_keys = data_bag_item("civicrm", "wp2fa_encrypt_keys")
40 database_password = passwords["database"]
41 site_key = passwords["site_key"]
42 cred_keys = passwords["cred_keys"]
43 sign_keys = passwords["sign_keys"]
45 mysql_user "civicrm@localhost" do
46 password database_password
49 mysql_database "civicrm" do
50 permissions "civicrm@localhost" => :all
53 wordpress_site "supporting.openstreetmap.org" do
56 donate.openstreetmap.org
57 donate.openstreetmap.com
58 donate.openstreetmap.net
60 join.osmfoundation.org
61 supporting.osmfoundation.org
62 support.osmfoundation.org
63 support.openstreetmap.org
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
74 wordpress_plugin "civicrm-wp-piwik" do
76 site "supporting.openstreetmap.org"
79 wordpress_plugin "registration-honeypot" do
80 site "supporting.openstreetmap.org"
83 wordpress_plugin "contact-form-7" do
84 site "supporting.openstreetmap.org"
87 wordpress_plugin "civicrm-admin-utilities" do
88 site "supporting.openstreetmap.org"
91 wordpress_plugin "host-webfonts-local" do
92 site "supporting.openstreetmap.org"
95 wordpress_theme "morden" do
96 site "supporting.openstreetmap.org"
97 repository "https://public-api.wordpress.com/rest/v1/themes/download/morden.zip"
100 wordpress_theme "varia" do
101 site "supporting.openstreetmap.org"
102 repository "https://public-api.wordpress.com/rest/v1/themes/download/varia.zip"
105 civicrm_version = node[:civicrm][:version]
106 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
108 directory "/opt/civicrm-#{civicrm_version}" do
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"
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"
132 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
134 destination "/opt/civicrm-#{civicrm_version}"
138 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
141 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
143 destination "/opt/civicrm-#{civicrm_version}/civicrm"
147 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
150 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
152 command "rsync --archive --delete --delete-delay --delay-updates /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
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
159 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
165 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
167 directory extensions_directory do
173 node[:civicrm][:extensions].each_value do |details|
174 if details[:repository]
175 git "#{extensions_directory}/#{details[:name]}" do
177 repository details[:repository]
178 revision details[:revision]
183 remote_file "#{cache_dir}/#{details[:name]}.zip" do
191 archive_file "#{cache_dir}/#{details[:name]}.zip" do
193 destination "#{extensions_directory}/#{details[:name]}"
198 subscribes :extract, "remote_file[#{cache_dir}/#{details[:name]}.zip]", :immediately
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);")
226 directory "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm" do
232 file "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/civicrm.settings.php" do
239 file "#{civicrm_directory}/civicrm.settings.php" do
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"
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"
253 systemd_timer "osmf-crm-jobs" do
254 description "Run CRM jobs"
256 on_unit_inactive_sec "15m"
259 service "osmf-crm-jobs.timer" do
260 action [:enable, :start]
263 template "/etc/cron.daily/osmf-crm-backup" do
264 source "backup.cron.erb"
268 variables :passwords => passwords