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