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 working_directory basedir
155 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]}"
156 exec_stop "#{basedir}/bin/dispatcher --osm-base --terminate"
157 standard_output "append:#{logdir}/osm_base.log"
161 service "overpass-dispatcher" do
165 systemd_service "overpass-area-dispatcher" do
166 description "Overpass Area Dispatcher"
167 after ["overpass-dispatcher"]
168 working_directory basedir
169 exec_start "#{basedir}/bin/dispatcher --areas #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db"
170 exec_stop "#{basedir}/bin/dispatcher --areas --terminate"
171 standard_output "append:#{logdir}/areas.log"
175 service "overpass-area-dispatcher" do
179 systemd_service "overpass-update" do
180 description "Overpass Update Application"
181 after ["overpass-dispatcher"]
182 working_directory basedir
183 exec_start "#{basedir}/bin/overpass-update-db"
184 standard_output "append:#{logdir}/update.log"
188 if node[:overpass][:meta_mode] == "attic"
189 systemd_service "overpass-area-processor" do
190 description "Overpass Area Processor"
191 after ["overpass-area-dispatcher"]
192 working_directory basedir
193 exec_start "#{basedir}/bin/overpass-update-areas"
194 standard_output "append:#{logdir}/area-processor.log"
199 systemd_service "overpass-area-processor" do
200 description "Overpass Area Processor"
201 after ["overpass-area-dispatcher"]
202 working_directory basedir
203 exec_start "#{basedir}/bin/osm3s_query --progress --rules"
204 standard_input "file:#{srcdir}/rules/areas.osm3s"
205 standard_output "append:#{logdir}/area-processor.log"
211 systemd_timer "overpass-area-processor" do
212 description "Update areas in Overpass"
213 on_calendar "*-*-* *:*:00"
216 service "overpass-area-processor" do
220 template "/etc/logrotate.d/overpass" do
221 source "logrotate.erb"
225 variables :logdir => logdir
230 %w[db_lag request_count].each do |name|
231 template "#{basedir}/munin/overpass_#{name}" do
232 source "munin_#{name}.erb"
236 variables :basedir => basedir
239 munin_plugin "overpass_#{name}" do
240 target "#{basedir}/munin/overpass_#{name}"
242 conf_variables :user => username
246 prometheus_exporter "overpass" do
250 "--overpass.base-directory=#{basedir}"