5 # Copyright 2013, OpenStreetMap Foundation
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "apache"
22 include_recipe "nodejs"
23 include_recipe "postgresql"
24 include_recipe "tools"
26 blocks = data_bag_item("tile", "blocks")
29 apache_module "expires"
30 apache_module "headers"
31 apache_module "remoteip"
32 apache_module "rewrite"
34 package "libapache2-mod-tile"
36 apache_module "tile" do
40 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
42 apache_site "default" do
46 apache_site "tile.openstreetmap.org" do
48 variables :caches => tilecaches
51 template "/etc/logrotate.d/apache2" do
52 source "logrotate.apache.erb"
58 directory "/srv/tile.openstreetmap.org" do
67 action [ :enable, :start ]
68 supports :status => false, :restart => true, :reload => false
71 directory node[:tile][:tile_directory] do
77 if node[:tile][:tile_directory] != "/srv/tile.openstreetmap.org/tiles"
78 link "/srv/tile.openstreetmap.org/tiles" do
79 to node[:tile][:tile_directory]
83 template "/etc/renderd.conf" do
84 source "renderd.conf.erb"
88 notifies :reload, resources(:service => "apache2")
89 notifies :restart, resources(:service => "renderd")
92 remote_directory "/srv/tile.openstreetmap.org/html" do
102 package "python-cairo"
103 package "python-mapnik"
105 directory "/srv/tile.openstreetmap.org/cgi-bin" do
111 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
116 variables :blocks => blocks
119 directory "/srv/tile.openstreetmap.org/data" do
125 node[:tile][:data].each do |name,data|
127 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
128 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
130 directory directory do
141 command "tar -zxf #{file} -C #{directory}"
145 elsif file =~ /\.tar\.bz2$/
150 command "tar -jxf #{file} -C #{directory}"
154 elsif file =~ /\.zip$/
159 command "unzip -qq #{file} -d #{directory}"
166 original = "#{directory}/#{data[:original]}"
167 processed = "#{directory}/#{data[:processed]}"
173 command "ogr2ogr #{processed} #{original}"
176 subscribes :run, resources(:execute => file), :immediately
180 execute "#{file}_shapeindex" do
182 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
185 subscribes :run, resources(:execute => file), :immediately
189 action :create_if_missing
194 notifies :run, resources(:execute => file), :immediately
195 notifies :restart, resources(:service => "renderd")
199 nodejs_package "carto"
200 nodejs_package "millstone"
202 directory "/srv/tile.openstreetmap.org/styles" do
208 node[:tile][:styles].each do |name,details|
209 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
210 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
212 template "/usr/local/bin/update-lowzoom-#{name}" do
213 source "update-lowzoom.erb"
217 variables :style => name
220 template "/etc/init.d/update-lowzoom-#{name}" do
221 source "update-lowzoom.init.erb"
225 variables :style => name
228 service "update-lowzoom-#{name}" do
230 supports :restart => true
233 directory tile_directory do
239 file "#{tile_directory}/planet-import-complete" do
240 action :create_if_missing
246 git style_directory do
248 repository details[:repository]
249 revision details[:revision]
254 link "#{style_directory}/data" do
255 to "/srv/tile.openstreetmap.org/data"
260 execute "#{style_directory}/project.mml" do
262 command "carto project.mml > project.xml"
266 subscribes :run, "git[#{style_directory}]"
267 notifies :restart, "service[renderd]", :immediately
268 notifies :restart, "service[update-lowzoom-#{name}]"
274 postgresql_user "jburgess" do
275 cluster node[:tile][:database][:cluster]
279 postgresql_user "tomh" do
280 cluster node[:tile][:database][:cluster]
284 postgresql_user "tile" do
285 cluster node[:tile][:database][:cluster]
288 postgresql_user "www-data" do
289 cluster node[:tile][:database][:cluster]
292 postgresql_database "gis" do
293 cluster node[:tile][:database][:cluster]
297 postgresql_extension "postgis" do
298 cluster node[:tile][:database][:cluster]
302 [ "geography_columns",
308 "spatial_ref_sys" ].each do |table|
309 postgresql_table table do
310 cluster node[:tile][:database][:cluster]
313 permissions "tile" => :all
317 [ "geometry_columns",
320 "planet_osm_polygon",
322 "planet_osm_nodes" ].each do |table|
323 postgresql_table table do
324 cluster node[:tile][:database][:cluster]
327 permissions "tile" => :all, "www-data" => :select
331 postgresql_munin "gis" do
332 cluster node[:tile][:database][:cluster]
336 #if node[:tile][:node_file]
337 # file node[:tile][:node_file] do
344 directory "/var/log/tile" do
356 package "libproj-dev"
357 package "libxml2-dev"
360 gem_package "proj4rb"
361 gem_package "libxml-ruby"
364 remote_directory "/usr/local/lib/site_ruby" do
374 template "/usr/local/bin/expire-tiles" do
375 source "expire-tiles.erb"
381 template "/etc/sudoers.d/tile" do
388 directory "/var/lib/replicate" do
394 template "/var/lib/replicate/configuration.txt" do
395 source "replicate.configuration.erb"
401 template "/usr/local/bin/replicate" do
402 source "replicate.erb"
408 template "/etc/init.d/replicate" do
409 source "replicate.init.erb"
415 service "replicate" do
416 action [ :enable, :start ]
417 supports :restart => true
418 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
419 subscribes :restart, resources(:template => "/etc/init.d/replicate")
422 template "/etc/logrotate.d/replicate" do
423 source "replicate.logrotate.erb"
429 template "/usr/local/bin/render-lowzoom" do
430 source "render-lowzoom.erb"
436 template "/etc/cron.d/render-lowzoom" do
437 source "render-lowzoom.cron.erb"
443 template "/etc/rsyslog.d/20-renderd.conf" do
444 source "renderd.rsyslog.erb"
448 notifies :restart, "service[rsyslog]"
451 munin_plugin "mod_tile_fresh"
452 munin_plugin "mod_tile_response"
453 munin_plugin "mod_tile_zoom"
454 munin_plugin "mod_tile_latency"
456 munin_plugin "renderd_processed"
457 munin_plugin "renderd_queue"
458 munin_plugin "renderd_zoom"
459 munin_plugin "renderd_zoom_time"
461 munin_plugin "replication_delay" do