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 cache_dir = Chef::Config[:file_cache_path]
34 passwords = data_bag_item("civicrm", "passwords")
35 wp2fa_encrypt_keys = data_bag_item("civicrm", "wp2fa_encrypt_keys")
37 database_password = passwords["database"]
38 site_key = passwords["site_key"]
39 cred_keys = passwords["cred_keys"]
40 sign_keys = passwords["sign_keys"]
42 mysql_user "civicrm@localhost" do
43 password database_password
46 mysql_database "civicrm" do
47 permissions "civicrm@localhost" => :all
50 apache_site "join.osmfoundation.org" do
54 wordpress_site "supporting.openstreetmap.org" do
55 aliases ["join.osmfoundation.org", "crm.osmfoundation.org", "supporting.osmfoundation.org", "support.osmfoundation.org", "support.openstreetmap.org", "supporting.osm.org", "support.osm.org"]
56 database_name "civicrm"
57 database_user "civicrm"
58 database_password database_password
59 wp2fa_encrypt_key wp2fa_encrypt_keys["key"]
60 fpm_prometheus_port 11301
63 wordpress_theme "osmblog-wp-theme" do
64 site "supporting.openstreetmap.org"
65 repository "https://github.com/osmfoundation/osmblog-wp-theme.git"
68 wordpress_plugin "registration-honeypot" do
69 site "supporting.openstreetmap.org"
72 wordpress_plugin "contact-form-7" do
73 site "supporting.openstreetmap.org"
76 wordpress_plugin "civicrm-admin-utilities" do
77 site "supporting.openstreetmap.org"
80 civicrm_version = node[:civicrm][:version]
81 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
83 directory "/opt/civicrm-#{civicrm_version}" do
89 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
90 action :create_if_missing
91 source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
98 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
99 action :create_if_missing
100 source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
107 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
109 destination "/opt/civicrm-#{civicrm_version}"
113 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
116 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
118 destination "/opt/civicrm-#{civicrm_version}/civicrm"
122 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
125 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
127 command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
130 subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
131 subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
134 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
140 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
142 directory extensions_directory do
148 node[:civicrm][:extensions].each_value do |details|
149 git "#{extensions_directory}/#{details[:name]}" do
151 repository details[:repository]
152 revision details[:revision]
158 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
159 line.gsub!(/%%cms%%/, "WordPress")
160 line.gsub!(/%%CMSdbUser%%/, "civicrm")
161 line.gsub!(/%%CMSdbPass%%/, database_password)
162 line.gsub!(/%%CMSdbHost%%/, "localhost")
163 line.gsub!(/%%CMSdbName%%/, "civicrm")
164 line.gsub!(/%%dbUser%%/, "civicrm")
165 line.gsub!(/%%dbPass%%/, database_password)
166 line.gsub!(/%%dbHost%%/, "localhost")
167 line.gsub!(/%%dbName%%/, "civicrm")
168 line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
169 line.gsub!(/%%templateCompileDir%%/, "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/templates_c/")
170 line.gsub!(/%%baseURL%%/, "http://supporting.openstreetmap.org/")
171 line.gsub!(/%%siteKey%%/, site_key)
172 line.gsub!(/%%credKeys%%/, cred_keys)
173 line.gsub!(/%%signKeys%%/, sign_keys)
174 line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/supporting.openstreetmap.org');")
179 file "#{civicrm_directory}/civicrm.settings.php" do
186 systemd_service "osmf-crm-jobs" do
187 description "Run CRM jobs"
188 exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s supporting.openstreetmap.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
190 sandbox :enable_network => true
191 memory_deny_write_execute false
192 restrict_address_families "AF_UNIX"
193 read_write_paths "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm"
196 systemd_timer "osmf-crm-jobs" do
197 description "Run CRM jobs"
199 on_unit_inactive_sec "15m"
202 service "osmf-crm-jobs.timer" do
203 action [:enable, :start]
206 template "/etc/cron.daily/osmf-crm-backup" do
207 source "backup.cron.erb"
211 variables :passwords => passwords