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