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