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"
32 apache_module "rewrite"
34 cache_dir = Chef::Config[:file_cache_path]
36 passwords = data_bag_item("civicrm", "passwords")
37 wp2fa_encrypt_keys = data_bag_item("civicrm", "wp2fa_encrypt_keys")
39 database_password = passwords["database"]
40 site_key = passwords["site_key"]
41 cred_keys = passwords["cred_keys"]
42 sign_keys = passwords["sign_keys"]
44 mysql_user "civicrm@localhost" do
45 password database_password
48 mysql_database "civicrm" do
49 permissions "civicrm@localhost" => :all
52 wordpress_site "supporting.openstreetmap.org" do
55 donate.openstreetmap.org
56 donate.openstreetmap.com
57 donate.openstreetmap.net
59 join.osmfoundation.org
60 supporting.osmfoundation.org
61 support.osmfoundation.org
62 support.openstreetmap.org
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
73 wordpress_theme "osmblog-wp-theme" do
74 site "supporting.openstreetmap.org"
75 repository "https://github.com/osmfoundation/osmblog-wp-theme.git"
78 wordpress_plugin "civicrm-wp-piwik" do
80 site "supporting.openstreetmap.org"
83 wordpress_plugin "registration-honeypot" do
84 site "supporting.openstreetmap.org"
87 wordpress_plugin "contact-form-7" do
88 site "supporting.openstreetmap.org"
91 wordpress_plugin "civicrm-admin-utilities" do
92 site "supporting.openstreetmap.org"
95 civicrm_version = node[:civicrm][:version]
96 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
98 directory "/opt/civicrm-#{civicrm_version}" do
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"
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"
122 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
124 destination "/opt/civicrm-#{civicrm_version}"
128 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
131 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
133 destination "/opt/civicrm-#{civicrm_version}/civicrm"
137 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
140 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
142 command "rsync --archive --delete --delete-delay --delay-updates /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
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
149 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
155 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
157 directory extensions_directory do
163 node[:civicrm][:extensions].each_value do |details|
164 git "#{extensions_directory}/#{details[:name]}" do
166 repository details[:repository]
167 revision details[:revision]
173 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
174 line.gsub!(/%%cms%%/, "WordPress")
175 line.gsub!(/%%CMSdbUser%%/, "civicrm")
176 line.gsub!(/%%CMSdbPass%%/, database_password)
177 line.gsub!(/%%CMSdbHost%%/, "localhost")
178 line.gsub!(/%%CMSdbName%%/, "civicrm")
179 line.gsub!(/%%dbUser%%/, "civicrm")
180 line.gsub!(/%%dbPass%%/, database_password)
181 line.gsub!(/%%dbHost%%/, "localhost")
182 line.gsub!(/%%dbName%%/, "civicrm")
183 line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
184 line.gsub!(/%%templateCompileDir%%/, "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/templates_c/")
185 line.gsub!(/%%baseURL%%/, "http://supporting.openstreetmap.org/")
186 line.gsub!(/%%siteKey%%/, site_key)
187 line.gsub!(/%%credKeys%%/, cred_keys)
188 line.gsub!(/%%signKeys%%/, sign_keys)
189 line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/supporting.openstreetmap.org');")
194 file "#{civicrm_directory}/civicrm.settings.php" do
201 systemd_service "osmf-crm-jobs" do
202 description "Run CRM jobs"
203 exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s supporting.openstreetmap.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
205 sandbox :enable_network => true
206 memory_deny_write_execute false
207 restrict_address_families "AF_UNIX"
208 read_write_paths "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm"
211 systemd_timer "osmf-crm-jobs" do
212 description "Run CRM jobs"
214 on_unit_inactive_sec "15m"
217 service "osmf-crm-jobs.timer" do
218 action [:enable, :start]
221 template "/etc/cron.daily/osmf-crm-backup" do
222 source "backup.cron.erb"
226 variables :passwords => passwords