]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tilecache/recipes/default.rb
Remove FTP pasv port restrictions
[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 #     https://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 include_recipe "ssl"
23 include_recipe "squid"
24 include_recipe "nginx"
25
26 package "apache2" do
27   action :remove
28 end
29
30 package %w[
31   xz-utils
32   openssl
33 ]
34
35 # oathtool for QoS token
36 package "oathtool"
37
38 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
39 tilerenders = search(:node, "roles:tile").sort_by { |n| n[:hostname] }
40
41 web_passwords = data_bag_item("web", "passwords")
42
43 tilecaches.each do |cache|
44   cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address|
45     firewall_rule "accept-squid" do
46       action :accept
47       family "inet"
48       source "net:#{address}"
49       dest "fw"
50       proto "tcp:syn"
51       dest_ports "3128"
52       source_ports "1024:"
53     end
54     firewall_rule "accept-squid-icp" do
55       action :accept
56       family "inet"
57       source "net:#{address}"
58       dest "fw"
59       proto "udp"
60       dest_ports "3130"
61       source_ports "3130"
62     end
63     firewall_rule "accept-squid-icp-reply" do
64       action :accept
65       family "inet"
66       source "fw"
67       dest "net:#{address}"
68       proto "udp"
69       dest_ports "3130"
70       source_ports "3130"
71     end
72   end
73 end
74
75 squid_fragment "tilecache" do
76   template "squid.conf.erb"
77   variables :caches => tilecaches, :renders => tilerenders
78 end
79
80 package "rsync"
81
82 template "/etc/logrotate.d/squid" do
83   source "logrotate.squid.erb"
84   owner "root"
85   group "root"
86   mode 0o644
87 end
88
89 nginx_site "default" do
90   action [:delete]
91 end
92
93 template "/usr/local/bin/nginx_generate_tilecache_qos_map" do
94   source "nginx_generate_tilecache_qos_map.erb"
95   owner "root"
96   group "root"
97   mode 0o750
98   variables :totp_key => web_passwords["totp_key"]
99 end
100
101 template "/etc/cron.d/tilecache" do
102   source "cron.erb"
103   owner "root"
104   group "root"
105   mode 0o644
106 end
107
108 execute "execute_nginx_generate_tilecache_qos_map" do
109   command "/usr/local/bin/nginx_generate_tilecache_qos_map"
110   creates "/etc/nginx/conf.d/tile_qos_rates.map"
111   action :run
112 end
113
114 ssl_certificate "tile.openstreetmap.org" do
115   domains ["tile.openstreetmap.org",
116            "a.tile.openstreetmap.org",
117            "b.tile.openstreetmap.org",
118            "c.tile.openstreetmap.org",
119            "tile.osm.org",
120            "a.tile.osm.org",
121            "b.tile.osm.org",
122            "c.tile.osm.org"]
123   notifies :restart, "service[nginx]"
124 end
125
126 nginx_site "tile" do
127   template "nginx_tile.conf.erb"
128   variables :caches => tilecaches
129 end
130
131 template "/etc/logrotate.d/nginx" do
132   source "logrotate.nginx.erb"
133   owner "root"
134   group "root"
135   mode 0o644
136 end
137
138 tilerenders.each do |render|
139   munin_plugin "ping_#{render[:fqdn]}" do
140     target "ping_"
141     conf "munin.ping.erb"
142     conf_variables :host => render[:fqdn]
143   end
144 end