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 "python"
25 include_recipe "tools"
27 blocks = data_bag_item("tile", "blocks")
28 web_passwords = data_bag_item("web", "passwords")
32 apache_module "expires"
33 apache_module "headers"
34 apache_module "remoteip"
35 apache_module "rewrite"
37 apache_module "tile" do
41 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
43 apache_site "default" do
47 apache_site "tile.openstreetmap.org" do
49 variables :caches => tilecaches
52 template "/etc/logrotate.d/apache2" do
53 source "logrotate.apache.erb"
59 directory "/srv/tile.openstreetmap.org" do
67 systemd_service "renderd" do
68 description "Mapnik rendering daemon"
69 after "postgresql.service"
70 wants "postgresql.service"
72 exec_start "/usr/bin/renderd -f"
73 runtime_directory "renderd"
80 no_new_privileges true
85 action [:enable, :start]
86 subscribes :restart, "systemd_service[renderd]"
89 directory "/srv/tile.openstreetmap.org/tiles" do
95 template "/etc/renderd.conf" do
96 source "renderd.conf.erb"
100 notifies :reload, "service[apache2]"
101 notifies :restart, "service[renderd]"
104 remote_directory "/srv/tile.openstreetmap.org/html" do
114 template "/srv/tile.openstreetmap.org/html/index.html" do
115 source "index.html.erb"
121 package "python-cairo"
122 package "python-mapnik"
123 package "python-setuptools"
125 python_package "pyotp"
127 package "fonts-noto-cjk"
128 package "fonts-noto-hinted"
129 package "fonts-noto-unhinted"
130 package "fonts-hanazono"
131 package "ttf-unifont"
133 directory "/srv/tile.openstreetmap.org/cgi-bin" do
139 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
144 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
147 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
154 template "/etc/cron.hourly/export" do
155 source "export.cron.erb"
161 directory "/srv/tile.openstreetmap.org/data" do
167 package "mapnik-utils"
169 node[:tile][:data].each_value do |data|
171 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
174 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
176 directory directory do
182 directory = "/srv/tile.openstreetmap.org/data"
190 command "tar -zxf #{file} -C #{directory}"
194 elsif file =~ /\.tar\.bz2$/
199 command "tar -jxf #{file} -C #{directory}"
203 elsif file =~ /\.zip$/
208 command "unzip -qq -o #{file} -d #{directory}"
214 execute "#{file}_shapeindex" do
216 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
219 subscribes :run, "execute[#{file}]", :immediately
225 use_conditional_get true
228 action :create_if_missing
236 notifies :run, "execute[#{file}]", :immediately
237 notifies :restart, "service[renderd]"
241 nodejs_package "carto"
242 nodejs_package "millstone"
244 systemd_service "update-lowzoom@" do
245 description "Low zoom tile update service for %i layer"
247 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
251 protect_system "full"
253 no_new_privileges true
257 directory "/srv/tile.openstreetmap.org/styles" do
263 node[:tile][:styles].each do |name, details|
264 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
265 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
267 template "/usr/local/bin/update-lowzoom-#{name}" do
268 source "update-lowzoom.erb"
272 variables :style => name
275 service "update-lowzoom@#{name}" do
277 supports :restart => true
280 directory tile_directory do
286 details[:tile_directories].each do |directory|
287 directory directory[:name] do
293 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
294 directory "#{directory[:name]}/#{zoom}" do
300 link "#{tile_directory}/#{zoom}" do
301 to "#{directory[:name]}/#{zoom}"
308 file "#{tile_directory}/planet-import-complete" do
309 action :create_if_missing
315 git style_directory do
317 repository details[:repository]
318 revision details[:revision]
323 link "#{style_directory}/data" do
324 to "/srv/tile.openstreetmap.org/data"
329 execute "#{style_directory}/project.mml" do
331 command "carto -a 3.0.0 project.mml > project.xml"
335 subscribes :run, "git[#{style_directory}]"
336 notifies :restart, "service[renderd]", :immediately
337 notifies :restart, "service[update-lowzoom@#{name}]"
341 postgresql_version = node[:tile][:database][:cluster].split("/").first
344 package "postgresql-#{postgresql_version}-postgis-2.3"
346 postgresql_user "jburgess" do
347 cluster node[:tile][:database][:cluster]
351 postgresql_user "tomh" do
352 cluster node[:tile][:database][:cluster]
356 postgresql_user "tile" do
357 cluster node[:tile][:database][:cluster]
360 postgresql_user "www-data" do
361 cluster node[:tile][:database][:cluster]
364 postgresql_database "gis" do
365 cluster node[:tile][:database][:cluster]
369 postgresql_extension "postgis" do
370 cluster node[:tile][:database][:cluster]
374 postgresql_extension "hstore" do
375 cluster node[:tile][:database][:cluster]
379 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
380 postgresql_table table do
381 cluster node[:tile][:database][:cluster]
384 permissions "tile" => :all
388 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
389 postgresql_table table do
390 cluster node[:tile][:database][:cluster]
393 permissions "tile" => :all, "www-data" => :select
397 postgresql_munin "gis" do
398 cluster node[:tile][:database][:cluster]
402 file node[:tile][:node_file] do
408 directory "/var/log/tile" do
420 package "libproj-dev"
421 package "libxml2-dev"
423 gem_package "proj4rb"
424 gem_package "libxml-ruby"
426 remote_directory "/usr/local/lib/site_ruby" do
436 template "/usr/local/bin/expire-tiles" do
437 source "expire-tiles.erb"
443 directory "/var/lib/replicate" do
449 directory "/var/lib/replicate/expire-queue" do
455 template "/var/lib/replicate/configuration.txt" do
456 source "replicate.configuration.erb"
462 template "/usr/local/bin/replicate" do
463 source "replicate.erb"
469 systemd_service "expire-tiles" do
470 description "Tile dirtying service"
473 exec_start "/usr/local/bin/expire-tiles"
474 standard_output "null"
477 protect_system "full"
479 no_new_privileges true
482 systemd_path "expire-tiles" do
483 description "Tile dirtying trigger"
484 directory_not_empty "/var/lib/replicate/expire-queue"
487 service "expire-tiles.path" do
488 action [:enable, :start]
489 subscribes :restart, "systemd_path[expire-tiles]"
492 systemd_service "replicate" do
493 description "Rendering database replication service"
494 after "postgresql.service"
495 wants "postgresql.service"
497 exec_start "/usr/local/bin/replicate"
500 protect_system "full"
502 no_new_privileges true
506 service "replicate" do
507 action [:enable, :start]
508 subscribes :restart, "template[/usr/local/bin/replicate]"
509 subscribes :restart, "systemd_service[replicate]"
512 template "/etc/logrotate.d/replicate" do
513 source "replicate.logrotate.erb"
519 template "/usr/local/bin/render-lowzoom" do
520 source "render-lowzoom.erb"
526 template "/etc/cron.d/render-lowzoom" do
527 source "render-lowzoom.cron.erb"
533 package "liblockfile-simple-perl"
534 package "libfilesys-df-perl"
536 template "/usr/local/bin/cleanup-tiles" do
537 source "cleanup-tiles.erb"
543 tile_directories = node[:tile][:styles].collect do |_, style|
544 style[:tile_directories].collect { |directory| directory[:name] }
545 end.flatten.sort.uniq
547 template "/etc/cron.d/cleanup-tiles" do
548 source "cleanup-tiles.cron.erb"
552 variables :directories => tile_directories
555 munin_plugin "mod_tile_fresh"
556 munin_plugin "mod_tile_latency"
557 munin_plugin "mod_tile_response"
558 munin_plugin "mod_tile_zoom"
560 munin_plugin "renderd_processed"
561 munin_plugin "renderd_queue"
562 munin_plugin "renderd_queue_time"
563 munin_plugin "renderd_zoom"
564 munin_plugin "renderd_zoom_time"
566 munin_plugin "replication_delay" do