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