5 # Copyright:: 2011, 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"
 
  24 geoservers = search(:node, "roles:geodns").collect(&:name).sort
 
  26 passwords = data_bag_item("dns", "passwords")
 
  36   libxml-treebuilder-perl
 
  43 cache_dir = Chef::Config[:file_cache_path]
 
  45 dnscontrol_version = "3.23.0"
 
  47 dnscontrol_arch = if arm?
 
  53 remote_file "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb" do
 
  54   source "https://github.com/StackExchange/dnscontrol/releases/download/v#{dnscontrol_version}/dnscontrol-#{dnscontrol_version}.#{dnscontrol_arch}.deb"
 
  61 dpkg_package "dnscontrol" do
 
  63   source "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb"
 
  64   subscribes :install, "remote_file[#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb]"
 
  67 directory "/srv/dns.openstreetmap.org" do
 
  73 remote_directory "/srv/dns.openstreetmap.org/html" do
 
  85 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
 
  86   zone = File.basename(kmlfile, ".json")
 
  88   template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
 
  89     source "zone.html.erb"
 
  93     variables :zone => zone
 
  99 template "/srv/dns.openstreetmap.org/html/index.html" do
 
 100   source "index.html.erb"
 
 104   variables :zones => zones
 
 107 ssl_certificate "dns.openstreetmap.org" do
 
 108   domains ["dns.openstreetmap.org", "dns.osm.org"]
 
 109   notifies :reload, "service[apache2]"
 
 112 apache_site "dns.openstreetmap.org" do
 
 113   template "apache.erb"
 
 114   directory "/srv/dns.openstreetmap.org"
 
 115   variables :aliases => ["dns.osm.org"]
 
 118 template "/usr/local/bin/dns-update" do
 
 119   source "dns-update.erb"
 
 123   variables :passwords => passwords, :geoservers => geoservers
 
 126 execute "dns-update" do
 
 128   command "/usr/local/bin/dns-update"
 
 133 directory "/var/lib/dns" do
 
 137   notifies :run, "execute[dns-update]"
 
 140 template "/var/lib/dns/creds.json" do
 
 141   source "creds.json.erb"
 
 145   variables :passwords => passwords
 
 148 template "/var/lib/dns/include/geo.js" do
 
 153   variables :geoservers => geoservers
 
 154   only_if { ::Dir.exist?("/var/lib/dns/include") }
 
 157 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
 
 158   source "post-receive"
 
 162   only_if { ::Dir.exist?("#{node[:dns][:repository]}/hooks") }
 
 165 template "/usr/local/bin/dns-check" do
 
 166   source "dns-check.erb"
 
 170   variables :passwords => passwords, :geoservers => geoservers
 
 173 systemd_service "dns-check" do
 
 174   description "Rebuild DNS zones with GeoDNS changes"
 
 175   exec_start "/usr/local/bin/dns-check"
 
 177   sandbox :enable_network => true
 
 179   read_write_paths "/var/lib/dns"
 
 182 systemd_timer "dns-check" do
 
 183   description "Rebuild DNS zones with GeoDNS changes"
 
 185   on_unit_active_sec "3m"
 
 188 service "dns-check.timer" do
 
 189   action [:enable, :start]