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 # https://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 "munin"
23 include_recipe "nodejs"
24 include_recipe "postgresql"
25 include_recipe "python"
26 include_recipe "tools"
28 blocks = data_bag_item("tile", "blocks")
29 web_passwords = data_bag_item("web", "passwords")
33 apache_module "expires"
34 apache_module "headers"
35 apache_module "remoteip"
36 apache_module "rewrite"
38 apache_module "tile" do
42 ssl_certificate node[:fqdn] do
43 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
44 notifies :reload, "service[apache2]"
47 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
49 apache_site "default" do
53 apache_site "tile.openstreetmap.org" do
55 variables :caches => tilecaches
58 template "/etc/logrotate.d/apache2" do
59 source "logrotate.apache.erb"
65 directory "/srv/tile.openstreetmap.org" do
73 systemd_service "renderd" do
74 description "Mapnik rendering daemon"
75 after "postgresql.service"
76 wants "postgresql.service"
78 exec_start "/usr/bin/renderd -f"
79 runtime_directory "renderd"
86 no_new_privileges true
91 action [:enable, :start]
92 subscribes :restart, "systemd_service[renderd]"
95 directory "/srv/tile.openstreetmap.org/tiles" do
101 template "/etc/renderd.conf" do
102 source "renderd.conf.erb"
106 notifies :reload, "service[apache2]"
107 notifies :restart, "service[renderd]"
110 remote_directory "/srv/tile.openstreetmap.org/html" do
120 template "/srv/tile.openstreetmap.org/html/index.html" do
121 source "index.html.erb"
133 python_package "pyotp"
143 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
144 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
145 action :create_if_missing
146 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
153 directory "/srv/tile.openstreetmap.org/cgi-bin" do
159 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
164 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
167 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
174 template "/etc/cron.hourly/export" do
175 source "export.cron.erb"
181 directory "/srv/tile.openstreetmap.org/data" do
187 package "mapnik-utils"
189 node[:tile][:data].each_value do |data|
191 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
194 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
196 directory directory do
202 directory = "/srv/tile.openstreetmap.org/data"
210 command "tar -zxf #{file} -C #{directory}"
214 elsif file =~ /\.tar\.bz2$/
219 command "tar -jxf #{file} -C #{directory}"
223 elsif file =~ /\.zip$/
228 command "unzip -qq -o #{file} -d #{directory}"
234 execute "#{file}_shapeindex" do
236 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
239 subscribes :run, "execute[#{file}]", :immediately
245 use_conditional_get true
248 action :create_if_missing
256 notifies :run, "execute[#{file}]", :immediately
257 notifies :restart, "service[renderd]"
261 nodejs_package "carto"
262 nodejs_package "millstone"
264 systemd_service "update-lowzoom@" do
265 description "Low zoom tile update service for %i layer"
267 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
271 protect_system "full"
273 no_new_privileges true
277 directory "/srv/tile.openstreetmap.org/styles" do
283 node[:tile][:styles].each do |name, details|
284 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
285 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
287 template "/usr/local/bin/update-lowzoom-#{name}" do
288 source "update-lowzoom.erb"
292 variables :style => name
295 service "update-lowzoom@#{name}" do
297 supports :restart => true
300 directory tile_directory do
306 details[:tile_directories].each do |directory|
307 directory directory[:name] do
313 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
314 directory "#{directory[:name]}/#{zoom}" do
320 link "#{tile_directory}/#{zoom}" do
321 to "#{directory[:name]}/#{zoom}"
328 file "#{tile_directory}/planet-import-complete" do
329 action :create_if_missing
335 git style_directory do
337 repository details[:repository]
338 revision details[:revision]
343 link "#{style_directory}/data" do
344 to "/srv/tile.openstreetmap.org/data"
349 execute "#{style_directory}/project.mml" do
351 command "carto -a 3.0.0 project.mml > project.xml"
355 subscribes :run, "git[#{style_directory}]"
356 notifies :restart, "service[renderd]", :immediately
357 notifies :restart, "service[update-lowzoom@#{name}]"
361 postgresql_version = node[:tile][:database][:cluster].split("/").first
362 postgis_version = node[:tile][:database][:postgis]
364 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
366 postgresql_user "jburgess" do
367 cluster node[:tile][:database][:cluster]
371 postgresql_user "tomh" do
372 cluster node[:tile][:database][:cluster]
376 postgresql_user "tile" do
377 cluster node[:tile][:database][:cluster]
380 postgresql_user "www-data" do
381 cluster node[:tile][:database][:cluster]
384 postgresql_database "gis" do
385 cluster node[:tile][:database][:cluster]
389 postgresql_extension "postgis" do
390 cluster node[:tile][:database][:cluster]
394 postgresql_extension "hstore" do
395 cluster node[:tile][:database][:cluster]
399 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
400 postgresql_table table do
401 cluster node[:tile][:database][:cluster]
404 permissions "tile" => :all
408 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
409 postgresql_table table do
410 cluster node[:tile][:database][:cluster]
413 permissions "tile" => :all, "www-data" => :select
417 postgresql_munin "gis" do
418 cluster node[:tile][:database][:cluster]
422 file node[:tile][:node_file] do
428 directory "/var/log/tile" do
442 remote_directory "/usr/local/bin" do
452 template "/usr/local/bin/expire-tiles" do
453 source "expire-tiles.erb"
459 directory "/var/lib/replicate" do
465 directory "/var/lib/replicate/expire-queue" do
471 template "/usr/local/bin/replicate" do
472 source "replicate.erb"
478 systemd_service "expire-tiles" do
479 description "Tile dirtying service"
482 exec_start "/usr/local/bin/expire-tiles"
483 standard_output "null"
486 protect_system "full"
488 no_new_privileges true
491 systemd_path "expire-tiles" do
492 description "Tile dirtying trigger"
493 directory_not_empty "/var/lib/replicate/expire-queue"
496 service "expire-tiles.path" do
497 action [:enable, :start]
498 subscribes :restart, "systemd_path[expire-tiles]"
501 systemd_service "replicate" do
502 description "Rendering database replication service"
503 after "postgresql.service"
504 wants "postgresql.service"
506 exec_start "/usr/local/bin/replicate"
509 protect_system "full"
511 no_new_privileges true
515 service "replicate" do
516 action [:enable, :start]
517 subscribes :restart, "template[/usr/local/bin/replicate]"
518 subscribes :restart, "systemd_service[replicate]"
521 template "/etc/logrotate.d/replicate" do
522 source "replicate.logrotate.erb"
528 template "/usr/local/bin/render-lowzoom" do
529 source "render-lowzoom.erb"
535 systemd_service "render-lowzoom" do
536 description "Render low zoom tiles"
538 exec_start "/usr/local/bin/render-lowzoom"
542 protect_system "full"
544 no_new_privileges true
547 systemd_timer "render-lowzoom" do
548 description "Render low zoom tiles"
549 on_calendar "Sun *-*~07/1 01:00:00"
552 service "render-lowzoom.timer" do
553 action [:enable, :start]
556 file "/etc/cron.d/render-lowzoom" do
560 package "liblockfile-simple-perl"
561 package "libfilesys-df-perl"
563 template "/usr/local/bin/cleanup-tiles" do
564 source "cleanup-tiles.erb"
570 tile_directories = node[:tile][:styles].collect do |_, style|
571 style[:tile_directories].collect { |directory| directory[:name] }
572 end.flatten.sort.uniq
574 template "/etc/cron.d/cleanup-tiles" do
575 source "cleanup-tiles.cron.erb"
579 variables :directories => tile_directories
582 munin_plugin "mod_tile_fresh"
583 munin_plugin "mod_tile_latency"
584 munin_plugin "mod_tile_response"
585 munin_plugin "mod_tile_zoom"
587 munin_plugin "renderd_processed"
588 munin_plugin "renderd_queue"
589 munin_plugin "renderd_queue_time"
590 munin_plugin "renderd_zoom"
591 munin_plugin "renderd_zoom_time"
593 munin_plugin "replication_delay"