]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
0a7ae17b8254336b38164d38030f2593f49b6560
[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 cache_dir = Chef::Config[:file_cache_path]
33
34 passwords = data_bag_item("civicrm", "passwords")
35 wp2fa_encrypt_keys = data_bag_item("civicrm", "wp2fa_encrypt_keys")
36
37 database_password = passwords["database"]
38 site_key = passwords["site_key"]
39 cred_keys = passwords["cred_keys"]
40 sign_keys = passwords["sign_keys"]
41
42 mysql_user "civicrm@localhost" do
43   password database_password
44 end
45
46 mysql_database "civicrm" do
47   permissions "civicrm@localhost" => :all
48 end
49
50 ssl_certificate "join.osmfoundation.org" do
51   domains [ "join.osmfoundation.org", "crm.osmfoundation.org",
52             "supporting.osmfoundation.org", "support.osmfoundation.org",
53             "support.openstreetmap.org", "supporting.osm.org",
54             "support.osm.org"]
55   notifies :reload, "service[apache2]"
56 end
57
58 apache_site "join.osmfoundation.org" do
59   template "apache.erb"
60 end
61
62 wordpress_site "supporting.openstreetmap.org" do
63   # Do not add aliases as this causes issues with civicrm PHP sessions
64   database_name "civicrm"
65   database_user "civicrm"
66   database_password database_password
67   wp2fa_encrypt_key wp2fa_encrypt_keys["key"]
68   fpm_prometheus_port 11301
69 end
70
71 wordpress_theme "osmblog-wp-theme" do
72   site "supporting.openstreetmap.org"
73   repository "https://github.com/osmfoundation/osmblog-wp-theme.git"
74 end
75
76 wordpress_plugin "registration-honeypot" do
77   site "supporting.openstreetmap.org"
78 end
79
80 wordpress_plugin "contact-form-7" do
81   site "supporting.openstreetmap.org"
82 end
83
84 wordpress_plugin "civicrm-admin-utilities" do
85   site "supporting.openstreetmap.org"
86 end
87
88 civicrm_version = node[:civicrm][:version]
89 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
90
91 directory "/opt/civicrm-#{civicrm_version}" do
92   owner "wordpress"
93   group "wordpress"
94   mode "755"
95 end
96
97 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
98   action :create_if_missing
99   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
100   owner "wordpress"
101   group "wordpress"
102   mode "644"
103   backup false
104 end
105
106 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
107   action :create_if_missing
108   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
109   owner "wordpress"
110   group "wordpress"
111   mode "644"
112   backup false
113 end
114
115 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
116   action :nothing
117   destination "/opt/civicrm-#{civicrm_version}"
118   overwrite true
119   owner "wordpress"
120   group "wordpress"
121   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
122 end
123
124 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
125   action :nothing
126   destination "/opt/civicrm-#{civicrm_version}/civicrm"
127   overwrite true
128   owner "wordpress"
129   group "wordpress"
130   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
131 end
132
133 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
134   action :nothing
135   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
136   user "wordpress"
137   group "wordpress"
138   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
139   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
140 end
141
142 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
143   owner "www-data"
144   group "www-data"
145   mode "755"
146 end
147
148 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
149
150 directory extensions_directory do
151   owner "wordpress"
152   group "wordpress"
153   mode "755"
154 end
155
156 node[:civicrm][:extensions].each_value do |details|
157   git "#{extensions_directory}/#{details[:name]}" do
158     action :sync
159     repository details[:repository]
160     revision details[:revision]
161     user "wordpress"
162     group "wordpress"
163   end
164 end
165
166 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
167   line.gsub!(/%%cms%%/, "WordPress")
168   line.gsub!(/%%CMSdbUser%%/, "civicrm")
169   line.gsub!(/%%CMSdbPass%%/, database_password)
170   line.gsub!(/%%CMSdbHost%%/, "localhost")
171   line.gsub!(/%%CMSdbName%%/, "civicrm")
172   line.gsub!(/%%dbUser%%/, "civicrm")
173   line.gsub!(/%%dbPass%%/, database_password)
174   line.gsub!(/%%dbHost%%/, "localhost")
175   line.gsub!(/%%dbName%%/, "civicrm")
176   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
177   line.gsub!(/%%templateCompileDir%%/, "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm/templates_c/")
178   line.gsub!(/%%baseURL%%/, "http://supporting.openstreetmap.org/")
179   line.gsub!(/%%siteKey%%/, site_key)
180   line.gsub!(/%%credKeys%%/, cred_keys)
181   line.gsub!(/%%signKeys%%/, sign_keys)
182   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/supporting.openstreetmap.org');")
183
184   line
185 end
186
187 file "#{civicrm_directory}/civicrm.settings.php" do
188   owner "wordpress"
189   group "wordpress"
190   mode "644"
191   content settings
192 end
193
194 systemd_service "osmf-crm-jobs" do
195   description "Run CRM jobs"
196   exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s supporting.openstreetmap.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
197   user "www-data"
198   sandbox :enable_network => true
199   memory_deny_write_execute false
200   restrict_address_families "AF_UNIX"
201   read_write_paths "/srv/supporting.openstreetmap.org/wp-content/uploads/civicrm"
202 end
203
204 systemd_timer "osmf-crm-jobs" do
205   description "Run CRM jobs"
206   on_boot_sec "15m"
207   on_unit_inactive_sec "15m"
208 end
209
210 service "osmf-crm-jobs.timer" do
211   action [:enable, :start]
212 end
213
214 template "/etc/cron.daily/osmf-crm-backup" do
215   source "backup.cron.erb"
216   owner "root"
217   group "root"
218   mode "750"
219   variables :passwords => passwords
220 end