]> git.openstreetmap.org Git - chef.git/blob - cookbooks/dns/recipes/default.rb
Merge remote-tracking branch 'github/pull/350' into master
[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-libyaml-perl
39   lockfile-progs
40 ]
41
42 remote_file "/usr/local/bin/dnscontrol" do
43   action :create
44   source "https://github.com/StackExchange/dnscontrol/releases/download/v3.4.2/dnscontrol-Linux"
45   owner "root"
46   group "root"
47   mode "755"
48 end
49
50 directory "/srv/dns.openstreetmap.org" do
51   owner "root"
52   group "root"
53   mode "755"
54 end
55
56 remote_directory "/srv/dns.openstreetmap.org/html" do
57   source "html"
58   owner "root"
59   group "root"
60   mode "755"
61   files_owner "root"
62   files_group "root"
63   files_mode "644"
64 end
65
66 zones = []
67
68 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
69   zone = File.basename(kmlfile, ".json")
70
71   template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
72     source "zone.html.erb"
73     owner "root"
74     group "root"
75     mode "644"
76     variables :zone => zone
77   end
78
79   zones.push(zone)
80 end
81
82 template "/srv/dns.openstreetmap.org/html/index.html" do
83   source "index.html.erb"
84   owner "root"
85   group "root"
86   mode "644"
87   variables :zones => zones
88 end
89
90 ssl_certificate "dns.openstreetmap.org" do
91   domains ["dns.openstreetmap.org", "dns.osm.org"]
92   notifies :reload, "service[apache2]"
93 end
94
95 apache_site "dns.openstreetmap.org" do
96   template "apache.erb"
97   directory "/srv/dns.openstreetmap.org"
98   variables :aliases => ["dns.osm.org"]
99 end
100
101 template "/usr/local/bin/dns-update" do
102   source "dns-update.erb"
103   owner "root"
104   group "git"
105   mode "750"
106   variables :passwords => passwords, :geoservers => geoservers
107 end
108
109 execute "dns-update" do
110   action :nothing
111   command "/usr/local/bin/dns-update"
112   user "git"
113   group "git"
114 end
115
116 directory "/var/lib/dns" do
117   owner "git"
118   group "git"
119   mode "2775"
120   notifies :run, "execute[dns-update]"
121 end
122
123 template "/var/lib/dns/creds.json" do
124   source "creds.json.erb"
125   owner "git"
126   group "git"
127   mode "440"
128   variables :passwords => passwords
129 end
130
131 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
132   source "post-receive"
133   owner "git"
134   group "git"
135   mode "750"
136   only_if { ::Dir.exist?("#{node[:dns][:repository]}/hooks") }
137 end
138
139 template "/usr/local/bin/dns-check" do
140   source "dns-check.erb"
141   owner "root"
142   group "git"
143   mode "750"
144   variables :passwords => passwords, :geoservers => geoservers
145 end
146
147 cron_d "dns" do
148   minute "*/3"
149   user "git"
150   command "/usr/local/bin/dns-check"
151   mailto "admins@openstreetmap.org"
152 end