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 apache_conf "renderd" do
48 ssl_certificate node[:fqdn] do
49 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
50 notifies :reload, "service[apache2]"
53 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
54 source "https://api.fastly.com/public-ip-list"
59 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
61 apache_site "default" do
65 apache_site "tileserver_site" do
69 apache_site "tile.openstreetmap.org" do
71 variables :fastly => fastlyips["addresses"]
74 template "/etc/logrotate.d/apache2" do
75 source "logrotate.apache.erb"
81 directory "/srv/tile.openstreetmap.org" do
87 directory "/srv/tile.openstreetmap.org/conf" do
93 file "/srv/tile.openstreetmap.org/conf/ip.map" do
101 systemd_service "renderd" do
103 after "postgresql.service"
104 wants "postgresql.service"
109 protect_system "full"
111 no_new_privileges true
115 systemd_service "renderd" do
120 action [:enable, :start]
121 subscribes :restart, "systemd_service[renderd]"
124 directory "/srv/tile.openstreetmap.org/tiles" do
130 template "/etc/renderd.conf" do
131 source "renderd.conf.erb"
135 notifies :reload, "service[apache2]"
136 notifies :restart, "service[renderd]"
139 remote_directory "/srv/tile.openstreetmap.org/html" do
149 template "/srv/tile.openstreetmap.org/html/index.html" do
150 source "index.html.erb"
162 python_package "pyotp" do
174 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
175 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
176 action :create_if_missing
177 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
184 directory "/srv/tile.openstreetmap.org/cgi-bin" do
190 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
195 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
198 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
205 template "/etc/cron.hourly/export" do
206 source "export.cron.erb"
212 directory "/srv/tile.openstreetmap.org/data" do
218 package "mapnik-utils"
220 node[:tile][:data].each_value do |data|
222 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
225 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
227 directory directory do
233 directory = "/srv/tile.openstreetmap.org/data"
241 command "tar -zxf #{file} -C #{directory}"
245 elsif file =~ /\.tar\.bz2$/
250 command "tar -jxf #{file} -C #{directory}"
254 elsif file =~ /\.zip$/
259 command "unzip -qq -o #{file} -d #{directory}"
265 execute "#{file}_shapeindex" do
267 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
270 subscribes :run, "execute[#{file}]", :immediately
276 use_conditional_get true
279 action :create_if_missing
287 notifies :run, "execute[#{file}]", :immediately
288 notifies :restart, "service[renderd]"
292 nodejs_package "carto"
294 systemd_service "update-lowzoom@" do
295 description "Low zoom tile update service for %i layer"
296 conflicts "render-lowzoom.service"
298 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
299 runtime_directory "update-lowzoom-%i"
303 protect_system "full"
305 no_new_privileges true
309 directory "/srv/tile.openstreetmap.org/styles" do
315 node[:tile][:styles].each do |name, details|
316 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
317 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
319 template "/usr/local/bin/update-lowzoom-#{name}" do
320 source "update-lowzoom.erb"
324 variables :style => name
327 service "update-lowzoom@#{name}" do
329 supports :restart => true
332 directory tile_directory do
338 details[:tile_directories].each do |directory|
339 directory directory[:name] do
345 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
346 directory "#{directory[:name]}/#{zoom}" do
352 link "#{tile_directory}/#{zoom}" do
353 to "#{directory[:name]}/#{zoom}"
360 file "#{tile_directory}/planet-import-complete" do
361 action :create_if_missing
367 git style_directory do
369 repository details[:repository]
370 revision details[:revision]
375 link "#{style_directory}/data" do
376 to "/srv/tile.openstreetmap.org/data"
381 execute "#{style_directory}/project.mml" do
383 command "carto -a 3.0.0 project.mml > project.xml"
387 subscribes :run, "git[#{style_directory}]"
388 notifies :restart, "service[renderd]", :immediately
389 notifies :restart, "service[update-lowzoom@#{name}]"
393 postgresql_version = node[:tile][:database][:cluster].split("/").first
394 postgis_version = node[:tile][:database][:postgis]
396 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
398 postgresql_user "jburgess" do
399 cluster node[:tile][:database][:cluster]
403 postgresql_user "tomh" do
404 cluster node[:tile][:database][:cluster]
408 postgresql_user "tile" do
409 cluster node[:tile][:database][:cluster]
412 postgresql_user "www-data" do
413 cluster node[:tile][:database][:cluster]
416 postgresql_user "_renderd" do
417 cluster node[:tile][:database][:cluster]
420 postgresql_database "gis" do
421 cluster node[:tile][:database][:cluster]
425 postgresql_extension "postgis" do
426 cluster node[:tile][:database][:cluster]
430 postgresql_extension "hstore" do
431 cluster node[:tile][:database][:cluster]
433 only_if { node[:tile][:database][:hstore] }
436 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
437 postgresql_table table do
438 cluster node[:tile][:database][:cluster]
441 permissions "tile" => :all
445 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
446 postgresql_table table do
447 cluster node[:tile][:database][:cluster]
450 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
460 if node[:tile][:database][:external_data_script]
461 execute node[:tile][:database][:external_data_script] do
462 command "#{node[:tile][:database][:external_data_script]} -R _renderd"
463 cwd "/srv/tile.openstreetmap.org"
469 Array(node[:tile][:database][:external_data_tables]).each do |table|
470 postgresql_table table do
471 cluster node[:tile][:database][:cluster]
474 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
479 postgresql_munin "gis" do
480 cluster node[:tile][:database][:cluster]
484 directory File.dirname(node[:tile][:database][:node_file]) do
491 file node[:tile][:database][:node_file] do
497 directory "/var/log/tile" do
511 gem_package "apachelogregex"
512 gem_package "file-tail"
513 gem_package "lru_redux"
515 remote_directory "/usr/local/bin" do
525 template "/usr/local/bin/tile-ratelimit" do
526 source "tile-ratelimit.erb"
532 systemd_service "tile-ratelimit" do
533 description "Monitor tile requests and enforce rate limits"
534 after "apache2.service"
537 exec_start "/usr/local/bin/tile-ratelimit"
541 protect_system "full"
543 read_write_paths "/srv/tile.openstreetmap.org/conf"
544 no_new_privileges true
548 service "tile-ratelimit" do
549 action [:enable, :start]
550 subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
551 subscribes :restart, "systemd_service[tile-ratelimit]"
554 template "/usr/local/bin/expire-tiles" do
555 source "expire-tiles.erb"
561 directory "/var/lib/replicate" do
567 directory "/var/lib/replicate/expire-queue" do
573 template "/usr/local/bin/replicate" do
574 source "replicate.erb"
578 variables :postgresql_version => postgresql_version.to_f
581 systemd_service "expire-tiles" do
582 description "Tile dirtying service"
585 exec_start "/usr/local/bin/expire-tiles"
586 standard_output "null"
589 protect_system "full"
591 no_new_privileges true
594 systemd_path "expire-tiles" do
595 description "Tile dirtying trigger"
596 directory_not_empty "/var/lib/replicate/expire-queue"
599 service "expire-tiles.path" do
600 action [:enable, :start]
601 subscribes :restart, "systemd_path[expire-tiles]"
604 systemd_service "replicate" do
605 description "Rendering database replication service"
606 after "postgresql.service"
607 wants "postgresql.service"
609 exec_start "/usr/local/bin/replicate"
612 protect_system "full"
614 no_new_privileges true
618 service "replicate" do
619 action [:enable, :start]
620 subscribes :restart, "template[/usr/local/bin/replicate]"
621 subscribes :restart, "systemd_service[replicate]"
624 template "/etc/logrotate.d/replicate" do
625 source "replicate.logrotate.erb"
631 template "/usr/local/bin/render-lowzoom" do
632 source "render-lowzoom.erb"
638 systemd_service "render-lowzoom" do
639 description "Render low zoom tiles"
640 condition_path_exists_glob "!/run/update-lowzoom-*"
642 exec_start "/usr/local/bin/render-lowzoom"
646 protect_system "full"
648 no_new_privileges true
651 systemd_timer "render-lowzoom" do
652 description "Render low zoom tiles"
653 on_calendar "Sun *-*~07/1 01:00:00"
656 service "render-lowzoom.timer" do
657 action [:enable, :start]
660 package "liblockfile-simple-perl"
661 package "libfilesys-df-perl"
663 template "/usr/local/bin/cleanup-tiles" do
664 source "cleanup-tiles.erb"
670 tile_directories = node[:tile][:styles].collect do |_, style|
671 style[:tile_directories].collect { |directory| directory[:name] }
672 end.flatten.sort.uniq
674 tile_directories.each do |directory|
675 label = directory.gsub("/", "-")
677 cron_d "cleanup-tiles#{label}" do
680 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
681 mailto "admins@openstreetmap.org"
685 munin_plugin "mod_tile_fresh"
686 munin_plugin "mod_tile_latency"
687 munin_plugin "mod_tile_response"
688 munin_plugin "mod_tile_zoom"
690 munin_plugin "renderd_processed"
691 munin_plugin "renderd_queue"
692 munin_plugin "renderd_queue_time"
693 munin_plugin "renderd_zoom"
694 munin_plugin "renderd_zoom_time"
696 munin_plugin "replication_delay"
698 prometheus_exporter "modtile" do
702 prometheus_exporter "renderd" do