]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tilecache/recipes/default.rb
86c7d0250d14b7cc7c6346a34c2f3681973212d3
[chef.git] / cookbooks / tilecache / recipes / default.rb
1 #
2 # Cookbook Name:: tilecache
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 require "ipaddr"
21
22 certificate = node[:tilecache][:ssl][:certificate]
23 node.default[:ssl][:certificates] = node[:ssl][:certificates] | [certificate]
24
25 include_recipe "ssl"
26 include_recipe "squid"
27 include_recipe "nginx"
28
29 package "apache2" do
30   action :remove
31 end
32
33 package "xz-utils"
34 package "openssl"
35
36 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
37 tilerenders = search(:node, "roles:tile").sort_by { |n| n[:hostname] }
38
39 tilecaches.each do |cache|
40   cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address|
41     firewall_rule "accept-squid" do
42       action :accept
43       family "inet"
44       source "net:#{address}"
45       dest "fw"
46       proto "tcp:syn"
47       dest_ports "3128"
48       source_ports "1024:"
49     end
50     firewall_rule "accept-squid-icp" do
51       action :accept
52       family "inet"
53       source "net:#{address}"
54       dest "fw"
55       proto "udp"
56       dest_ports "3130"
57       source_ports "3130"
58     end
59     firewall_rule "accept-squid-icp-reply" do
60       action :accept
61       family "inet"
62       source "fw"
63       dest "net:#{address}"
64       proto "udp"
65       dest_ports "3130"
66       source_ports "3130"
67     end
68   end
69 end
70
71 squid_fragment "tilecache" do
72   template "squid.conf.erb"
73   variables :caches => tilecaches, :renders => tilerenders
74 end
75
76 template "/etc/logrotate.d/squid" do
77   source "logrotate.squid.erb"
78   owner "root"
79   group "root"
80   mode 0644
81 end
82
83 nginx_site "default" do
84   action [:delete]
85 end
86
87 resolvers = node[:networking][:nameservers].map do |resolver|
88   IPAddr.new(resolver).ipv6? ? "[#{resolver}]" : resolver
89 end
90
91 nginx_site "tile-ssl" do
92   template "nginx_tile_ssl.conf.erb"
93   variables :certificate => certificate, :resolvers => resolvers, :caches => tilecaches
94 end
95
96 service "nginx-certificate-restart" do
97   service_name "nginx"
98   action :nothing
99   subscribes :restart, "cookbook_file[/etc/ssl/certs/rapidssl.pem]"
100   subscribes :restart, "cookbook_file[/etc/ssl/certs/#{certificate}.pem]"
101   subscribes :restart, "file[/etc/ssl/private/#{certificate}.key]"
102 end
103
104 template "/etc/logrotate.d/nginx" do
105   source "logrotate.nginx.erb"
106   owner "root"
107   group "root"
108   mode 0644
109 end
110
111 tilerenders.each do |render|
112   munin_plugin "ping_#{render[:fqdn]}" do
113     target "ping_"
114     conf "munin.ping.erb"
115     conf_variables :host => render[:fqdn]
116   end
117 end