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 apache_module "tile" do
38 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
40 apache_site "default" do
44 apache_site "tile.openstreetmap.org" do
46 variables :caches => tilecaches
49 template "/etc/logrotate.d/apache2" do
50 source "logrotate.apache.erb"
56 directory "/srv/tile.openstreetmap.org" do
65 action [ :enable, :start ]
66 supports :status => false, :restart => true, :reload => false
69 directory "/srv/tile.openstreetmap.org/tiles" do
75 template "/etc/renderd.conf" do
76 source "renderd.conf.erb"
80 notifies :reload, resources(:service => "apache2")
81 notifies :restart, resources(:service => "renderd")
84 remote_directory "/srv/tile.openstreetmap.org/html" do
94 template "/srv/tile.openstreetmap.org/html/index.html" do
95 source "index.html.erb"
101 package "python-cairo"
102 package "python-mapnik"
104 directory "/srv/tile.openstreetmap.org/cgi-bin" do
110 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
115 variables :blocks => blocks
118 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
125 template "/etc/cron.hourly/export" do
126 source "export.cron.erb"
132 directory "/srv/tile.openstreetmap.org/data" do
138 node[:tile][:data].each do |name,data|
140 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
141 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
143 directory directory do
154 command "tar -zxf #{file} -C #{directory}"
158 elsif file =~ /\.tar\.bz2$/
163 command "tar -jxf #{file} -C #{directory}"
167 elsif file =~ /\.zip$/
172 command "unzip -qq -o #{file} -d #{directory}"
179 original = "#{directory}/#{data[:original]}"
180 processed = "#{directory}/#{data[:processed]}"
186 command "ogr2ogr #{processed} #{original}"
189 subscribes :run, resources(:execute => file), :immediately
193 execute "#{file}_shapeindex" do
195 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
198 subscribes :run, resources(:execute => file), :immediately
204 use_conditional_get true
206 action :create_if_missing
214 notifies :run, resources(:execute => file), :immediately
215 notifies :restart, resources(:service => "renderd")
219 nodejs_package "carto"
220 nodejs_package "millstone"
222 directory "/srv/tile.openstreetmap.org/styles" do
228 node[:tile][:styles].each do |name,details|
229 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
230 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
232 template "/usr/local/bin/update-lowzoom-#{name}" do
233 source "update-lowzoom.erb"
237 variables :style => name
240 template "/etc/init.d/update-lowzoom-#{name}" do
241 source "update-lowzoom.init.erb"
245 variables :style => name
248 service "update-lowzoom-#{name}" do
250 supports :restart => true
253 directory tile_directory do
259 details[:tile_directories].each do |directory|
260 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
261 directory "#{directory[:name]}/#{zoom}" do
267 link "#{tile_directory}/#{zoom}" do
268 to "#{directory[:name]}/#{zoom}"
275 file "#{tile_directory}/planet-import-complete" do
276 action :create_if_missing
282 git style_directory do
284 repository details[:repository]
285 revision details[:revision]
290 link "#{style_directory}/data" do
291 to "/srv/tile.openstreetmap.org/data"
296 execute "#{style_directory}/project.mml" do
298 command "carto project.mml > project.xml"
302 subscribes :run, "git[#{style_directory}]"
303 notifies :restart, "service[renderd]", :immediately
304 notifies :restart, "service[update-lowzoom-#{name}]"
310 postgresql_user "jburgess" do
311 cluster node[:tile][:database][:cluster]
315 postgresql_user "tomh" do
316 cluster node[:tile][:database][:cluster]
320 postgresql_user "tile" do
321 cluster node[:tile][:database][:cluster]
324 postgresql_user "www-data" do
325 cluster node[:tile][:database][:cluster]
328 postgresql_database "gis" do
329 cluster node[:tile][:database][:cluster]
333 postgresql_extension "postgis" do
334 cluster node[:tile][:database][:cluster]
338 [ "geography_columns",
344 "spatial_ref_sys" ].each do |table|
345 postgresql_table table do
346 cluster node[:tile][:database][:cluster]
349 permissions "tile" => :all
353 [ "geometry_columns",
356 "planet_osm_polygon",
357 "planet_osm_roads" ].each do |table|
358 postgresql_table table do
359 cluster node[:tile][:database][:cluster]
362 permissions "tile" => :all, "www-data" => :select
366 postgresql_munin "gis" do
367 cluster node[:tile][:database][:cluster]
371 tile_uid = node[:etc][:passwd]["tile"][:uid]
372 www_data_gid = node[:etc][:group]["www-data"][:gid]
374 ruby_block node[:tile][:node_file] do
376 File.chown(tile_uid, www_data_gid, node[:tile][:node_file])
377 File.chmod(0640, node[:tile][:node_file])
380 stat = File.stat(node[:tile][:node_file])
381 stat.uid == tile_uid && stat.gid == www_data_gid && stat.mode == 0640
385 directory "/var/log/tile" do
397 package "libproj-dev"
398 package "libxml2-dev"
400 gem_package "proj4rb"
401 gem_package "libxml-ruby"
404 remote_directory "/usr/local/lib/site_ruby" do
414 template "/usr/local/bin/expire-tiles" do
415 source "expire-tiles.erb"
421 template "/etc/sudoers.d/tile" do
428 directory "/var/lib/replicate" do
434 template "/var/lib/replicate/configuration.txt" do
435 source "replicate.configuration.erb"
441 template "/usr/local/bin/replicate" do
442 source "replicate.erb"
448 template "/etc/init.d/replicate" do
449 source "replicate.init.erb"
455 service "replicate" do
456 action [ :enable, :start ]
457 supports :restart => true
458 subscribes :restart, resources(:template => "/usr/local/bin/replicate")
459 subscribes :restart, resources(:template => "/etc/init.d/replicate")
462 template "/etc/logrotate.d/replicate" do
463 source "replicate.logrotate.erb"
469 template "/usr/local/bin/render-lowzoom" do
470 source "render-lowzoom.erb"
476 template "/etc/cron.d/render-lowzoom" do
477 source "render-lowzoom.cron.erb"
483 template "/etc/rsyslog.d/20-renderd.conf" do
484 source "renderd.rsyslog.erb"
488 notifies :restart, "service[rsyslog]"
491 package "libfilesys-df-perl"
493 template "/usr/local/bin/cleanup-tiles" do
494 source "cleanup-tiles.erb"
500 tile_directories = node[:tile][:styles].collect do |name,style|
501 style[:tile_directories].collect { |directory| directory[:name] }
502 end.flatten.sort.uniq
504 template "/etc/cron.d/cleanup-tiles" do
505 source "cleanup-tiles.cron.erb"
509 variables :directories => tile_directories
512 munin_plugin "mod_tile_fresh"
513 munin_plugin "mod_tile_latency"
514 munin_plugin "mod_tile_response"
515 munin_plugin "mod_tile_zoom"
517 munin_plugin "renderd_processed"
518 munin_plugin "renderd_queue"
519 munin_plugin "renderd_queue_time"
520 munin_plugin "renderd_zoom"
521 munin_plugin "renderd_zoom_time"
523 munin_plugin "replication_delay" do