]> git.openstreetmap.org Git - chef.git/blob - cookbooks/nominatim/recipes/default.rb
ba010b0d6c5793a59f50bd396a1ef94f3a0765e3
[chef.git] / cookbooks / nominatim / recipes / default.rb
1 #
2 # Cookbook Name:: nominatim
3 # Recipe:: default
4 #
5 # Copyright 2012, 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 #     http://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 "apache::ssl"
21 include_recipe "postgresql"
22 include_recipe "git"
23
24 package "php5"
25 package "php5-cli"
26 package "php5-pgsql"
27 package "php5-fpm"
28 package "php-pear"
29 package "php-apc"
30
31 apache_module "rewrite"
32
33 if node[:lsb][:release].to_f >= 14.04
34   apache_module "proxy"
35   apache_module "proxy_fcgi"
36 else
37   apache_module "fastcgi-handler"
38 end
39
40 home_directory = data_bag_item("accounts", "nominatim")["home"]
41 source_directory = "#{home_directory}/nominatim"
42 email_errors = data_bag_item("accounts", "lonvia")["email"]
43
44 database_cluster = node[:nominatim][:database][:cluster]
45 database_version = database_cluster.sub(/\/.*/, "")
46 database_name = node[:nominatim][:database][:dbname]
47
48 postgis_version = node[:nominatim][:database][:postgis]
49
50 service "php5-fpm" do
51   action [ :enable, :start ]
52   supports :status => true, :restart => true, :reload => true
53 end
54
55 apache_site "nominatim.openstreetmap.org" do
56   template "apache.erb"
57   directory source_directory
58   variables :pools => node[:nominatim][:fpm_pools]
59 end
60
61 node[:nominatim][:fpm_pools].each do |name,data|
62   template "/etc/php5/fpm/pool.d/#{name}.conf" do
63     source "fpm.conf.erb"
64     owner "root"
65     group "root"
66     mode 0644
67     variables data.merge(:name => name)
68     notifies :reload, "service[php5-fpm]"
69   end
70 end
71
72 postgresql_user "tomh" do
73   cluster database_cluster
74   superuser true
75 end
76
77 postgresql_user "lonvia" do
78   cluster database_cluster
79   superuser true
80 end
81
82 postgresql_user "twain" do
83   cluster database_cluster
84   superuser true
85 end
86
87 postgresql_user "nominatim" do
88   cluster database_cluster
89   superuser true
90 end
91
92 postgresql_user "www-data" do
93   cluster database_cluster
94 end
95
96 postgresql_munin "nominatim" do
97   cluster database_cluster
98   database database_name
99 end
100
101 directory "/var/log/nominatim" do
102   owner "nominatim"
103   group "nominatim"
104   mode 0755
105 end
106
107 template "/etc/logrotate.d/nominatim" do
108   source "logrotate.nominatim.erb"
109   owner "root"
110   group "root"
111   mode 0644
112 end
113
114
115 package "osmosis"
116 package "gcc"
117 package "proj-bin"
118 package "libgeos-c1"
119 package "postgresql-#{database_version}-postgis-#{postgis_version}"
120 package "postgresql-server-dev-#{database_version}"
121 package "build-essential"
122 package "libxml2-dev"
123 package "libgeos-dev"
124 package "libgeos++-dev"
125 package "libpq-dev"
126 package "libbz2-dev"
127 package "libtool"
128 package "automake"
129 package "libproj-dev"
130 package "libprotobuf-c0-dev"
131 package "protobuf-c-compiler"
132 package "python-psycopg2"
133
134 execute "php-pear-db" do
135   command "pear install DB"
136   not_if { File.exists?("/usr/share/php/DB") }
137 end
138
139 execute "compile_nominatim" do
140   action :nothing
141   command "cd #{source_directory} && ./autogen.sh && ./configure && make"
142   user "nominatim"
143 end
144
145 git source_directory do
146   action :checkout
147   repository node[:nominatim][:repository]
148   enable_submodules true
149   user "nominatim"
150   group "nominatim"
151   notifies :run, "execute[compile_nominatim]"
152 end
153
154 directory "#{source_directory}/log" do
155   owner "nominatim"
156   group "nominatim"
157   mode 0755
158 end
159
160
161 template "#{source_directory}/.git/hooks/post-merge" do
162   source "update_source.erb"
163   owner  "nominatim"
164   group  "nominatim"
165   mode   0755
166   variables :source_directory => source_directory
167 end
168
169 template "#{source_directory}/settings/local.php" do
170   source "nominatim.erb"
171   owner "nominatim"
172   group "nominatim"
173   mode 0664
174 end
175
176 template "#{source_directory}/settings/ip_blocks.conf" do
177   action :create_if_missing
178   source "ipblocks.erb"
179   owner "nominatim"
180   group "nominatim"
181   mode 0664
182 end
183
184 file "#{source_directory}/settings/apache_blocks.conf" do
185   action :create_if_missing
186   owner "nominatim"
187   group "nominatim"
188   mode 0664
189 end
190
191 file "#{source_directory}/settings/ip_blocks.map" do
192   action :create_if_missing
193   owner "nominatim"
194   group "nominatim"
195   mode 0664
196 end
197
198 cron "nominatim_logrotate" do
199   hour "5"
200   minute "30"
201   weekday "0"
202   command "#{source_directory}/utils/cron_logrotate.sh"
203   user "nominatim"
204   mailto email_errors
205 end
206
207 cron "nominatim_banip" do
208   command "#{source_directory}/utils/cron_banip.py"
209   user "nominatim"
210   mailto email_errors
211 end
212
213 cron "nominatim_vacuum" do
214   hour "2"
215   minute "00"
216   command "#{source_directory}/utils/cron_vacuum.sh"
217   user "nominatim"
218   mailto email_errors
219 end
220
221 ['search', 'reverse'].each do |filename|
222   ['phpj', 'phpx'].each do |ext|
223     link "#{source_directory}/website/#{filename}.#{ext}" do
224       to "#{source_directory}/website/#{filename}.php"
225       user "nominatim"
226       group "nominatim"
227     end
228   end
229 end
230
231 template "#{source_directory}/utils/nominatim-update" do
232   source "updater.erb"
233   user   "nominatim"
234   group  "nominatim"
235   mode   0755
236 end
237
238 template "/etc/init.d/nominatim-update" do
239   source "updater.init.erb"
240   user   "nominatim"
241   group  "nominatim"
242   mode   0755
243   variables :source_directory => source_directory
244 end
245
246 munin_plugin_conf "nominatim" do
247   template "munin.erb"
248 end
249
250 munin_plugin "nominatim_importlag" do
251   target "#{source_directory}/munin/nominatim_importlag"
252 end
253
254 munin_plugin "nominatim_query_speed" do
255   target "#{source_directory}/munin/nominatim_query_speed"
256 end
257
258 munin_plugin "nominatim_requests" do
259   target "#{source_directory}/munin/nominatim_requests"
260 end
261
262 munin_plugin "nominatim_throttled_ips" do
263   target "#{source_directory}/munin/nominatim_throttled_ips"
264 end
265
266 template "/usr/local/bin/backup-nominatim" do
267   source "backup-nominatim.erb"
268   owner "root"
269   group "root"
270   mode 0755
271 end
272
273 cron "nominatim_backup" do
274   hour "3"
275   minute "00"
276   day "1"
277   command "/usr/local/bin/backup-nominatim"
278   user "nominatim"
279   mailto email_errors
280 end