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 = "4.3.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
62 source "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb"
63 version "#{dnscontrol_version}"
66 directory "/srv/dns.openstreetmap.org" do
72 remote_directory "/srv/dns.openstreetmap.org/html" do
84 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
85 zone = File.basename(kmlfile, ".json")
87 template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
88 source "zone.html.erb"
92 variables :zone => zone
98 template "/srv/dns.openstreetmap.org/html/index.html" do
99 source "index.html.erb"
103 variables :zones => zones
106 ssl_certificate "dns.openstreetmap.org" do
107 domains ["dns.openstreetmap.org", "dns.osm.org"]
108 notifies :reload, "service[apache2]"
111 apache_site "dns.openstreetmap.org" do
112 template "apache.erb"
113 directory "/srv/dns.openstreetmap.org"
114 variables :aliases => ["dns.osm.org"]
117 template "/usr/local/bin/dns-update" do
118 source "dns-update.erb"
122 variables :passwords => passwords, :geoservers => geoservers
125 execute "dns-update" do
127 command "/usr/local/bin/dns-update"
132 directory "/var/lib/dns" do
136 notifies :run, "execute[dns-update]"
139 template "/var/lib/dns/creds.json" do
140 source "creds.json.erb"
144 variables :passwords => passwords
147 template "/var/lib/dns/include/geo.js" do
152 variables :geoservers => geoservers
153 only_if { ::Dir.exist?("/var/lib/dns/include") }
156 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
157 source "post-receive"
161 only_if { ::Dir.exist?("#{node[:dns][:repository]}/hooks") }
164 template "/usr/local/bin/dns-check" do
165 source "dns-check.erb"
169 variables :passwords => passwords, :geoservers => geoservers
172 systemd_service "dns-check" do
173 description "Rebuild DNS zones with GeoDNS changes"
174 exec_start "/usr/local/bin/dns-check"
176 sandbox :enable_network => true
178 read_write_paths "/var/lib/dns"
181 systemd_timer "dns-check" do
182 description "Rebuild DNS zones with GeoDNS changes"
184 on_unit_active_sec "3m"
187 service "dns-check.timer" do
188 action [:enable, :start]