]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Add OOB addresses for remaining G9s in Dublin
[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   unzip
28   wkhtmltopdf
29   php-bcmath
30 ]
31
32 cache_dir = Chef::Config[:file_cache_path]
33
34 passwords = data_bag_item("civicrm", "passwords")
35
36 database_password = passwords["database"]
37 site_key = passwords["key"]
38
39 mysql_user "civicrm@localhost" do
40   password database_password
41 end
42
43 mysql_database "civicrm" do
44   permissions "civicrm@localhost" => :all
45 end
46
47 wordpress_site "join.osmfoundation.org" do
48   aliases "crm.osmfoundation.org"
49   database_name "civicrm"
50   database_user "civicrm"
51   database_password database_password
52   fpm_prometheus_port 11301
53 end
54
55 wordpress_theme "osmblog-wp-theme" do
56   site "join.osmfoundation.org"
57   repository "https://github.com/harry-wood/osmblog-wp-theme.git"
58 end
59
60 wordpress_plugin "registration-honeypot" do
61   site "join.osmfoundation.org"
62 end
63
64 wordpress_plugin "sitepress-multilingual-cms" do
65   site "join.osmfoundation.org"
66   repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
67   not_if { kitchen? }
68 end
69
70 wordpress_plugin "contact-form-7" do
71   site "join.osmfoundation.org"
72 end
73
74 wordpress_plugin "civicrm-admin-utilities" do
75   site "join.osmfoundation.org"
76 end
77
78 civicrm_version = node[:civicrm][:version]
79 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
80
81 directory "/opt/civicrm-#{civicrm_version}" do
82   owner "wordpress"
83   group "wordpress"
84   mode "755"
85 end
86
87 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
88   action :create_if_missing
89   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
90   owner "wordpress"
91   group "wordpress"
92   mode "644"
93   backup false
94 end
95
96 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
97   action :create_if_missing
98   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
99   owner "wordpress"
100   group "wordpress"
101   mode "644"
102   backup false
103 end
104
105 execute "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
106   action :nothing
107   command "unzip -o -qq #{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip"
108   cwd "/opt/civicrm-#{civicrm_version}"
109   user "wordpress"
110   group "wordpress"
111   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
112 end
113
114 execute "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
115   action :nothing
116   command "tar -zxf #{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz"
117   cwd "/opt/civicrm-#{civicrm_version}/civicrm"
118   user "wordpress"
119   group "wordpress"
120   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
121 end
122
123 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
124   action :nothing
125   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
126   user "wordpress"
127   group "wordpress"
128   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
129   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
130 end
131
132 directory "/srv/join.osmfoundation.org/wp-content/uploads" do
133   owner "www-data"
134   group "www-data"
135   mode "755"
136 end
137
138 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
139
140 directory extensions_directory do
141   owner "wordpress"
142   group "wordpress"
143   mode "755"
144 end
145
146 node[:civicrm][:extensions].each_value do |details|
147   git "#{extensions_directory}/#{details[:name]}" do
148     action :sync
149     repository details[:repository]
150     revision details[:revision]
151     user "wordpress"
152     group "wordpress"
153   end
154 end
155
156 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
157   line.gsub!(/%%cms%%/, "WordPress")
158   line.gsub!(/%%CMSdbUser%%/, "civicrm")
159   line.gsub!(/%%CMSdbPass%%/, database_password)
160   line.gsub!(/%%CMSdbHost%%/, "localhost")
161   line.gsub!(/%%CMSdbName%%/, "civicrm")
162   line.gsub!(/%%dbUser%%/, "civicrm")
163   line.gsub!(/%%dbPass%%/, database_password)
164   line.gsub!(/%%dbHost%%/, "localhost")
165   line.gsub!(/%%dbName%%/, "civicrm")
166   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
167   line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/uploads/civicrm/templates_c/")
168   line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
169   line.gsub!(/%%siteKey%%/, site_key)
170   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
171
172   line
173 end
174
175 file "#{civicrm_directory}/civicrm.settings.php" do
176   owner "wordpress"
177   group "wordpress"
178   mode "644"
179   content settings
180 end
181
182 cron_d "osmf-crm" do
183   minute "*/15"
184   user "www-data"
185   command "php #{civicrm_directory}/civicrm/bin/cli.php -s join.osmfoundation.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute 2>&1 | egrep -v '^PHP (Deprecated|Warning):'"
186   mailto "admins@openstreetmap.org"
187 end
188
189 template "/etc/cron.daily/osmf-crm-backup" do
190   source "backup.cron.erb"
191   owner "root"
192   group "root"
193   mode "750"
194   variables :passwords => passwords
195 end