]> git.openstreetmap.org Git - chef.git/blob - cookbooks/dns/recipes/default.rb
a78d1d5fc952e583d924c30377fbec368f7a1e86
[chef.git] / cookbooks / dns / recipes / default.rb
1 #
2 # Cookbook Name:: 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 "git"
21 include_recipe "apache"
22
23 passwords = data_bag_item("dns", "passwords")
24
25 package %w[
26   make
27   perl
28   libxml-treebuilder-perl
29   libxml-writer-perl
30   libyaml-perl
31   libwww-perl
32   libjson-xs-perl
33 ]
34
35 directory "/srv/dns.openstreetmap.org" do
36   owner "root"
37   group "root"
38   mode 0o755
39 end
40
41 remote_directory "/srv/dns.openstreetmap.org/html" do
42   source "html"
43   owner "root"
44   group "root"
45   mode 0o755
46   files_owner "root"
47   files_group "root"
48   files_mode 0o644
49 end
50
51 zones = []
52
53 Dir.glob("/var/lib/dns/json/*.json").each do |kmlfile|
54   zone = File.basename(kmlfile, ".json")
55
56   template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
57     source "zone.html.erb"
58     owner "root"
59     group "root"
60     mode 0o644
61     variables :zone => zone
62   end
63
64   zones.push(zone)
65 end
66
67 template "/srv/dns.openstreetmap.org/html/index.html" do
68   source "index.html.erb"
69   owner "root"
70   group "root"
71   mode 0o644
72   variables :zones => zones
73 end
74
75 ssl_certificate "dns.openstreetmap.org" do
76   domains ["dns.openstreetmap.org", "dns.osm.org"]
77   notifies :reload, "service[apache2]"
78 end
79
80 apache_site "dns.openstreetmap.org" do
81   template "apache.erb"
82   directory "/srv/dns.openstreetmap.org"
83   variables :aliases => ["dns.osm.org"]
84 end
85
86 template "/usr/local/bin/dns-update" do
87   source "dns-update.erb"
88   owner "root"
89   group "git"
90   mode 0o750
91   variables :passwords => passwords
92 end
93
94 execute "dns-update" do
95   action :nothing
96   command "/usr/local/bin/dns-update"
97   user "git"
98   group "git"
99 end
100
101 directory "/var/lib/dns" do
102   owner "git"
103   group "git"
104   mode 0o2775
105   notifies :run, "execute[dns-update]"
106 end
107
108 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
109   source "post-receive"
110   owner "git"
111   group "git"
112   mode 0o750
113 end
114
115 template "/usr/local/bin/dns-check" do
116   source "dns-check.erb"
117   owner "root"
118   group "git"
119   mode 0o750
120   variables :passwords => passwords
121 end
122
123 template "/etc/cron.d/dns" do
124   source "cron.erb"
125   owner "root"
126   group "root"
127   mode 0o644
128 end