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 "accounts"
21 include_recipe "apache"
23 include_recipe "munin"
24 include_recipe "nodejs"
25 include_recipe "postgresql"
26 include_recipe "python"
27 include_recipe "tools"
29 blocks = data_bag_item("tile", "blocks")
30 web_passwords = data_bag_item("web", "passwords")
34 apache_module "expires"
35 apache_module "headers"
36 apache_module "remoteip"
37 apache_module "rewrite"
39 apache_module "tile" do
43 ssl_certificate node[:fqdn] do
44 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
45 notifies :reload, "service[apache2]"
48 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
50 apache_site "default" do
54 apache_site "tile.openstreetmap.org" do
56 variables :caches => tilecaches
59 template "/etc/logrotate.d/apache2" do
60 source "logrotate.apache.erb"
66 directory "/srv/tile.openstreetmap.org" do
74 systemd_service "renderd" do
75 description "Mapnik rendering daemon"
76 after "postgresql.service"
77 wants "postgresql.service"
79 exec_start "/usr/bin/renderd -f"
80 runtime_directory "renderd"
87 no_new_privileges true
92 action [:enable, :start]
93 subscribes :restart, "systemd_service[renderd]"
96 directory "/srv/tile.openstreetmap.org/tiles" do
102 template "/etc/renderd.conf" do
103 source "renderd.conf.erb"
107 notifies :reload, "service[apache2]"
108 notifies :restart, "service[renderd]"
111 remote_directory "/srv/tile.openstreetmap.org/html" do
121 template "/srv/tile.openstreetmap.org/html/index.html" do
122 source "index.html.erb"
134 python_package "pyotp" do
146 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
147 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
148 action :create_if_missing
149 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
156 directory "/srv/tile.openstreetmap.org/cgi-bin" do
162 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
167 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
170 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
177 template "/etc/cron.hourly/export" do
178 source "export.cron.erb"
184 directory "/srv/tile.openstreetmap.org/data" do
190 package "mapnik-utils"
192 node[:tile][:data].each_value do |data|
194 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
197 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
199 directory directory do
205 directory = "/srv/tile.openstreetmap.org/data"
213 command "tar -zxf #{file} -C #{directory}"
217 elsif file =~ /\.tar\.bz2$/
222 command "tar -jxf #{file} -C #{directory}"
226 elsif file =~ /\.zip$/
231 command "unzip -qq -o #{file} -d #{directory}"
237 execute "#{file}_shapeindex" do
239 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
242 subscribes :run, "execute[#{file}]", :immediately
248 use_conditional_get true
251 action :create_if_missing
259 notifies :run, "execute[#{file}]", :immediately
260 notifies :restart, "service[renderd]"
264 nodejs_package "carto"
266 systemd_service "update-lowzoom@" do
267 description "Low zoom tile update service for %i layer"
269 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
273 protect_system "full"
275 no_new_privileges true
279 directory "/srv/tile.openstreetmap.org/styles" do
285 node[:tile][:styles].each do |name, details|
286 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
287 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
289 template "/usr/local/bin/update-lowzoom-#{name}" do
290 source "update-lowzoom.erb"
294 variables :style => name
297 service "update-lowzoom@#{name}" do
299 supports :restart => true
302 directory tile_directory do
308 details[:tile_directories].each do |directory|
309 directory directory[:name] do
315 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
316 directory "#{directory[:name]}/#{zoom}" do
322 link "#{tile_directory}/#{zoom}" do
323 to "#{directory[:name]}/#{zoom}"
330 file "#{tile_directory}/planet-import-complete" do
331 action :create_if_missing
337 git style_directory do
339 repository details[:repository]
340 revision details[:revision]
345 link "#{style_directory}/data" do
346 to "/srv/tile.openstreetmap.org/data"
351 execute "#{style_directory}/project.mml" do
353 command "carto -a 3.0.0 project.mml > project.xml"
357 subscribes :run, "git[#{style_directory}]"
358 notifies :restart, "service[renderd]", :immediately
359 notifies :restart, "service[update-lowzoom@#{name}]"
363 postgresql_version = node[:tile][:database][:cluster].split("/").first
364 postgis_version = node[:tile][:database][:postgis]
366 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
368 postgresql_user "jburgess" do
369 cluster node[:tile][:database][:cluster]
373 postgresql_user "tomh" do
374 cluster node[:tile][:database][:cluster]
378 postgresql_user "tile" do
379 cluster node[:tile][:database][:cluster]
382 postgresql_user "www-data" do
383 cluster node[:tile][:database][:cluster]
386 postgresql_database "gis" do
387 cluster node[:tile][:database][:cluster]
391 postgresql_extension "postgis" do
392 cluster node[:tile][:database][:cluster]
396 postgresql_extension "hstore" do
397 cluster node[:tile][:database][:cluster]
399 only_if { node[:tile][:database][:hstore] }
402 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
403 postgresql_table table do
404 cluster node[:tile][:database][:cluster]
407 permissions "tile" => :all
411 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
412 postgresql_table table do
413 cluster node[:tile][:database][:cluster]
416 permissions "tile" => :all, "www-data" => :select
420 postgresql_munin "gis" do
421 cluster node[:tile][:database][:cluster]
425 directory File.dirname(node[:tile][:database][:node_file]) do
432 file node[:tile][:database][:node_file] do
438 directory "/var/log/tile" do
452 remote_directory "/usr/local/bin" do
462 template "/usr/local/bin/expire-tiles" do
463 source "expire-tiles.erb"
469 directory "/var/lib/replicate" do
475 directory "/var/lib/replicate/expire-queue" do
481 template "/usr/local/bin/replicate" do
482 source "replicate.erb"
486 variables :postgresql_version => postgresql_version.to_f
489 systemd_service "expire-tiles" do
490 description "Tile dirtying service"
493 exec_start "/usr/local/bin/expire-tiles"
494 standard_output "null"
497 protect_system "full"
499 no_new_privileges true
502 systemd_path "expire-tiles" do
503 description "Tile dirtying trigger"
504 directory_not_empty "/var/lib/replicate/expire-queue"
507 service "expire-tiles.path" do
508 action [:enable, :start]
509 subscribes :restart, "systemd_path[expire-tiles]"
512 systemd_service "replicate" do
513 description "Rendering database replication service"
514 after "postgresql.service"
515 wants "postgresql.service"
517 exec_start "/usr/local/bin/replicate"
520 protect_system "full"
522 no_new_privileges true
526 service "replicate" do
527 action [:enable, :start]
528 subscribes :restart, "template[/usr/local/bin/replicate]"
529 subscribes :restart, "systemd_service[replicate]"
532 template "/etc/logrotate.d/replicate" do
533 source "replicate.logrotate.erb"
539 template "/usr/local/bin/render-lowzoom" do
540 source "render-lowzoom.erb"
546 systemd_service "render-lowzoom" do
547 description "Render low zoom tiles"
549 exec_start "/usr/local/bin/render-lowzoom"
553 protect_system "full"
555 no_new_privileges true
558 systemd_timer "render-lowzoom" do
559 description "Render low zoom tiles"
560 on_calendar "Sun *-*~07/1 01:00:00"
563 service "render-lowzoom.timer" do
564 action [:enable, :start]
567 file "/etc/cron.d/render-lowzoom" do
571 package "liblockfile-simple-perl"
572 package "libfilesys-df-perl"
574 template "/usr/local/bin/cleanup-tiles" do
575 source "cleanup-tiles.erb"
581 tile_directories = node[:tile][:styles].collect do |_, style|
582 style[:tile_directories].collect { |directory| directory[:name] }
583 end.flatten.sort.uniq
585 template "/etc/cron.d/cleanup-tiles" do
586 source "cleanup-tiles.cron.erb"
590 variables :directories => tile_directories
593 munin_plugin "mod_tile_fresh"
594 munin_plugin "mod_tile_latency"
595 munin_plugin "mod_tile_response"
596 munin_plugin "mod_tile_zoom"
598 munin_plugin "renderd_processed"
599 munin_plugin "renderd_queue"
600 munin_plugin "renderd_queue_time"
601 munin_plugin "renderd_zoom"
602 munin_plugin "renderd_zoom_time"
604 munin_plugin "replication_delay"