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
66 action [:enable, :start]
67 supports :status => false, :restart => true, :reload => false
70 directory "/srv/tile.openstreetmap.org/tiles" do
76 template "/etc/renderd.conf" do
77 source "renderd.conf.erb"
81 notifies :reload, "service[apache2]"
82 notifies :restart, "service[renderd]"
85 remote_directory "/srv/tile.openstreetmap.org/html" do
95 template "/srv/tile.openstreetmap.org/html/index.html" do
96 source "index.html.erb"
102 package "python-cairo"
103 package "python-mapnik"
106 package "ttf-unifont"
108 if node[:lsb][:release].to_f >= 16.04
109 package "fonts-droid-fallback"
111 package "fonts-droid"
114 package "fonts-sipa-arundina"
115 package "fonts-sil-padauk"
116 package "fonts-khmeros"
117 package "fonts-beng-extra"
118 package "fonts-gargi"
119 package "fonts-taml-tscu"
120 package "fonts-tibetan-machine"
122 directory "/srv/tile.openstreetmap.org/cgi-bin" do
128 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
133 variables :blocks => blocks
136 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
143 template "/etc/cron.hourly/export" do
144 source "export.cron.erb"
150 directory "/srv/tile.openstreetmap.org/data" do
156 package "mapnik-utils"
158 node[:tile][:data].each_value do |data|
160 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
163 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
165 directory directory do
171 directory = "/srv/tile.openstreetmap.org/data"
179 command "tar -zxf #{file} -C #{directory}"
183 elsif file =~ /\.tar\.bz2$/
188 command "tar -jxf #{file} -C #{directory}"
192 elsif file =~ /\.zip$/
197 command "unzip -qq -o #{file} -d #{directory}"
203 execute "#{file}_shapeindex" do
205 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
208 subscribes :run, "execute[#{file}]", :immediately
214 use_conditional_get true
217 action :create_if_missing
225 notifies :run, "execute[#{file}]", :immediately
226 notifies :restart, "service[renderd]"
230 nodejs_package "carto"
231 nodejs_package "millstone"
233 directory "/srv/tile.openstreetmap.org/styles" do
239 node[:tile][:styles].each do |name, details|
240 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
241 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
243 template "/usr/local/bin/update-lowzoom-#{name}" do
244 source "update-lowzoom.erb"
248 variables :style => name
251 template "/etc/init.d/update-lowzoom-#{name}" do
252 source "update-lowzoom.init.erb"
256 variables :style => name
259 service "update-lowzoom-#{name}" do
261 supports :restart => true
264 directory tile_directory do
270 details[:tile_directories].each do |directory|
271 directory directory[:name] do
277 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
278 directory "#{directory[:name]}/#{zoom}" do
284 link "#{tile_directory}/#{zoom}" do
285 to "#{directory[:name]}/#{zoom}"
292 file "#{tile_directory}/planet-import-complete" do
293 action :create_if_missing
299 git style_directory do
301 repository details[:repository]
302 revision details[:revision]
307 link "#{style_directory}/data" do
308 to "/srv/tile.openstreetmap.org/data"
313 execute "#{style_directory}/project.mml" do
315 command "carto project.mml > project.xml"
319 subscribes :run, "git[#{style_directory}]"
320 notifies :restart, "service[renderd]", :immediately
321 notifies :restart, "service[update-lowzoom-#{name}]"
327 postgresql_user "jburgess" do
328 cluster node[:tile][:database][:cluster]
332 postgresql_user "tomh" do
333 cluster node[:tile][:database][:cluster]
337 postgresql_user "tile" do
338 cluster node[:tile][:database][:cluster]
341 postgresql_user "www-data" do
342 cluster node[:tile][:database][:cluster]
345 postgresql_database "gis" do
346 cluster node[:tile][:database][:cluster]
350 postgresql_extension "postgis" do
351 cluster node[:tile][:database][:cluster]
355 %w(geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys).each do |table|
356 postgresql_table table do
357 cluster node[:tile][:database][:cluster]
360 permissions "tile" => :all
364 %w(geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads).each do |table|
365 postgresql_table table do
366 cluster node[:tile][:database][:cluster]
369 permissions "tile" => :all, "www-data" => :select
373 postgresql_munin "gis" do
374 cluster node[:tile][:database][:cluster]
378 file node[:tile][:node_file] do
384 directory "/var/log/tile" do
396 package "libproj-dev"
397 package "libxml2-dev"
399 gem_package "proj4rb"
400 gem_package "libxml-ruby"
402 remote_directory "/usr/local/lib/site_ruby" do
412 template "/usr/local/bin/expire-tiles" do
413 source "expire-tiles.erb"
419 template "/etc/sudoers.d/tile" do
426 directory "/var/lib/replicate" do
432 template "/var/lib/replicate/configuration.txt" do
433 source "replicate.configuration.erb"
439 template "/usr/local/bin/replicate" do
440 source "replicate.erb"
446 template "/etc/init.d/replicate" do
447 source "replicate.init.erb"
453 service "replicate" do
454 action [:enable, :start]
455 supports :restart => true
456 subscribes :restart, "template[/usr/local/bin/replicate]"
457 subscribes :restart, "template[/etc/init.d/replicate]"
460 template "/etc/logrotate.d/replicate" do
461 source "replicate.logrotate.erb"
467 template "/usr/local/bin/render-lowzoom" do
468 source "render-lowzoom.erb"
474 template "/etc/cron.d/render-lowzoom" do
475 source "render-lowzoom.cron.erb"
481 if node[:lsb][:release].to_f >= 16.04
482 file "/etc/rsyslog.d/20-renderd.conf" do
484 notifies :restart, "service[rsyslog]"
487 file "/etc/logrotate.d/renderd" do
491 template "/etc/rsyslog.d/20-renderd.conf" do
492 source "renderd.rsyslog.erb"
496 notifies :restart, "service[rsyslog]"
499 template "/etc/logrotate.d/renderd" do
500 source "renderd.logrotate.erb"
507 package "liblockfile-simple-perl"
508 package "libfilesys-df-perl"
510 template "/usr/local/bin/cleanup-tiles" do
511 source "cleanup-tiles.erb"
517 tile_directories = node[:tile][:styles].collect do |_, style|
518 style[:tile_directories].collect { |directory| directory[:name] }
519 end.flatten.sort.uniq
521 template "/etc/cron.d/cleanup-tiles" do
522 source "cleanup-tiles.cron.erb"
526 variables :directories => tile_directories
529 munin_plugin "mod_tile_fresh"
530 munin_plugin "mod_tile_latency"
531 munin_plugin "mod_tile_response"
532 munin_plugin "mod_tile_zoom"
534 munin_plugin "renderd_processed"
535 munin_plugin "renderd_queue"
536 munin_plugin "renderd_queue_time"
537 munin_plugin "renderd_zoom"
538 munin_plugin "renderd_zoom_time"
540 munin_plugin "replication_delay" do