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"
29 include_recipe "tools"
31 blocks = data_bag_item("tile", "blocks")
32 web_passwords = data_bag_item("web", "passwords")
36 apache_module "expires"
37 apache_module "headers"
38 apache_module "remoteip"
39 apache_module "rewrite"
41 apache_module "tile" do
45 apache_conf "renderd" do
49 ssl_certificate node[:fqdn] do
50 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
51 notifies :reload, "service[apache2]"
54 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
55 source "https://api.fastly.com/public-ip-list"
60 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
62 apache_site "default" do
66 apache_site "tileserver_site" do
70 apache_site "tile.openstreetmap.org" do
72 variables :fastly => fastlyips["addresses"]
75 template "/etc/logrotate.d/apache2" do
76 source "logrotate.apache.erb"
82 directory "/srv/tile.openstreetmap.org" do
88 directory "/srv/tile.openstreetmap.org/conf" do
94 file "/srv/tile.openstreetmap.org/conf/ip.map" do
102 systemd_service "renderd" do
104 after "postgresql.service"
105 wants "postgresql.service"
110 protect_system "full"
112 no_new_privileges true
116 systemd_service "renderd" do
121 action [:enable, :start]
122 subscribes :restart, "systemd_service[renderd]"
125 directory "/srv/tile.openstreetmap.org/tiles" do
131 template "/etc/renderd.conf" do
132 source "renderd.conf.erb"
136 notifies :reload, "service[apache2]"
137 notifies :restart, "service[renderd]"
140 remote_directory "/srv/tile.openstreetmap.org/html" do
150 template "/srv/tile.openstreetmap.org/html/index.html" do
151 source "index.html.erb"
164 python_package "pyotp" do
168 directory "/srv/tile.openstreetmap.org/cgi-bin" do
174 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
179 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
182 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
189 template "/etc/cron.hourly/export" do
190 source "export.cron.erb"
196 directory "/srv/tile.openstreetmap.org/data" do
208 node[:tile][:data].each_value do |data|
210 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
213 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
215 directory directory do
221 directory = "/srv/tile.openstreetmap.org/data"
227 command "tar -zxf #{file} -C #{directory}"
231 elsif file =~ /\.tar\.bz2$/
234 command "tar -jxf #{file} -C #{directory}"
238 elsif file =~ /\.zip$/
241 command "unzip -qq -o #{file} -d #{directory}"
247 execute "#{file}_shapeindex" do
249 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
252 subscribes :run, "execute[#{file}]", :immediately
258 use_conditional_get true
261 action :create_if_missing
269 notifies :run, "execute[#{file}]", :immediately
270 notifies :restart, "service[renderd]"
274 nodejs_package "carto"
276 systemd_service "update-lowzoom@" do
277 description "Low zoom tile update service for %i layer"
278 conflicts "render-lowzoom.service"
280 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
281 runtime_directory "update-lowzoom-%i"
285 protect_system "strict"
288 "/srv/tile.openstreetmap.org/tiles/%i",
291 no_new_privileges true
295 directory "/srv/tile.openstreetmap.org/styles" do
301 node[:tile][:styles].each do |name, details|
302 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
303 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
305 template "/usr/local/bin/update-lowzoom-#{name}" do
306 source "update-lowzoom.erb"
310 variables :style => name
313 service "update-lowzoom@#{name}" do
315 supports :restart => true
318 directory tile_directory do
324 details[:tile_directories].each do |directory|
325 directory directory[:name] do
331 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
332 directory "#{directory[:name]}/#{zoom}" do
338 link "#{tile_directory}/#{zoom}" do
339 to "#{directory[:name]}/#{zoom}"
346 file "#{tile_directory}/planet-import-complete" do
347 action :create_if_missing
353 git style_directory do
355 repository details[:repository]
356 revision details[:revision]
361 link "#{style_directory}/data" do
362 to "/srv/tile.openstreetmap.org/data"
367 if details[:fonts_script]
368 execute details[:fonts_script] do
370 command details[:fonts_script]
374 subscribes :run, "git[#{style_directory}]"
378 execute "#{style_directory}/project.mml" do
380 command "carto -a 3.0.0 project.mml > project.xml"
384 subscribes :run, "git[#{style_directory}]"
385 notifies :restart, "service[renderd]", :immediately
386 notifies :restart, "service[update-lowzoom@#{name}]"
390 postgresql_version = node[:tile][:database][:cluster].split("/").first
391 postgis_version = node[:tile][:database][:postgis]
393 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
395 postgresql_user "jburgess" do
396 cluster node[:tile][:database][:cluster]
400 postgresql_user "tomh" do
401 cluster node[:tile][:database][:cluster]
405 postgresql_user "pnorman" do
406 cluster node[:tile][:database][:cluster]
410 postgresql_user "tile" do
411 cluster node[:tile][:database][:cluster]
414 postgresql_user "www-data" do
415 cluster node[:tile][:database][:cluster]
418 postgresql_user "_renderd" do
419 cluster node[:tile][:database][:cluster]
422 postgresql_database "gis" do
423 cluster node[:tile][:database][:cluster]
427 postgresql_extension "postgis" do
428 cluster node[:tile][:database][:cluster]
432 postgresql_extension "hstore" do
433 cluster node[:tile][:database][:cluster]
435 only_if { node[:tile][:database][:hstore] }
438 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
439 postgresql_table table do
440 cluster node[:tile][:database][:cluster]
443 permissions "tile" => :all
447 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
448 postgresql_table table do
449 cluster node[:tile][:database][:cluster]
452 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
462 if node[:tile][:database][:external_data_script]
463 execute node[:tile][:database][:external_data_script] do
464 command "#{node[:tile][:database][:external_data_script]} -R _renderd"
465 cwd "/srv/tile.openstreetmap.org"
471 Array(node[:tile][:database][:external_data_tables]).each do |table|
472 postgresql_table table do
473 cluster node[:tile][:database][:cluster]
476 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
481 postgresql_munin "gis" do
482 cluster node[:tile][:database][:cluster]
486 directory File.dirname(node[:tile][:database][:node_file]) do
493 file node[:tile][:database][:node_file] do
499 directory "/var/log/tile" do
512 gem_package "apachelogregex" do
513 gem_binary node[:ruby][:gem]
516 gem_package "file-tail" do
517 gem_binary node[:ruby][:gem]
520 gem_package "lru_redux" do
521 gem_binary node[:ruby][:gem]
524 remote_directory "/usr/local/bin" do
534 template "/usr/local/bin/tile-ratelimit" do
535 source "tile-ratelimit.erb"
541 systemd_service "tile-ratelimit" do
542 description "Monitor tile requests and enforce rate limits"
543 after "apache2.service"
546 exec_start "/usr/local/bin/tile-ratelimit"
551 protect_system "strict"
553 read_write_paths "/srv/tile.openstreetmap.org/conf"
554 no_new_privileges true
558 service "tile-ratelimit" do
559 action [:enable, :start]
560 subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
561 subscribes :restart, "systemd_service[tile-ratelimit]"
564 template "/usr/local/bin/expire-tiles" do
565 source "expire-tiles.erb"
571 directory "/var/lib/replicate" do
577 directory "/var/lib/replicate/expire-queue" do
583 template "/usr/local/bin/replicate" do
584 source "replicate.erb"
588 variables :postgresql_version => postgresql_version.to_f
591 systemd_service "expire-tiles" do
592 description "Tile dirtying service"
595 exec_start "/usr/local/bin/expire-tiles"
597 standard_output "null"
600 protect_system "strict"
603 "/store/database/nodes",
605 "/var/lib/replicate/expire-queue",
608 no_new_privileges true
611 systemd_path "expire-tiles" do
612 description "Tile dirtying trigger"
613 directory_not_empty "/var/lib/replicate/expire-queue"
616 service "expire-tiles.path" do
617 action [:enable, :start]
618 subscribes :restart, "systemd_path[expire-tiles]"
621 systemd_service "replicate" do
622 description "Rendering database replication service"
623 after "postgresql.service"
624 wants "postgresql.service"
626 exec_start "/usr/local/bin/replicate"
629 protect_system "strict"
632 "/store/database/nodes",
633 "/var/lib/replicate",
636 no_new_privileges true
640 service "replicate" do
641 action [:enable, :start]
642 subscribes :restart, "template[/usr/local/bin/replicate]"
643 subscribes :restart, "systemd_service[replicate]"
646 template "/etc/logrotate.d/replicate" do
647 source "replicate.logrotate.erb"
653 template "/usr/local/bin/render-lowzoom" do
654 source "render-lowzoom.erb"
660 systemd_service "render-lowzoom" do
661 description "Render low zoom tiles"
662 condition_path_exists_glob "!/run/update-lowzoom-*"
664 exec_start "/usr/local/bin/render-lowzoom"
668 protect_system "strict"
670 read_write_paths "/var/log/tile"
671 no_new_privileges true
674 systemd_timer "render-lowzoom" do
675 description "Render low zoom tiles"
676 on_calendar "Fri *-*-* 23:00:00 UTC"
679 service "render-lowzoom.timer" do
680 action [:enable, :start]
683 package "liblockfile-simple-perl"
684 package "libfilesys-df-perl"
686 template "/usr/local/bin/cleanup-tiles" do
687 source "cleanup-tiles.erb"
693 tile_directories = node[:tile][:styles].collect do |_, style|
694 style[:tile_directories].collect { |directory| directory[:name] }
695 end.flatten.sort.uniq
697 tile_directories.each do |directory|
698 label = directory.gsub("/", "-")
700 cron_d "cleanup-tiles#{label}" do
703 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
704 mailto "admins@openstreetmap.org"
708 munin_plugin "mod_tile_fresh"
709 munin_plugin "mod_tile_latency"
710 munin_plugin "mod_tile_response"
711 munin_plugin "mod_tile_zoom"
713 munin_plugin "renderd_processed"
714 munin_plugin "renderd_queue"
715 munin_plugin "renderd_queue_time"
716 munin_plugin "renderd_zoom"
717 munin_plugin "renderd_zoom_time"
719 munin_plugin "replication_delay"
721 package "ruby-webrick"
723 prometheus_exporter "modtile" do
727 prometheus_exporter "renderd" do