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"
265 nodejs_package "millstone"
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 file "/etc/cron.d/render-lowzoom" do
572 package "liblockfile-simple-perl"
573 package "libfilesys-df-perl"
575 template "/usr/local/bin/cleanup-tiles" do
576 source "cleanup-tiles.erb"
582 tile_directories = node[:tile][:styles].collect do |_, style|
583 style[:tile_directories].collect { |directory| directory[:name] }
584 end.flatten.sort.uniq
586 template "/etc/cron.d/cleanup-tiles" do
587 source "cleanup-tiles.cron.erb"
591 variables :directories => tile_directories
594 munin_plugin "mod_tile_fresh"
595 munin_plugin "mod_tile_latency"
596 munin_plugin "mod_tile_response"
597 munin_plugin "mod_tile_zoom"
599 munin_plugin "renderd_processed"
600 munin_plugin "renderd_queue"
601 munin_plugin "renderd_queue_time"
602 munin_plugin "renderd_zoom"
603 munin_plugin "renderd_zoom_time"
605 munin_plugin "replication_delay"