]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/frontend.rb
imagery: za fix NGI url
[chef.git] / cookbooks / web / recipes / frontend.rb
1 #
2 # Cookbook:: web
3 # Recipe:: frontend
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 node.default[:memcached][:ip_address] = node.internal_ipaddress || "127.0.0.1"
21
22 include_recipe "memcached"
23 include_recipe "apache"
24 include_recipe "fail2ban"
25 include_recipe "web::rails"
26 include_recipe "web::cgimap"
27
28 web_passwords = data_bag_item("web", "passwords")
29
30 apache_module "alias"
31 apache_module "expires"
32 apache_module "headers"
33 apache_module "proxy"
34 apache_module "proxy_fcgi"
35 apache_module "lbmethod_byrequests"
36 apache_module "lbmethod_bybusyness"
37 apache_module "reqtimeout"
38 apache_module "rewrite"
39 apache_module "unique_id"
40
41 apache_site "default" do
42   action [:disable]
43 end
44
45 remote_directory "#{node[:web][:base_directory]}/static" do
46   source "static"
47   owner "root"
48   group "root"
49   mode "755"
50   files_owner "root"
51   files_group "root"
52   files_mode "644"
53 end
54
55 apache_site "www.openstreetmap.org" do
56   template "apache.frontend.erb"
57   variables :status => node[:web][:status],
58             :secret_key_base => web_passwords["secret_key_base"]
59 end
60
61 template "/etc/logrotate.d/apache2" do
62   source "logrotate.apache.erb"
63   owner "root"
64   group "root"
65   mode "644"
66 end
67
68 fail2ban_filter "apache-request-timeout" do
69   failregex '^<ADDR> .* "-" 408 .*$'
70 end
71
72 fail2ban_jail "apache-request-timeout" do
73   filter "apache-request-timeout"
74   logpath "/var/log/apache2/access.log"
75   ports [80, 443]
76 end
77
78 fail2ban_filter "apache-trackpoints-timeout" do
79   failregex '^<ADDR> .* "GET /api/0\.6/trackpoints\?.*" 408 .*$'
80 end
81
82 fail2ban_jail "apache-trackpoints-timeout" do
83   filter "apache-trackpoints-timeout"
84   logpath "/var/log/apache2/access.log"
85   ports [80, 443]
86   bantime "12h"
87   findtime "30m"
88 end
89
90 fail2ban_filter "apache-notes-search" do
91   failregex '^<ADDR> .* "GET /api/0\.6/notes/search\?q=abcde&.*$'
92 end
93
94 fail2ban_jail "apache-notes-search" do
95   filter "apache-notes-search"
96   logpath "/var/log/apache2/access.log"
97   ports [80, 443]
98 end
99
100 if %w[database_offline database_readonly].include?(node[:web][:status])
101   service "rails-jobs@mailers" do
102     action :stop
103   end
104
105   service "rails-jobs@storage" do
106     action :stop
107   end
108
109   service "rails-jobs@traces" do
110     action :stop
111   end
112 else
113   service "rails-jobs@mailers" do
114     action [:enable, :start]
115     supports :restart => true
116     subscribes :restart, "rails_port[www.openstreetmap.org]"
117     subscribes :restart, "systemd_service[rails-jobs@]"
118   end
119
120   service "rails-jobs@storage" do
121     action [:enable, :start]
122     supports :restart => true
123     subscribes :restart, "rails_port[www.openstreetmap.org]"
124     subscribes :restart, "systemd_service[rails-jobs@]"
125   end
126
127   service "rails-jobs@traces" do
128     action [:enable, :start]
129     supports :restart => true
130     subscribes :restart, "rails_port[www.openstreetmap.org]"
131     subscribes :restart, "systemd_service[rails-jobs@]"
132   end
133 end
134
135 template "/usr/local/bin/deliver-message" do
136   source "deliver-message.erb"
137   owner "rails"
138   group "rails"
139   mode "0700"
140   variables :secret_key_base => web_passwords["secret_key_base"]
141 end