]> git.openstreetmap.org Git - chef.git/blob - cookbooks/dns/recipes/default.rb
8db66d6c986e2a0c49d03714ef69ee51a9e53213
[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::ssl"
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 ssl_certificate "dns.openstreetmap.org" do
75   domains "dns.openstreetmap.org"
76   notifies :reload, "service[apache2]"
77 end
78
79 apache_site "dns.openstreetmap.org" do
80   template "apache.erb"
81   directory "/srv/dns.openstreetmap.org"
82 end
83
84 template "/usr/local/bin/dns-update" do
85   source "dns-update.erb"
86   owner "root"
87   group "git"
88   mode 0o750
89   variables :passwords => passwords
90 end
91
92 execute "dns-update" do
93   action :nothing
94   command "/usr/local/bin/dns-update"
95   user "git"
96   group "git"
97 end
98
99 directory "/var/lib/dns" do
100   owner "git"
101   group "git"
102   mode 0o2775
103   notifies :run, "execute[dns-update]"
104 end
105
106 cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
107   source "post-receive"
108   owner "git"
109   group "git"
110   mode 0o750
111 end
112
113 template "/usr/local/bin/dns-check" do
114   source "dns-check.erb"
115   owner "root"
116   group "git"
117   mode 0o750
118   variables :passwords => passwords
119 end
120
121 template "/etc/cron.d/dns" do
122   source "cron.erb"
123   owner "root"
124   group "root"
125   mode 0o644
126 end