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"
55 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
56 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
58 apache_site "default" do
62 apache_site "tile.openstreetmap.org" do
64 variables :caches => tilecaches, :fastly => fastlyips["addresses"]
67 template "/etc/logrotate.d/apache2" do
68 source "logrotate.apache.erb"
74 directory "/srv/tile.openstreetmap.org" do
82 systemd_service "renderd" do
83 description "Mapnik rendering daemon"
84 after "postgresql.service"
85 wants "postgresql.service"
87 exec_start "/usr/bin/renderd -f"
88 runtime_directory "renderd"
96 no_new_privileges true
101 action [:enable, :start]
102 subscribes :restart, "systemd_service[renderd]"
105 directory "/srv/tile.openstreetmap.org/tiles" do
111 template "/etc/renderd.conf" do
112 source "renderd.conf.erb"
116 notifies :reload, "service[apache2]"
117 notifies :restart, "service[renderd]"
120 remote_directory "/srv/tile.openstreetmap.org/html" do
130 template "/srv/tile.openstreetmap.org/html/index.html" do
131 source "index.html.erb"
143 python_package "pyotp" do
155 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
156 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
157 action :create_if_missing
158 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
165 directory "/srv/tile.openstreetmap.org/cgi-bin" do
171 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
176 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
179 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
186 template "/etc/cron.hourly/export" do
187 source "export.cron.erb"
193 directory "/srv/tile.openstreetmap.org/data" do
199 package "mapnik-utils"
201 node[:tile][:data].each_value do |data|
203 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
206 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
208 directory directory do
214 directory = "/srv/tile.openstreetmap.org/data"
222 command "tar -zxf #{file} -C #{directory}"
226 elsif file =~ /\.tar\.bz2$/
231 command "tar -jxf #{file} -C #{directory}"
235 elsif file =~ /\.zip$/
240 command "unzip -qq -o #{file} -d #{directory}"
246 execute "#{file}_shapeindex" do
248 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
251 subscribes :run, "execute[#{file}]", :immediately
257 use_conditional_get true
260 action :create_if_missing
268 notifies :run, "execute[#{file}]", :immediately
269 notifies :restart, "service[renderd]"
273 nodejs_package "carto"
275 systemd_service "update-lowzoom@" do
276 description "Low zoom tile update service for %i layer"
278 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
282 protect_system "full"
284 no_new_privileges true
288 directory "/srv/tile.openstreetmap.org/styles" do
294 node[:tile][:styles].each do |name, details|
295 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
296 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
298 template "/usr/local/bin/update-lowzoom-#{name}" do
299 source "update-lowzoom.erb"
303 variables :style => name
306 service "update-lowzoom@#{name}" do
308 supports :restart => true
311 directory tile_directory do
317 details[:tile_directories].each do |directory|
318 directory directory[:name] do
324 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
325 directory "#{directory[:name]}/#{zoom}" do
331 link "#{tile_directory}/#{zoom}" do
332 to "#{directory[:name]}/#{zoom}"
339 file "#{tile_directory}/planet-import-complete" do
340 action :create_if_missing
346 git style_directory do
348 repository details[:repository]
349 revision details[:revision]
354 link "#{style_directory}/data" do
355 to "/srv/tile.openstreetmap.org/data"
360 execute "#{style_directory}/project.mml" do
362 command "carto -a 3.0.0 project.mml > project.xml"
366 subscribes :run, "git[#{style_directory}]"
367 notifies :restart, "service[renderd]", :immediately
368 notifies :restart, "service[update-lowzoom@#{name}]"
372 postgresql_version = node[:tile][:database][:cluster].split("/").first
373 postgis_version = node[:tile][:database][:postgis]
375 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
377 postgresql_user "jburgess" do
378 cluster node[:tile][:database][:cluster]
382 postgresql_user "tomh" do
383 cluster node[:tile][:database][:cluster]
387 postgresql_user "tile" do
388 cluster node[:tile][:database][:cluster]
391 postgresql_user "www-data" do
392 cluster node[:tile][:database][:cluster]
395 postgresql_database "gis" do
396 cluster node[:tile][:database][:cluster]
400 postgresql_extension "postgis" do
401 cluster node[:tile][:database][:cluster]
405 postgresql_extension "hstore" do
406 cluster node[:tile][:database][:cluster]
408 only_if { node[:tile][:database][:hstore] }
411 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
412 postgresql_table table do
413 cluster node[:tile][:database][:cluster]
416 permissions "tile" => :all
420 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
421 postgresql_table table do
422 cluster node[:tile][:database][:cluster]
425 permissions "tile" => :all, "www-data" => :select
435 if node[:tile][:database][:external_data_script]
436 execute node[:tile][:database][:external_data_script] do
437 command node[:tile][:database][:external_data_script]
438 cwd "/srv/tile.openstreetmap.org"
443 Array(node[:tile][:database][:external_data_tables]).each do |table|
444 postgresql_table table do
445 cluster node[:tile][:database][:cluster]
448 permissions "tile" => :all, "www-data" => :select
453 postgresql_munin "gis" do
454 cluster node[:tile][:database][:cluster]
458 directory File.dirname(node[:tile][:database][:node_file]) do
465 file node[:tile][:database][:node_file] do
471 directory "/var/log/tile" do
485 remote_directory "/usr/local/bin" do
495 template "/usr/local/bin/expire-tiles" do
496 source "expire-tiles.erb"
502 directory "/var/lib/replicate" do
508 directory "/var/lib/replicate/expire-queue" do
514 template "/usr/local/bin/replicate" do
515 source "replicate.erb"
519 variables :postgresql_version => postgresql_version.to_f
522 systemd_service "expire-tiles" do
523 description "Tile dirtying service"
526 exec_start "/usr/local/bin/expire-tiles"
527 standard_output "null"
530 protect_system "full"
532 no_new_privileges true
535 systemd_path "expire-tiles" do
536 description "Tile dirtying trigger"
537 directory_not_empty "/var/lib/replicate/expire-queue"
540 service "expire-tiles.path" do
541 action [:enable, :start]
542 subscribes :restart, "systemd_path[expire-tiles]"
545 systemd_service "replicate" do
546 description "Rendering database replication service"
547 after "postgresql.service"
548 wants "postgresql.service"
550 exec_start "/usr/local/bin/replicate"
553 protect_system "full"
555 no_new_privileges true
559 service "replicate" do
560 action [:enable, :start]
561 subscribes :restart, "template[/usr/local/bin/replicate]"
562 subscribes :restart, "systemd_service[replicate]"
565 template "/etc/logrotate.d/replicate" do
566 source "replicate.logrotate.erb"
572 template "/usr/local/bin/render-lowzoom" do
573 source "render-lowzoom.erb"
579 systemd_service "render-lowzoom" do
580 description "Render low zoom tiles"
582 exec_start "/usr/local/bin/render-lowzoom"
586 protect_system "full"
588 no_new_privileges true
591 systemd_timer "render-lowzoom" do
592 description "Render low zoom tiles"
593 on_calendar "Sun *-*~07/1 01:00:00"
596 service "render-lowzoom.timer" do
597 action [:enable, :start]
600 package "liblockfile-simple-perl"
601 package "libfilesys-df-perl"
603 template "/usr/local/bin/cleanup-tiles" do
604 source "cleanup-tiles.erb"
610 tile_directories = node[:tile][:styles].collect do |_, style|
611 style[:tile_directories].collect { |directory| directory[:name] }
612 end.flatten.sort.uniq
614 tile_directories.each do |directory|
615 label = directory.gsub("/", "-")
617 cron_d "cleanup-tiles#{label}" do
620 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
621 mailto "admins@openstreetmap.org"
625 munin_plugin "mod_tile_fresh"
626 munin_plugin "mod_tile_latency"
627 munin_plugin "mod_tile_response"
628 munin_plugin "mod_tile_zoom"
630 munin_plugin "renderd_processed"
631 munin_plugin "renderd_queue"
632 munin_plugin "renderd_queue_time"
633 munin_plugin "renderd_zoom"
634 munin_plugin "renderd_zoom_time"
636 munin_plugin "replication_delay"
638 prometheus_exporter "modtile" do
642 prometheus_exporter "renderd" do