]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Merge remote-tracking branch 'github/pull/524'
[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
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/osmfoundation/osmblog-wp-theme.git"
58 end
59
60 wordpress_plugin "registration-honeypot" do
61   site "join.osmfoundation.org"
62 end
63
64 wordpress_plugin "contact-form-7" do
65   site "join.osmfoundation.org"
66 end
67
68 wordpress_plugin "civicrm-admin-utilities" do
69   site "join.osmfoundation.org"
70 end
71
72 civicrm_version = node[:civicrm][:version]
73 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
74
75 directory "/opt/civicrm-#{civicrm_version}" do
76   owner "wordpress"
77   group "wordpress"
78   mode "755"
79 end
80
81 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
82   action :create_if_missing
83   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
84   owner "wordpress"
85   group "wordpress"
86   mode "644"
87   backup false
88 end
89
90 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
91   action :create_if_missing
92   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
93   owner "wordpress"
94   group "wordpress"
95   mode "644"
96   backup false
97 end
98
99 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
100   action :nothing
101   destination "/opt/civicrm-#{civicrm_version}"
102   overwrite true
103   owner "wordpress"
104   group "wordpress"
105   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
106 end
107
108 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
109   action :nothing
110   destination "/opt/civicrm-#{civicrm_version}/civicrm"
111   overwrite true
112   owner "wordpress"
113   group "wordpress"
114   subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
115 end
116
117 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
118   action :nothing
119   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
120   user "wordpress"
121   group "wordpress"
122   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
123   subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
124 end
125
126 directory "/srv/join.osmfoundation.org/wp-content/uploads" do
127   owner "www-data"
128   group "www-data"
129   mode "755"
130 end
131
132 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
133
134 directory extensions_directory do
135   owner "wordpress"
136   group "wordpress"
137   mode "755"
138 end
139
140 node[:civicrm][:extensions].each_value do |details|
141   git "#{extensions_directory}/#{details[:name]}" do
142     action :sync
143     repository details[:repository]
144     revision details[:revision]
145     user "wordpress"
146     group "wordpress"
147   end
148 end
149
150 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
151   line.gsub!(/%%cms%%/, "WordPress")
152   line.gsub!(/%%CMSdbUser%%/, "civicrm")
153   line.gsub!(/%%CMSdbPass%%/, database_password)
154   line.gsub!(/%%CMSdbHost%%/, "localhost")
155   line.gsub!(/%%CMSdbName%%/, "civicrm")
156   line.gsub!(/%%dbUser%%/, "civicrm")
157   line.gsub!(/%%dbPass%%/, database_password)
158   line.gsub!(/%%dbHost%%/, "localhost")
159   line.gsub!(/%%dbName%%/, "civicrm")
160   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
161   line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/uploads/civicrm/templates_c/")
162   line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
163   line.gsub!(/%%siteKey%%/, site_key)
164   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
165
166   line
167 end
168
169 file "#{civicrm_directory}/civicrm.settings.php" do
170   owner "wordpress"
171   group "wordpress"
172   mode "644"
173   content settings
174 end
175
176 cron_d "osmf-crm" do
177   minute "*/15"
178   user "www-data"
179   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):'"
180   mailto "admins@openstreetmap.org"
181 end
182
183 template "/etc/cron.daily/osmf-crm-backup" do
184   source "backup.cron.erb"
185   owner "root"
186   group "root"
187   mode "750"
188   variables :passwords => passwords
189 end