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][:full_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"
78 gem_binary node[:ruby][:gem]
81 directory "#{basedir}/apache" do
87 template "#{basedir}/apache/totp-filter" do
88 source "totp-filter.erb"
92 variables :totp_key => web_passwords["totp_key"]
95 ssl_certificate node[:fqdn] do
97 node[:overpass][:fqdn]]
98 notifies :reload, "service[apache2]"
102 apache_module "headers"
103 apache_module "rewrite"
105 apache_site "default" do
109 apache_site "#{node[:overpass][:fqdn]}" do
110 template "apache.erb"
111 directory "#{basedir}/site"
112 variables :script_directory => "#{basedir}/cgi-bin"
123 logdir = node[:overpass][:logdir]
132 %w[overpass-update-db overpass-update-areas].each do |fname|
133 template "#{basedir}/bin/#{fname}" do
134 source "#{fname}.erb"
138 variables :basedir => basedir, :srcdir => srcdir
142 template "#{basedir}/bin/overpass-import-db" do
143 source "overpass-import-db.erb"
147 variables :basedir => basedir, :username => username, :srcdir => srcdir
150 systemd_service "overpass-dispatcher" do
151 description "Overpass Main Dispatcher"
152 working_directory basedir
153 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]}"
154 exec_stop "#{basedir}/bin/dispatcher --osm-base --terminate"
155 standard_output "append:#{logdir}/osm_base.log"
159 service "overpass-dispatcher" do
163 systemd_service "overpass-area-dispatcher" do
164 description "Overpass Area Dispatcher"
165 after ["overpass-dispatcher"]
166 working_directory basedir
167 exec_start "#{basedir}/bin/dispatcher --areas #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db"
168 exec_stop "#{basedir}/bin/dispatcher --areas --terminate"
169 standard_output "append:#{logdir}/areas.log"
173 service "overpass-area-dispatcher" do
177 systemd_service "overpass-update" do
178 description "Overpass Update Application"
179 after ["overpass-dispatcher"]
180 working_directory basedir
181 exec_start "#{basedir}/bin/overpass-update-db"
182 standard_output "append:#{logdir}/update.log"
186 if node[:overpass][:meta_mode] == "attic"
187 systemd_service "overpass-area-processor" do
188 description "Overpass Area Processor"
189 after ["overpass-area-dispatcher"]
190 working_directory basedir
191 exec_start "#{basedir}/bin/overpass-update-areas"
192 standard_output "append:#{logdir}/area-processor.log"
197 systemd_service "overpass-area-processor" do
198 description "Overpass Area Processor"
199 after ["overpass-area-dispatcher"]
200 working_directory basedir
201 exec_start "#{basedir}/bin/osm3s_query --progress --rules"
202 standard_input "file:#{srcdir}/rules/areas.osm3s"
203 standard_output "append:#{logdir}/area-processor.log"
209 systemd_timer "overpass-area-processor" do
210 description "Update areas in Overpass"
211 on_calendar "*-*-* *:*:00"
214 service "overpass-area-processor" do
218 template "/etc/logrotate.d/overpass" do
219 source "logrotate.erb"
223 variables :logdir => logdir
228 %w[db_lag request_count].each do |name|
229 template "#{basedir}/munin/overpass_#{name}" do
230 source "munin_#{name}.erb"
234 variables :basedir => basedir
237 munin_plugin "overpass_#{name}" do
238 target "#{basedir}/munin/overpass_#{name}"
240 conf_variables :user => username
244 prometheus_exporter "overpass" do
248 "--overpass.base-directory=#{basedir}"