From: Tom Hughes Date: Mon, 17 Jun 2013 20:57:12 +0000 (+0100) Subject: Add DNS cookbook X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/effb14435dcfd32dbfe1d2693117dfa97e9db84d?ds=sidebyside Add DNS cookbook --- diff --git a/cookbooks/dns/README.rdoc b/cookbooks/dns/README.rdoc new file mode 100644 index 000000000..3de2ec7a3 --- /dev/null +++ b/cookbooks/dns/README.rdoc @@ -0,0 +1,8 @@ += DESCRIPTION: + += REQUIREMENTS: + += ATTRIBUTES: + += USAGE: + diff --git a/cookbooks/dns/files/default/html/dns.css b/cookbooks/dns/files/default/html/dns.css new file mode 100644 index 000000000..0a22de636 --- /dev/null +++ b/cookbooks/dns/files/default/html/dns.css @@ -0,0 +1,7 @@ +#map { + position: absolute; + top: 0px; + bottom: 0px; + left: 0px; + right: 0px; +} diff --git a/cookbooks/dns/files/default/html/dns.js b/cookbooks/dns/files/default/html/dns.js new file mode 100644 index 000000000..0677292a3 --- /dev/null +++ b/cookbooks/dns/files/default/html/dns.js @@ -0,0 +1,35 @@ +function createMap(divName, jsonFile) { + // Create a map + var map = L.map(divName); + + // Add OpenStreetMap layer + L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { + attribution: "© OpenStreetMap and contributors, under an open license", + maxZoom: 18 + }).addTo(map); + + // Add the JSON file as an overlay + $.ajax({ + url: jsonFile, + success: function(json) { + var jsonLayer = L.geoJson(json, { + style: function(feature) { + return { color: feature.properties.colour, weight: 2, opacity: 1 } + }, + onEachFeature: function (feature, layer) { + layer.bindPopup(feature.properties.country + " via " + feature.properties.server); + layer.on("mouseover", function () { + this.setStyle({ weight: 5 }); + }); + layer.on("mouseout", function () { + this.setStyle({ weight: 2 }); + }); + } + }).addTo(map); + + map.fitBounds(jsonLayer.getBounds()); + } + }); + + return map; +} diff --git a/cookbooks/dns/files/default/post-receive b/cookbooks/dns/files/default/post-receive new file mode 100644 index 000000000..0d8d82e9d --- /dev/null +++ b/cookbooks/dns/files/default/post-receive @@ -0,0 +1,13 @@ +#!/bin/zsh + +# DO NOT EDIT - This file is being maintained by Chef + +unset GIT_DIR + +while read oldrev newrev refname +do + if [[ "$refname" = "refs/heads/master" ]] + then + /usr/local/bin/dns-update + fi +done diff --git a/cookbooks/dns/metadata.rb b/cookbooks/dns/metadata.rb new file mode 100644 index 000000000..d2b4f54db --- /dev/null +++ b/cookbooks/dns/metadata.rb @@ -0,0 +1,6 @@ +maintainer "OpenStreetMap Administrators" +maintainer_email "admins@openstreetmap.org" +license "Apache 2.0" +description "Configure DNS management" +long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc')) +version "1.0.0" diff --git a/cookbooks/dns/recipes/default.rb b/cookbooks/dns/recipes/default.rb new file mode 100644 index 000000000..5486014d9 --- /dev/null +++ b/cookbooks/dns/recipes/default.rb @@ -0,0 +1,121 @@ +# +# Cookbook Name:: dns +# Recipe:: default +# +# Copyright 2011, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe "git" +include_recipe "apache" + +passwords = data_bag_item("dns", "passwords") + +package "make" + +package "perl" +package "libxml-treebuilder-perl" +package "libxml-writer-perl" +package "libyaml-perl" +package "libwww-perl" +package "libjson-xs-perl" + +directory "/srv/dns.openstreetmap.org" do + owner "root" + group "root" + mode 0755 +end + +remote_directory "/srv/dns.openstreetmap.org/html" do + source "html" + owner "root" + group "root" + mode 0755 + files_owner "root" + files_group "root" + files_mode 0644 +end + +zones = Array.new + +Dir.glob("/var/lib/dns/kml/*.kml").each do |kmlfile| + zone = File.basename(kmlfile, ".kml") + + template "/srv/dns.openstreetmap.org/html/#{zone}.html" do + source "zone.html.erb" + owner "root" + group "root" + mode 0644 + variables :zone => zone + end + + zones.push(zone) +end + +template "/srv/dns.openstreetmap.org/html/index.html" do + source "index.html.erb" + owner "root" + group "root" + mode 0644 + variables :zones => zones +end + +apache_site "dns.openstreetmap.org" do + template "apache.erb" + directory "/srv/dns.openstreetmap.org" +end + +template "/usr/local/bin/dns-update" do + source "dns-update.erb" + owner "root" + group "git" + mode 0750 + variables :passwords => passwords +end + +execute "dns-update" do + action :nothing + command "/usr/local/bin/dns-update" + user "git" + group "git" +end + +directory "/var/lib/dns" do + owner "git" + group "git" + mode 02775 + notifies :run, resources(:execute => "dns-update") +end + +cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do + source "post-receive" + owner "git" + group "git" + mode 0750 +end + +template "/usr/local/bin/dns-check" do + source "dns-check.erb" + owner "root" + group "git" + mode 0750 + variables :passwords => passwords +end + +template "/etc/cron.d/dns" do + source "cron.erb" + owner "root" + group "root" + mode 0644 +end diff --git a/cookbooks/dns/templates/default/apache.erb b/cookbooks/dns/templates/default/apache.erb new file mode 100644 index 000000000..478ca4262 --- /dev/null +++ b/cookbooks/dns/templates/default/apache.erb @@ -0,0 +1,12 @@ +# DO NOT EDIT - This file is being maintained by Chef + + + ServerName <%= @name %> + ServerAdmin webmaster@openstreetmap.org + + CustomLog /var/log/apache2/<%= @name %>-access.log combined + ErrorLog /var/log/apache2/<%= @name %>-error.log + + DocumentRoot <%= @directory %>/html + Alias /json/ /var/lib/dns/json/ + diff --git a/cookbooks/dns/templates/default/cron.erb b/cookbooks/dns/templates/default/cron.erb new file mode 100644 index 000000000..5ab9b3af7 --- /dev/null +++ b/cookbooks/dns/templates/default/cron.erb @@ -0,0 +1,3 @@ +# DO NOT EDIT - This file is being maintained by Chef + +*/3 * * * * git /usr/local/bin/dns-check diff --git a/cookbooks/dns/templates/default/dns-check.erb b/cookbooks/dns/templates/default/dns-check.erb new file mode 100755 index 000000000..24fc320e2 --- /dev/null +++ b/cookbooks/dns/templates/default/dns-check.erb @@ -0,0 +1,7 @@ +#!/bin/sh + +export RSYNC_PASSWORD=<%= @passwords["rsync"] %> +export PINGDOM_USERNAME=pingdom@openstreetmap.org +export PINGDOM_PASSWORD=<%= @passwords["pingdom"] %> + +make --quiet --directory=/var/lib/dns --assume-new=lib/countries.xml update > /dev/null diff --git a/cookbooks/dns/templates/default/dns-update.erb b/cookbooks/dns/templates/default/dns-update.erb new file mode 100755 index 000000000..596a4dd7d --- /dev/null +++ b/cookbooks/dns/templates/default/dns-update.erb @@ -0,0 +1,20 @@ +#!/bin/sh + +# DO NOT EDIT - This file is being maintained by Chef + +umask 0002 + +export RSYNC_PASSWORD=<%= @passwords["rsync"] %> +export PINGDOM_USERNAME=pingdom@openstreetmap.org +export PINGDOM_PASSWORD=<%= @passwords["pingdom"] %> + +cd /var/lib/dns + +if [ ! -d .git ] +then + git clone /var/lib/git/dns.git /var/lib/dns +fi + +git pull -q + +make update diff --git a/cookbooks/dns/templates/default/index.html.erb b/cookbooks/dns/templates/default/index.html.erb new file mode 100644 index 000000000..3a70473e4 --- /dev/null +++ b/cookbooks/dns/templates/default/index.html.erb @@ -0,0 +1,13 @@ + + + + + GeoDNS - Zones + + +

GeoDNS Zones

+ <% @zones.each do |zone| -%> +

<%= zone %>

+ <% end -%> + + diff --git a/cookbooks/dns/templates/default/zone.html.erb b/cookbooks/dns/templates/default/zone.html.erb new file mode 100644 index 000000000..792b65ca0 --- /dev/null +++ b/cookbooks/dns/templates/default/zone.html.erb @@ -0,0 +1,18 @@ + + + + + GeoDNS - <%= @zone %> + + + + + + + + +
+ +