5 # Copyright:: 2021, 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 include_recipe "accounts"
21 include_recipe "apache"
22 include_recipe "munin"
23 include_recipe "prometheus"
27 basedir = data_bag_item("accounts", username)["home"]
28 web_passwords = data_bag_item("web", "passwords")
30 %w[bin site diffs db src munin].each do |dirname|
31 directory "#{basedir}/#{dirname}" do
39 ## Install overpass from source
41 srcdir = "#{basedir}/src/osm-3s_v#{node[:overpass][:version]}"
52 remote_file "#{srcdir}.tar.gz" do
54 source "https://dev.overpass-api.de/releases/osm-3s_v#{node[:overpass][:version]}.tar.gz"
60 execute "source_tarball" do
62 command "tar -xf #{srcdir}.tar.gz"
64 notifies :run, "execute[install_overpass]"
65 not_if { ::File.exist?(srcdir) }
68 execute "install_overpass" do
72 command "./configure --enable-lz4 --prefix=#{basedir} && make install"
73 notifies :restart, "service[overpass-dispatcher]"
74 notifies :restart, "service[overpass-area-dispatcher]"
80 gem_binary node[:ruby][:gem]
83 directory "#{basedir}/apache" do
89 template "#{basedir}/apache/totp-filter" do
90 source "totp-filter.erb"
94 variables :totp_key => web_passwords["totp_key"]
97 ssl_certificate node[:fqdn] do
99 node[:overpass][:fqdn]]
100 notifies :reload, "service[apache2]"
104 apache_module "headers"
105 apache_module "rewrite"
107 apache_site "default" do
111 apache_site "#{node[:overpass][:fqdn]}" do
112 template "apache.erb"
113 directory "#{basedir}/site"
114 variables :script_directory => "#{basedir}/cgi-bin"
125 logdir = node[:overpass][:logdir]
134 %w[overpass-update-db overpass-update-areas].each do |fname|
135 template "#{basedir}/bin/#{fname}" do
136 source "#{fname}.erb"
140 variables :basedir => basedir, :srcdir => srcdir
144 template "#{basedir}/bin/overpass-import-db" do
145 source "overpass-import-db.erb"
149 variables :basedir => basedir, :username => username, :srcdir => srcdir
152 systemd_service "overpass-dispatcher" do
153 description "Overpass Main Dispatcher"
154 wants ["overpass-area-dispatcher.service"]
155 working_directory basedir
156 exec_start "#{basedir}/bin/dispatcher --osm-base #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db --rate-limit=#{node[:overpass][:rate_limit]} --space=#{node[:overpass][:dispatcher_space]}"
157 exec_stop "#{basedir}/bin/dispatcher --osm-base --terminate"
158 standard_output "append:#{logdir}/osm_base.log"
162 service "overpass-dispatcher" do
166 systemd_service "overpass-area-dispatcher" do
167 description "Overpass Area Dispatcher"
168 after ["overpass-dispatcher.service"]
169 working_directory basedir
170 exec_start "#{basedir}/bin/dispatcher --areas #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db"
171 exec_stop "#{basedir}/bin/dispatcher --areas --terminate"
172 standard_output "append:#{logdir}/areas.log"
176 service "overpass-area-dispatcher" do
180 systemd_service "overpass-update" do
181 description "Overpass Update Application"
182 after ["overpass-dispatcher.service"]
183 wants ["overpass-area-processor.service"]
184 working_directory basedir
185 exec_start "#{basedir}/bin/overpass-update-db"
186 standard_output "append:#{logdir}/update.log"
191 if node[:overpass][:meta_mode] == "attic"
192 systemd_service "overpass-area-processor" do
193 description "Overpass Area Processor"
194 after ["overpass-area-dispatcher.service", "overpass-update.service"]
195 working_directory basedir
196 exec_start "#{basedir}/bin/overpass-update-areas"
197 standard_output "append:#{logdir}/area-processor.log"
203 systemd_service "overpass-area-processor" do
204 description "Overpass Area Processor"
205 after ["overpass-area-dispatcher.service", "overpass-update.service"]
206 working_directory basedir
207 exec_start "#{basedir}/bin/osm3s_query --progress --rules"
208 standard_input "file:#{srcdir}/rules/areas.osm3s"
209 standard_output "append:#{logdir}/area-processor.log"
216 systemd_timer "overpass-area-processor" do
220 service "overpass-area-processor" do
224 template "/etc/logrotate.d/overpass" do
225 source "logrotate.erb"
229 variables :logdir => logdir
234 %w[db_lag request_count].each do |name|
235 template "#{basedir}/munin/overpass_#{name}" do
236 source "munin_#{name}.erb"
240 variables :basedir => basedir
243 munin_plugin "overpass_#{name}" do
244 target "#{basedir}/munin/overpass_#{name}"
246 conf_variables :user => username
250 prometheus_exporter "overpass" do
254 "--overpass.base-directory=#{basedir}"