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
102 description "Mapnik rendering daemon"
103 after "postgresql.service"
104 wants "postgresql.service"
106 exec_start "/usr/bin/renderd -f"
107 runtime_directory "renderd"
108 standard_error "null"
113 protect_system "full"
115 no_new_privileges true
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_database "gis" do
417 cluster node[:tile][:database][:cluster]
421 postgresql_extension "postgis" do
422 cluster node[:tile][:database][:cluster]
426 postgresql_extension "hstore" do
427 cluster node[:tile][:database][:cluster]
429 only_if { node[:tile][:database][:hstore] }
432 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
433 postgresql_table table do
434 cluster node[:tile][:database][:cluster]
437 permissions "tile" => :all
441 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
442 postgresql_table table do
443 cluster node[:tile][:database][:cluster]
446 permissions "tile" => :all, "www-data" => :select
456 if node[:tile][:database][:external_data_script]
457 execute node[:tile][:database][:external_data_script] do
458 command "#{node[:tile][:database][:external_data_script]} -R www-data"
459 cwd "/srv/tile.openstreetmap.org"
465 postgresql_munin "gis" do
466 cluster node[:tile][:database][:cluster]
470 directory File.dirname(node[:tile][:database][:node_file]) do
477 file node[:tile][:database][:node_file] do
483 directory "/var/log/tile" do
497 gem_package "apachelogregex"
498 gem_package "file-tail"
499 gem_package "lru_redux"
501 remote_directory "/usr/local/bin" do
511 template "/usr/local/bin/tile-ratelimit" do
512 source "tile-ratelimit.erb"
518 systemd_service "tile-ratelimit" do
519 description "Monitor tile requests and enforce rate limits"
520 after "apache2.service"
523 exec_start "/usr/local/bin/tile-ratelimit"
527 protect_system "full"
529 read_write_paths "/srv/tile.openstreetmap.org/conf"
530 no_new_privileges true
534 service "tile-ratelimit" do
535 action [:enable, :start]
536 subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
537 subscribes :restart, "systemd_service[tile-ratelimit]"
540 template "/usr/local/bin/expire-tiles" do
541 source "expire-tiles.erb"
547 directory "/var/lib/replicate" do
553 directory "/var/lib/replicate/expire-queue" do
559 template "/usr/local/bin/replicate" do
560 source "replicate.erb"
564 variables :postgresql_version => postgresql_version.to_f
567 systemd_service "expire-tiles" do
568 description "Tile dirtying service"
571 exec_start "/usr/local/bin/expire-tiles"
572 standard_output "null"
575 protect_system "full"
577 no_new_privileges true
580 systemd_path "expire-tiles" do
581 description "Tile dirtying trigger"
582 directory_not_empty "/var/lib/replicate/expire-queue"
585 service "expire-tiles.path" do
586 action [:enable, :start]
587 subscribes :restart, "systemd_path[expire-tiles]"
590 systemd_service "replicate" do
591 description "Rendering database replication service"
592 after "postgresql.service"
593 wants "postgresql.service"
595 exec_start "/usr/local/bin/replicate"
598 protect_system "full"
600 no_new_privileges true
604 service "replicate" do
605 action [:enable, :start]
606 subscribes :restart, "template[/usr/local/bin/replicate]"
607 subscribes :restart, "systemd_service[replicate]"
610 template "/etc/logrotate.d/replicate" do
611 source "replicate.logrotate.erb"
617 template "/usr/local/bin/render-lowzoom" do
618 source "render-lowzoom.erb"
624 systemd_service "render-lowzoom" do
625 description "Render low zoom tiles"
626 condition_path_exists_glob "!/run/update-lowzoom-*"
628 exec_start "/usr/local/bin/render-lowzoom"
632 protect_system "full"
634 no_new_privileges true
637 systemd_timer "render-lowzoom" do
638 description "Render low zoom tiles"
639 on_calendar "Sun *-*~07/1 01:00:00"
642 service "render-lowzoom.timer" do
643 action [:enable, :start]
646 package "liblockfile-simple-perl"
647 package "libfilesys-df-perl"
649 template "/usr/local/bin/cleanup-tiles" do
650 source "cleanup-tiles.erb"
656 tile_directories = node[:tile][:styles].collect do |_, style|
657 style[:tile_directories].collect { |directory| directory[:name] }
658 end.flatten.sort.uniq
660 tile_directories.each do |directory|
661 label = directory.gsub("/", "-")
663 cron_d "cleanup-tiles#{label}" do
666 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
667 mailto "admins@openstreetmap.org"
671 munin_plugin "mod_tile_fresh"
672 munin_plugin "mod_tile_latency"
673 munin_plugin "mod_tile_response"
674 munin_plugin "mod_tile_zoom"
676 munin_plugin "renderd_processed"
677 munin_plugin "renderd_queue"
678 munin_plugin "renderd_queue_time"
679 munin_plugin "renderd_zoom"
680 munin_plugin "renderd_zoom_time"
682 munin_plugin "replication_delay"
684 prometheus_exporter "modtile" do
688 prometheus_exporter "renderd" do