]> git.openstreetmap.org Git - chef.git/blob - cookbooks/dns/recipes/default.rb
Install libyaml-perl for dns-check
[chef.git] / cookbooks / dns / recipes / default.rb
1 #
2 # Cookbook:: dns
3 # Recipe:: default
4 #
5 # Copyright:: 2011, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "accounts"
21 include_recipe "apache"
22 include_recipe "git"
23
24 geoservers = search(:node, "roles:geodns").collect(&:name).sort
25
26 passwords = data_bag_item("dns", "passwords")
27
28 package %w[
29   make
30   parallel
31   rsync
32   perl
33   libdigest-sha-perl
34   libjson-xs-perl
35   libwww-perl
36   libxml-treebuilder-perl
37   libxml-writer-perl
38   libyaml-perl
39   libyaml-libyaml-perl
40   lockfile-progs
41 ]
42
43 cache_dir = Chef::Config[:file_cache_path]
44
45 dnscontrol_version = "3.21.0"
46
47 dnscontrol_arch = if arm?
48                     "arm64"
49                   else
50                     "amd64"
51                   end
52
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"
55   owner "root"
56   group "root"
57   mode "644"
58   backup false
59 end
60
61 dpkg_package "dnscontrol" do
62   action :nothing
63   source "#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb"
64   subscribes :install, "remote_file[#{cache_dir}/dnscontrol-#{dnscontrol_version}.deb]"
65 end
66
67 directory "/srv/dns.openstreetmap.org" do
68   owner "root"
69   group "root"
70   mode "755"
71 end
72
73 remote_directory "/srv/dns.openstreetmap.org/html" do
74   source "html"
75   owner "root"
76   group "root"
77   mode "755"
78   files_owner "root"
79   files_group "root"
80   files_mode "644"
81 end
82
83 zones = []
84
85 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
86   zone = File.basename(kmlfile, ".json")
87
88   template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
89     source "zone.html.erb"
90     owner "root"
91     group "root"
92     mode "644"
93     variables :zone => zone
94   end
95
96   zones.push(zone)
97 end
98
99 template "/srv/dns.openstreetmap.org/html/index.html" do
100   source "index.html.erb"
101   owner "root"
102   group "root"
103   mode "644"
104   variables :zones => zones
105 end
106
107 ssl_certificate "dns.openstreetmap.org" do
108   domains ["dns.openstreetmap.org", "dns.osm.org"]
109   notifies :reload, "service[apache2]"
110 end
111
112 apache_site "dns.openstreetmap.org" do
113   template "apache.erb"
114   directory "/srv/dns.openstreetmap.org"
115   variables :aliases => ["dns.osm.org"]
116 end
117
118 template "/usr/local/bin/dns-update" do
119   source "dns-update.erb"
120   owner "root"
121   group "git"
122   mode "750"
123   variables :passwords => passwords, :geoservers => geoservers
124 end
125
126 execute "dns-update" do
127   action :nothing
128   command "/usr/local/bin/dns-update"
129   user "git"
130   group "git"
131 end
132
133 directory "/var/lib/dns" do
134   owner "git"
135   group "git"
136   mode "2775"
137   notifies :run, "execute[dns-update]"
138 end
139
140 template "/var/lib/dns/creds.json" do
141   source "creds.json.erb"
142   owner "git"
143   group "git"
144   mode "440"
145   variables :passwords => passwords
146 end
147
148 template "/var/lib/dns/include/geo.js" do
149   source "geo.js.erb"
150   owner "git"
151   group "git"
152   mode "440"
153   variables :geoservers => geoservers
154   only_if { ::Dir.exist?("/var/lib/dns/include") }
155 end
156
157 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
158   source "post-receive"
159   owner "git"
160   group "git"
161   mode "750"
162   only_if { ::Dir.exist?("#{node[:dns][:repository]}/hooks") }
163 end
164
165 template "/usr/local/bin/dns-check" do
166   source "dns-check.erb"
167   owner "root"
168   group "git"
169   mode "750"
170   variables :passwords => passwords, :geoservers => geoservers
171 end
172
173 systemd_service "dns-check" do
174   description "Rebuild DNS zones with GeoDNS changes"
175   exec_start "/usr/local/bin/dns-check"
176   user "git"
177   private_tmp true
178   private_devices true
179   protect_system "strict"
180   protect_home true
181   read_write_paths "/var/lib/dns"
182   no_new_privileges true
183 end
184
185 systemd_timer "dns-check" do
186   description "Rebuild DNS zones with GeoDNS changes"
187   on_boot_sec "3m"
188   on_unit_active_sec "3m"
189 end
190
191 service "dns-check.timer" do
192   action [:enable, :start]
193 end