]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
civicrm: rename to supportings.openstreetmap.org
[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 apache_site "join.osmfoundation.org" do
51   action :disable
52 end
53
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
61 end
62
63 wordpress_theme "osmblog-wp-theme" do
64   site "supporting.openstreetmap.org"
65   repository "https://github.com/osmfoundation/osmblog-wp-theme.git"
66 end
67
68 wordpress_plugin "registration-honeypot" do
69   site "supporting.openstreetmap.org"
70 end
71
72 wordpress_plugin "contact-form-7" do
73   site "supporting.openstreetmap.org"
74 end
75
76 wordpress_plugin "civicrm-admin-utilities" do
77   site "supporting.openstreetmap.org"
78 end
79
80 civicrm_version = node[:civicrm][:version]
81 civicrm_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm"
82
83 directory "/opt/civicrm-#{civicrm_version}" do
84   owner "wordpress"
85   group "wordpress"
86   mode "755"
87 end
88
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"
92   owner "wordpress"
93   group "wordpress"
94   mode "644"
95   backup false
96 end
97
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"
101   owner "wordpress"
102   group "wordpress"
103   mode "644"
104   backup false
105 end
106
107 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
108   action :nothing
109   destination "/opt/civicrm-#{civicrm_version}"
110   overwrite true
111   owner "wordpress"
112   group "wordpress"
113   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
114 end
115
116 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
117   action :nothing
118   destination "/opt/civicrm-#{civicrm_version}/civicrm"
119   overwrite true
120   owner "wordpress"
121   group "wordpress"
122   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
123 end
124
125 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
126   action :nothing
127   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
128   user "wordpress"
129   group "wordpress"
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
132 end
133
134 directory "/srv/supporting.openstreetmap.org/wp-content/uploads" do
135   owner "www-data"
136   group "www-data"
137   mode "755"
138 end
139
140 extensions_directory = "/srv/supporting.openstreetmap.org/wp-content/plugins/civicrm-extensions"
141
142 directory extensions_directory do
143   owner "wordpress"
144   group "wordpress"
145   mode "755"
146 end
147
148 node[:civicrm][:extensions].each_value do |details|
149   git "#{extensions_directory}/#{details[:name]}" do
150     action :sync
151     repository details[:repository]
152     revision details[:revision]
153     user "wordpress"
154     group "wordpress"
155   end
156 end
157
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');")
175
176   line
177 end
178
179 file "#{civicrm_directory}/civicrm.settings.php" do
180   owner "wordpress"
181   group "wordpress"
182   mode "644"
183   content settings
184 end
185
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"
189   user "www-data"
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"
194 end
195
196 systemd_timer "osmf-crm-jobs" do
197   description "Run CRM jobs"
198   on_boot_sec "15m"
199   on_unit_inactive_sec "15m"
200 end
201
202 service "osmf-crm-jobs.timer" do
203   action [:enable, :start]
204 end
205
206 template "/etc/cron.daily/osmf-crm-backup" do
207   source "backup.cron.erb"
208   owner "root"
209   group "root"
210   mode "750"
211   variables :passwords => passwords
212 end