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