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