]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Add initial version of prometheus cookbook
[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 ]
30
31 cache_dir = Chef::Config[:file_cache_path]
32
33 passwords = data_bag_item("civicrm", "passwords")
34
35 database_password = passwords["database"]
36 site_key = passwords["key"]
37
38 mysql_user "civicrm@localhost" do
39   password database_password
40 end
41
42 mysql_database "civicrm" do
43   permissions "civicrm@localhost" => :all
44 end
45
46 wordpress_site "join.osmfoundation.org" do
47   aliases "crm.osmfoundation.org"
48   database_name "civicrm"
49   database_user "civicrm"
50   database_password database_password
51 end
52
53 wordpress_theme "osmblog-wp-theme" do
54   site "join.osmfoundation.org"
55   repository "https://github.com/harry-wood/osmblog-wp-theme.git"
56 end
57
58 wordpress_plugin "registration-honeypot" do
59   site "join.osmfoundation.org"
60 end
61
62 wordpress_plugin "sitepress-multilingual-cms" do
63   site "join.osmfoundation.org"
64   repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
65   not_if { ENV["TEST_KITCHEN"] }
66 end
67
68 wordpress_plugin "contact-form-7" 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 execute "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
100   action :nothing
101   command "unzip -o -qq #{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip"
102   cwd "/opt/civicrm-#{civicrm_version}"
103   user "wordpress"
104   group "wordpress"
105   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
106 end
107
108 execute "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
109   action :nothing
110   command "tar -zxf #{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz"
111   cwd "/opt/civicrm-#{civicrm_version}/civicrm"
112   user "wordpress"
113   group "wordpress"
114   subscribes :run, "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, "execute[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
123   subscribes :run, "execute[#{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