5 # Copyright:: 2011, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
20 node.default[:memcached][:ip_address] = node.internal_ipaddress || "127.0.0.1"
22 include_recipe "memcached"
23 include_recipe "apache"
24 include_recipe "fail2ban"
25 include_recipe "web::rails"
26 include_recipe "web::cgimap"
28 web_passwords = data_bag_item("web", "passwords")
31 apache_module "expires"
32 apache_module "headers"
34 apache_module "proxy_fcgi"
35 apache_module "lbmethod_byrequests"
36 apache_module "lbmethod_bybusyness"
37 apache_module "remoteip"
38 apache_module "reqtimeout"
39 apache_module "rewrite"
40 apache_module "unique_id"
42 apache_site "default" do
46 remote_directory "#{node[:web][:base_directory]}/static" do
56 template "#{node[:web][:base_directory]}/static/.well-known/security.txt" do
57 source "security.txt.erb"
63 remote_file "#{Chef::Config[:file_cache_path]}/cloudflare-ipv4-list" do
64 source "https://www.cloudflare.com/ips-v4"
69 cloudflare_ipv4 = IO.read("#{Chef::Config[:file_cache_path]}/cloudflare-ipv4-list").lines.map(&:chomp)
71 remote_file "#{Chef::Config[:file_cache_path]}/cloudflare-ipv6-list" do
72 source "https://www.cloudflare.com/ips-v6"
77 cloudflare_ipv6 = IO.read("#{Chef::Config[:file_cache_path]}/cloudflare-ipv6-list").lines.map(&:chomp)
79 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
80 source "https://api.fastly.com/public-ip-list"
85 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
87 apache_site "www.openstreetmap.org" do
88 template "apache.frontend.erb"
89 variables :cloudflare => cloudflare_ipv4 + cloudflare_ipv6,
90 :fastly => fastlyips["addresses"] + fastlyips["ipv6_addresses"],
91 :status => node[:web][:status],
92 :secret_key_base => web_passwords["secret_key_base"]
95 template "/etc/logrotate.d/apache2" do
96 source "logrotate.apache.erb"
102 fail2ban_filter "apache-request-timeout" do
103 failregex '^<ADDR> .* "-" 408 .*$'
106 fail2ban_jail "apache-request-timeout" do
107 filter "apache-request-timeout"
108 logpath "/var/log/apache2/access.log"
112 fail2ban_filter "apache-trackpoints-timeout" do
113 failregex '^<ADDR> .* "GET /api/0\.6/trackpoints\?.*" 408 .*$'
116 fail2ban_jail "apache-trackpoints-timeout" do
117 filter "apache-trackpoints-timeout"
118 logpath "/var/log/apache2/access.log"
124 fail2ban_filter "apache-notes-search" do
125 failregex '^<ADDR> .* "GET /api/0\.6/notes/search\?q=abcde&.*$'
128 fail2ban_jail "apache-notes-search" do
129 filter "apache-notes-search"
130 logpath "/var/log/apache2/access.log"
134 if %w[database_offline database_readonly].include?(node[:web][:status])
135 service "rails-jobs@mailers" do
139 service "rails-jobs@storage" do
143 service "rails-jobs@traces" do
147 service "rails-jobs@mailers" do
148 action [:enable, :start]
149 supports :restart => true
150 subscribes :restart, "rails_port[www.openstreetmap.org]"
151 subscribes :restart, "systemd_service[rails-jobs@]"
154 service "rails-jobs@storage" do
155 action [:enable, :start]
156 supports :restart => true
157 subscribes :restart, "rails_port[www.openstreetmap.org]"
158 subscribes :restart, "systemd_service[rails-jobs@]"
161 service "rails-jobs@traces" do
162 action [:enable, :start]
163 supports :restart => true
164 subscribes :restart, "rails_port[www.openstreetmap.org]"
165 subscribes :restart, "systemd_service[rails-jobs@]"
169 template "/usr/local/bin/deliver-message" do
170 source "deliver-message.erb"
174 variables :secret_key_base => web_passwords["secret_key_base"]