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 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
50 source "https://api.fastly.com/public-ip-list"
54 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
55 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
57 apache_site "default" do
61 apache_site "tile.openstreetmap.org" do
63 variables :caches => tilecaches, :fastly => fastlyips["addresses"]
66 template "/etc/logrotate.d/apache2" do
67 source "logrotate.apache.erb"
73 directory "/srv/tile.openstreetmap.org" do
81 systemd_service "renderd" do
82 description "Mapnik rendering daemon"
83 after "postgresql.service"
84 wants "postgresql.service"
86 exec_start "/usr/bin/renderd -f"
87 runtime_directory "renderd"
95 no_new_privileges true
100 action [:enable, :start]
101 subscribes :restart, "systemd_service[renderd]"
104 directory "/srv/tile.openstreetmap.org/tiles" do
110 template "/etc/renderd.conf" do
111 source "renderd.conf.erb"
115 notifies :reload, "service[apache2]"
116 notifies :restart, "service[renderd]"
119 remote_directory "/srv/tile.openstreetmap.org/html" do
129 template "/srv/tile.openstreetmap.org/html/index.html" do
130 source "index.html.erb"
142 python_package "pyotp" do
154 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
155 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
156 action :create_if_missing
157 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
164 directory "/srv/tile.openstreetmap.org/cgi-bin" do
170 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
175 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
178 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
185 template "/etc/cron.hourly/export" do
186 source "export.cron.erb"
192 directory "/srv/tile.openstreetmap.org/data" do
198 package "mapnik-utils"
200 node[:tile][:data].each_value do |data|
202 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
205 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
207 directory directory do
213 directory = "/srv/tile.openstreetmap.org/data"
221 command "tar -zxf #{file} -C #{directory}"
225 elsif file =~ /\.tar\.bz2$/
230 command "tar -jxf #{file} -C #{directory}"
234 elsif file =~ /\.zip$/
239 command "unzip -qq -o #{file} -d #{directory}"
245 execute "#{file}_shapeindex" do
247 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
250 subscribes :run, "execute[#{file}]", :immediately
256 use_conditional_get true
259 action :create_if_missing
267 notifies :run, "execute[#{file}]", :immediately
268 notifies :restart, "service[renderd]"
272 nodejs_package "carto"
274 systemd_service "update-lowzoom@" do
275 description "Low zoom tile update service for %i layer"
277 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
281 protect_system "full"
283 no_new_privileges true
287 directory "/srv/tile.openstreetmap.org/styles" do
293 node[:tile][:styles].each do |name, details|
294 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
295 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
297 template "/usr/local/bin/update-lowzoom-#{name}" do
298 source "update-lowzoom.erb"
302 variables :style => name
305 service "update-lowzoom@#{name}" do
307 supports :restart => true
310 directory tile_directory do
316 details[:tile_directories].each do |directory|
317 directory directory[:name] do
323 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
324 directory "#{directory[:name]}/#{zoom}" do
330 link "#{tile_directory}/#{zoom}" do
331 to "#{directory[:name]}/#{zoom}"
338 file "#{tile_directory}/planet-import-complete" do
339 action :create_if_missing
345 git style_directory do
347 repository details[:repository]
348 revision details[:revision]
353 link "#{style_directory}/data" do
354 to "/srv/tile.openstreetmap.org/data"
359 execute "#{style_directory}/project.mml" do
361 command "carto -a 3.0.0 project.mml > project.xml"
365 subscribes :run, "git[#{style_directory}]"
366 notifies :restart, "service[renderd]", :immediately
367 notifies :restart, "service[update-lowzoom@#{name}]"
371 postgresql_version = node[:tile][:database][:cluster].split("/").first
372 postgis_version = node[:tile][:database][:postgis]
374 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
376 postgresql_user "jburgess" do
377 cluster node[:tile][:database][:cluster]
381 postgresql_user "tomh" do
382 cluster node[:tile][:database][:cluster]
386 postgresql_user "tile" do
387 cluster node[:tile][:database][:cluster]
390 postgresql_user "www-data" do
391 cluster node[:tile][:database][:cluster]
394 postgresql_database "gis" do
395 cluster node[:tile][:database][:cluster]
399 postgresql_extension "postgis" do
400 cluster node[:tile][:database][:cluster]
404 postgresql_extension "hstore" do
405 cluster node[:tile][:database][:cluster]
407 only_if { node[:tile][:database][:hstore] }
410 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
411 postgresql_table table do
412 cluster node[:tile][:database][:cluster]
415 permissions "tile" => :all
419 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
420 postgresql_table table do
421 cluster node[:tile][:database][:cluster]
424 permissions "tile" => :all, "www-data" => :select
428 postgresql_munin "gis" do
429 cluster node[:tile][:database][:cluster]
433 directory File.dirname(node[:tile][:database][:node_file]) do
440 file node[:tile][:database][:node_file] do
446 directory "/var/log/tile" do
460 remote_directory "/usr/local/bin" do
470 template "/usr/local/bin/expire-tiles" do
471 source "expire-tiles.erb"
477 directory "/var/lib/replicate" do
483 directory "/var/lib/replicate/expire-queue" do
489 template "/usr/local/bin/replicate" do
490 source "replicate.erb"
494 variables :postgresql_version => postgresql_version.to_f
497 systemd_service "expire-tiles" do
498 description "Tile dirtying service"
501 exec_start "/usr/local/bin/expire-tiles"
502 standard_output "null"
505 protect_system "full"
507 no_new_privileges true
510 systemd_path "expire-tiles" do
511 description "Tile dirtying trigger"
512 directory_not_empty "/var/lib/replicate/expire-queue"
515 service "expire-tiles.path" do
516 action [:enable, :start]
517 subscribes :restart, "systemd_path[expire-tiles]"
520 systemd_service "replicate" do
521 description "Rendering database replication service"
522 after "postgresql.service"
523 wants "postgresql.service"
525 exec_start "/usr/local/bin/replicate"
528 protect_system "full"
530 no_new_privileges true
534 service "replicate" do
535 action [:enable, :start]
536 subscribes :restart, "template[/usr/local/bin/replicate]"
537 subscribes :restart, "systemd_service[replicate]"
540 template "/etc/logrotate.d/replicate" do
541 source "replicate.logrotate.erb"
547 template "/usr/local/bin/render-lowzoom" do
548 source "render-lowzoom.erb"
554 systemd_service "render-lowzoom" do
555 description "Render low zoom tiles"
557 exec_start "/usr/local/bin/render-lowzoom"
561 protect_system "full"
563 no_new_privileges true
566 systemd_timer "render-lowzoom" do
567 description "Render low zoom tiles"
568 on_calendar "Sun *-*~07/1 01:00:00"
571 service "render-lowzoom.timer" do
572 action [:enable, :start]
575 package "liblockfile-simple-perl"
576 package "libfilesys-df-perl"
578 template "/usr/local/bin/cleanup-tiles" do
579 source "cleanup-tiles.erb"
585 tile_directories = node[:tile][:styles].collect do |_, style|
586 style[:tile_directories].collect { |directory| directory[:name] }
587 end.flatten.sort.uniq
589 tile_directories.each do |directory|
590 label = directory.gsub("/", "-")
592 cron_d "cleanup-tiles#{label}" do
595 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
596 mailto "admins@openstreetmap.org"
600 munin_plugin "mod_tile_fresh"
601 munin_plugin "mod_tile_latency"
602 munin_plugin "mod_tile_response"
603 munin_plugin "mod_tile_zoom"
605 munin_plugin "renderd_processed"
606 munin_plugin "renderd_queue"
607 munin_plugin "renderd_queue_time"
608 munin_plugin "renderd_zoom"
609 munin_plugin "renderd_zoom_time"
611 munin_plugin "replication_delay"
613 prometheus_exporter "modtile" do
617 prometheus_exporter "renderd" do