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