]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tilecache/recipes/default.rb
Split out default munin plugin installation to a new recipe
[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 "fail2ban"
23 include_recipe "munin"
24 include_recipe "nginx"
25 include_recipe "squid"
26 include_recipe "ssl"
27
28 package "apache2" do
29   action :remove
30 end
31
32 package %w[
33   xz-utils
34   openssl
35 ]
36
37 # oathtool for QoS token
38 package "oathtool"
39
40 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
41 tilerenders = search(:node, "roles:tile").sort_by { |n| n[:hostname] }
42
43 web_passwords = data_bag_item("web", "passwords")
44
45 tilecaches.each do |cache|
46   cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address|
47     firewall_rule "accept-squid" do
48       action :accept
49       family "inet"
50       source "net:#{address}"
51       dest "fw"
52       proto "tcp:syn"
53       dest_ports "3128"
54       source_ports "1024:"
55     end
56
57     firewall_rule "accept-squid-icp" do
58       action :accept
59       family "inet"
60       source "net:#{address}"
61       dest "fw"
62       proto "udp"
63       dest_ports "3130"
64       source_ports "3130"
65     end
66
67     firewall_rule "accept-squid-icp-reply" do
68       action :accept
69       family "inet"
70       source "fw"
71       dest "net:#{address}"
72       proto "udp"
73       dest_ports "3130"
74       source_ports "3130"
75     end
76
77     firewall_rule "accept-squid-htcp" do
78       action :accept
79       family "inet"
80       source "net:#{address}"
81       dest "fw"
82       proto "udp"
83       dest_ports "4827"
84       source_ports "4827"
85     end
86
87     firewall_rule "accept-squid-htcp-reply" do
88       action :accept
89       family "inet"
90       source "fw"
91       dest "net:#{address}"
92       proto "udp"
93       dest_ports "4827"
94       source_ports "4827"
95     end
96   end
97 end
98
99 squid_fragment "tilecache" do
100   template "squid.conf.erb"
101   variables :caches => tilecaches, :renders => tilerenders
102 end
103
104 package "rsync"
105
106 template "/etc/logrotate.d/squid" do
107   source "logrotate.squid.erb"
108   owner "root"
109   group "root"
110   mode 0o644
111 end
112
113 # Configure cron with lower cpu and IO priority
114 systemd_service "cron-load" do
115   service "cron"
116   dropin "load"
117   nice 19
118   io_scheduling_class "best-effort"
119   io_scheduling_priority 7
120   notifies :restart, "service[cron]"
121 end
122
123 nginx_site "default" do
124   action [:delete]
125 end
126
127 template "/usr/local/bin/nginx_generate_tilecache_qos_map" do
128   source "nginx_generate_tilecache_qos_map.erb"
129   owner "root"
130   group "root"
131   mode 0o750
132   variables :totp_key => web_passwords["totp_key"]
133 end
134
135 template "/etc/cron.d/tilecache" do
136   source "cron.erb"
137   owner "root"
138   group "root"
139   mode 0o644
140 end
141
142 execute "execute_nginx_generate_tilecache_qos_map" do
143   command "/usr/local/bin/nginx_generate_tilecache_qos_map"
144   creates "/etc/nginx/conf.d/tile_qos_rates.map"
145   action :run
146 end
147
148 ssl_certificate "tile.openstreetmap.org" do
149   domains ["tile.openstreetmap.org",
150            "a.tile.openstreetmap.org",
151            "b.tile.openstreetmap.org",
152            "c.tile.openstreetmap.org",
153            "tile.osm.org",
154            "a.tile.osm.org",
155            "b.tile.osm.org",
156            "c.tile.osm.org"]
157   notifies :restart, "service[nginx]"
158 end
159
160 nginx_site "tile" do
161   template "nginx_tile.conf.erb"
162   variables :caches => tilecaches
163 end
164
165 template "/etc/logrotate.d/nginx" do
166   source "logrotate.nginx.erb"
167   owner "root"
168   group "root"
169   mode 0o644
170 end
171
172 fail2ban_jail "squid" do
173   maxretry 1000
174 end
175
176 tilerenders.each do |render|
177   munin_plugin "ping_#{render[:fqdn]}" do
178     target "ping_"
179     conf "munin.ping.erb"
180     conf_variables :host => render[:fqdn]
181   end
182 end