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")
30 apache_module "expires"
31 apache_module "headers"
32 apache_module "remoteip"
33 apache_module "rewrite"
35 apache_module "tile" do
39 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
41 apache_site "default" do
45 apache_site "tile.openstreetmap.org" do
47 variables :caches => tilecaches
50 template "/etc/logrotate.d/apache2" do
51 source "logrotate.apache.erb"
57 directory "/srv/tile.openstreetmap.org" do
65 systemd_service "renderd" do
66 description "Mapnik rendering daemon"
67 after "postgresql.service"
68 wants "postgresql.service"
70 exec_start "/usr/bin/renderd -f"
81 action [:enable, :start]
84 directory "/srv/tile.openstreetmap.org/tiles" do
90 template "/etc/renderd.conf" do
91 source "renderd.conf.erb"
95 notifies :reload, "service[apache2]"
96 notifies :restart, "service[renderd]"
99 remote_directory "/srv/tile.openstreetmap.org/html" do
109 template "/srv/tile.openstreetmap.org/html/index.html" do
110 source "index.html.erb"
116 package "python-cairo"
117 package "python-mapnik"
120 package "ttf-unifont"
122 if node[:lsb][:release].to_f >= 16.04
123 package "fonts-droid-fallback"
125 package "fonts-droid"
128 package "fonts-sipa-arundina"
129 package "fonts-sil-padauk"
130 package "fonts-khmeros"
131 package "fonts-beng-extra"
132 package "fonts-gargi"
133 package "fonts-taml-tscu"
134 package "fonts-tibetan-machine"
136 directory "/srv/tile.openstreetmap.org/cgi-bin" do
142 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
147 variables :blocks => blocks
150 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
157 template "/etc/cron.hourly/export" do
158 source "export.cron.erb"
164 directory "/srv/tile.openstreetmap.org/data" do
170 package "mapnik-utils"
172 node[:tile][:data].each_value do |data|
174 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
177 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
179 directory directory do
185 directory = "/srv/tile.openstreetmap.org/data"
193 command "tar -zxf #{file} -C #{directory}"
197 elsif file =~ /\.tar\.bz2$/
202 command "tar -jxf #{file} -C #{directory}"
206 elsif file =~ /\.zip$/
211 command "unzip -qq -o #{file} -d #{directory}"
217 execute "#{file}_shapeindex" do
219 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
222 subscribes :run, "execute[#{file}]", :immediately
228 use_conditional_get true
231 action :create_if_missing
239 notifies :run, "execute[#{file}]", :immediately
240 notifies :restart, "service[renderd]"
244 nodejs_package "carto"
245 nodejs_package "millstone"
247 directory "/srv/tile.openstreetmap.org/styles" do
253 node[:tile][:styles].each do |name, details|
254 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
255 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
257 template "/usr/local/bin/update-lowzoom-#{name}" do
258 source "update-lowzoom.erb"
262 variables :style => name
265 template "/etc/init.d/update-lowzoom-#{name}" do
266 source "update-lowzoom.init.erb"
270 variables :style => name
273 service "update-lowzoom-#{name}" do
275 supports :restart => true
278 directory tile_directory do
284 details[:tile_directories].each do |directory|
285 directory directory[:name] do
291 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
292 directory "#{directory[:name]}/#{zoom}" do
298 link "#{tile_directory}/#{zoom}" do
299 to "#{directory[:name]}/#{zoom}"
306 file "#{tile_directory}/planet-import-complete" do
307 action :create_if_missing
313 git style_directory do
315 repository details[:repository]
316 revision details[:revision]
321 link "#{style_directory}/data" do
322 to "/srv/tile.openstreetmap.org/data"
327 execute "#{style_directory}/project.mml" do
329 command "carto project.mml > project.xml"
333 subscribes :run, "git[#{style_directory}]"
334 notifies :restart, "service[renderd]", :immediately
335 notifies :restart, "service[update-lowzoom-#{name}]"
341 postgresql_user "jburgess" do
342 cluster node[:tile][:database][:cluster]
346 postgresql_user "tomh" do
347 cluster node[:tile][:database][:cluster]
351 postgresql_user "tile" do
352 cluster node[:tile][:database][:cluster]
355 postgresql_user "www-data" do
356 cluster node[:tile][:database][:cluster]
359 postgresql_database "gis" do
360 cluster node[:tile][:database][:cluster]
364 postgresql_extension "postgis" do
365 cluster node[:tile][:database][:cluster]
369 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
370 postgresql_table table do
371 cluster node[:tile][:database][:cluster]
374 permissions "tile" => :all
378 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
379 postgresql_table table do
380 cluster node[:tile][:database][:cluster]
383 permissions "tile" => :all, "www-data" => :select
387 postgresql_munin "gis" do
388 cluster node[:tile][:database][:cluster]
392 file node[:tile][:node_file] do
398 directory "/var/log/tile" do
410 package "libproj-dev"
411 package "libxml2-dev"
413 gem_package "proj4rb"
414 gem_package "libxml-ruby"
416 remote_directory "/usr/local/lib/site_ruby" do
426 template "/usr/local/bin/expire-tiles" do
427 source "expire-tiles.erb"
433 template "/etc/sudoers.d/tile" do
440 directory "/var/lib/replicate" do
446 template "/var/lib/replicate/configuration.txt" do
447 source "replicate.configuration.erb"
453 template "/usr/local/bin/replicate" do
454 source "replicate.erb"
460 template "/etc/init.d/replicate" do
461 source "replicate.init.erb"
467 service "replicate" do
468 action [:enable, :start]
469 supports :restart => true
470 subscribes :restart, "template[/usr/local/bin/replicate]"
471 subscribes :restart, "template[/etc/init.d/replicate]"
474 template "/etc/logrotate.d/replicate" do
475 source "replicate.logrotate.erb"
481 template "/usr/local/bin/render-lowzoom" do
482 source "render-lowzoom.erb"
488 template "/etc/cron.d/render-lowzoom" do
489 source "render-lowzoom.cron.erb"
495 if node[:lsb][:release].to_f >= 16.04
496 file "/etc/rsyslog.d/20-renderd.conf" do
498 notifies :restart, "service[rsyslog]"
501 file "/etc/logrotate.d/renderd" do
505 template "/etc/rsyslog.d/20-renderd.conf" do
506 source "renderd.rsyslog.erb"
510 notifies :restart, "service[rsyslog]"
513 template "/etc/logrotate.d/renderd" do
514 source "renderd.logrotate.erb"
521 package "liblockfile-simple-perl"
522 package "libfilesys-df-perl"
524 template "/usr/local/bin/cleanup-tiles" do
525 source "cleanup-tiles.erb"
531 tile_directories = node[:tile][:styles].collect do |_, style|
532 style[:tile_directories].collect { |directory| directory[:name] }
533 end.flatten.sort.uniq
535 template "/etc/cron.d/cleanup-tiles" do
536 source "cleanup-tiles.cron.erb"
540 variables :directories => tile_directories
543 munin_plugin "mod_tile_fresh"
544 munin_plugin "mod_tile_latency"
545 munin_plugin "mod_tile_response"
546 munin_plugin "mod_tile_zoom"
548 munin_plugin "renderd_processed"
549 munin_plugin "renderd_queue"
550 munin_plugin "renderd_queue_time"
551 munin_plugin "renderd_zoom"
552 munin_plugin "renderd_zoom_time"
554 munin_plugin "replication_delay" do