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 "prometheus"
27 include_recipe "python"
28 include_recipe "tools"
30 blocks = data_bag_item("tile", "blocks")
31 web_passwords = data_bag_item("web", "passwords")
35 apache_module "expires"
36 apache_module "headers"
37 apache_module "remoteip"
38 apache_module "rewrite"
40 apache_module "tile" do
44 ssl_certificate node[:fqdn] do
45 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
46 notifies :reload, "service[apache2]"
49 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
51 apache_site "default" do
55 apache_site "tile.openstreetmap.org" do
57 variables :caches => tilecaches
60 template "/etc/logrotate.d/apache2" do
61 source "logrotate.apache.erb"
67 directory "/srv/tile.openstreetmap.org" do
75 systemd_service "renderd" do
76 description "Mapnik rendering daemon"
77 after "postgresql.service"
78 wants "postgresql.service"
80 exec_start "/usr/bin/renderd -f"
81 runtime_directory "renderd"
88 no_new_privileges true
93 action [:enable, :start]
94 subscribes :restart, "systemd_service[renderd]"
97 directory "/srv/tile.openstreetmap.org/tiles" do
103 template "/etc/renderd.conf" do
104 source "renderd.conf.erb"
108 notifies :reload, "service[apache2]"
109 notifies :restart, "service[renderd]"
112 remote_directory "/srv/tile.openstreetmap.org/html" do
122 template "/srv/tile.openstreetmap.org/html/index.html" do
123 source "index.html.erb"
135 python_package "pyotp" do
147 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
148 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
149 action :create_if_missing
150 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
157 directory "/srv/tile.openstreetmap.org/cgi-bin" do
163 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
168 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
171 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
178 template "/etc/cron.hourly/export" do
179 source "export.cron.erb"
185 directory "/srv/tile.openstreetmap.org/data" do
191 package "mapnik-utils"
193 node[:tile][:data].each_value do |data|
195 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
198 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
200 directory directory do
206 directory = "/srv/tile.openstreetmap.org/data"
214 command "tar -zxf #{file} -C #{directory}"
218 elsif file =~ /\.tar\.bz2$/
223 command "tar -jxf #{file} -C #{directory}"
227 elsif file =~ /\.zip$/
232 command "unzip -qq -o #{file} -d #{directory}"
238 execute "#{file}_shapeindex" do
240 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
243 subscribes :run, "execute[#{file}]", :immediately
249 use_conditional_get true
252 action :create_if_missing
260 notifies :run, "execute[#{file}]", :immediately
261 notifies :restart, "service[renderd]"
265 nodejs_package "carto"
267 systemd_service "update-lowzoom@" do
268 description "Low zoom tile update service for %i layer"
270 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
274 protect_system "full"
276 no_new_privileges true
280 directory "/srv/tile.openstreetmap.org/styles" do
286 node[:tile][:styles].each do |name, details|
287 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
288 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
290 template "/usr/local/bin/update-lowzoom-#{name}" do
291 source "update-lowzoom.erb"
295 variables :style => name
298 service "update-lowzoom@#{name}" do
300 supports :restart => true
303 directory tile_directory do
309 details[:tile_directories].each do |directory|
310 directory directory[:name] do
316 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
317 directory "#{directory[:name]}/#{zoom}" do
323 link "#{tile_directory}/#{zoom}" do
324 to "#{directory[:name]}/#{zoom}"
331 file "#{tile_directory}/planet-import-complete" do
332 action :create_if_missing
338 git style_directory do
340 repository details[:repository]
341 revision details[:revision]
346 link "#{style_directory}/data" do
347 to "/srv/tile.openstreetmap.org/data"
352 execute "#{style_directory}/project.mml" do
354 command "carto -a 3.0.0 project.mml > project.xml"
358 subscribes :run, "git[#{style_directory}]"
359 notifies :restart, "service[renderd]", :immediately
360 notifies :restart, "service[update-lowzoom@#{name}]"
364 postgresql_version = node[:tile][:database][:cluster].split("/").first
365 postgis_version = node[:tile][:database][:postgis]
367 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
369 postgresql_user "jburgess" do
370 cluster node[:tile][:database][:cluster]
374 postgresql_user "tomh" do
375 cluster node[:tile][:database][:cluster]
379 postgresql_user "tile" do
380 cluster node[:tile][:database][:cluster]
383 postgresql_user "www-data" do
384 cluster node[:tile][:database][:cluster]
387 postgresql_database "gis" do
388 cluster node[:tile][:database][:cluster]
392 postgresql_extension "postgis" do
393 cluster node[:tile][:database][:cluster]
397 postgresql_extension "hstore" do
398 cluster node[:tile][:database][:cluster]
400 only_if { node[:tile][:database][:hstore] }
403 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
404 postgresql_table table do
405 cluster node[:tile][:database][:cluster]
408 permissions "tile" => :all
412 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
413 postgresql_table table do
414 cluster node[:tile][:database][:cluster]
417 permissions "tile" => :all, "www-data" => :select
421 postgresql_munin "gis" do
422 cluster node[:tile][:database][:cluster]
426 directory File.dirname(node[:tile][:database][:node_file]) do
433 file node[:tile][:database][:node_file] do
439 directory "/var/log/tile" do
453 remote_directory "/usr/local/bin" do
463 template "/usr/local/bin/expire-tiles" do
464 source "expire-tiles.erb"
470 directory "/var/lib/replicate" do
476 directory "/var/lib/replicate/expire-queue" do
482 template "/usr/local/bin/replicate" do
483 source "replicate.erb"
487 variables :postgresql_version => postgresql_version.to_f
490 systemd_service "expire-tiles" do
491 description "Tile dirtying service"
494 exec_start "/usr/local/bin/expire-tiles"
495 standard_output "null"
498 protect_system "full"
500 no_new_privileges true
503 systemd_path "expire-tiles" do
504 description "Tile dirtying trigger"
505 directory_not_empty "/var/lib/replicate/expire-queue"
508 service "expire-tiles.path" do
509 action [:enable, :start]
510 subscribes :restart, "systemd_path[expire-tiles]"
513 systemd_service "replicate" do
514 description "Rendering database replication service"
515 after "postgresql.service"
516 wants "postgresql.service"
518 exec_start "/usr/local/bin/replicate"
521 protect_system "full"
523 no_new_privileges true
527 service "replicate" do
528 action [:enable, :start]
529 subscribes :restart, "template[/usr/local/bin/replicate]"
530 subscribes :restart, "systemd_service[replicate]"
533 template "/etc/logrotate.d/replicate" do
534 source "replicate.logrotate.erb"
540 template "/usr/local/bin/render-lowzoom" do
541 source "render-lowzoom.erb"
547 systemd_service "render-lowzoom" do
548 description "Render low zoom tiles"
550 exec_start "/usr/local/bin/render-lowzoom"
554 protect_system "full"
556 no_new_privileges true
559 systemd_timer "render-lowzoom" do
560 description "Render low zoom tiles"
561 on_calendar "Sun *-*~07/1 01:00:00"
564 service "render-lowzoom.timer" do
565 action [:enable, :start]
568 package "liblockfile-simple-perl"
569 package "libfilesys-df-perl"
571 template "/usr/local/bin/cleanup-tiles" do
572 source "cleanup-tiles.erb"
578 tile_directories = node[:tile][:styles].collect do |_, style|
579 style[:tile_directories].collect { |directory| directory[:name] }
580 end.flatten.sort.uniq
582 tile_directories.each do |directory|
583 label = directory.gsub("/", "-")
585 cron_d "cleanup-tiles#{label}" do
588 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
589 mailto "admins@openstreetmap.org"
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"
606 prometheus_collector "modtile" do
610 prometheus_collector "renderd" do